F

In the first test case, P(0)=F2F2=22=4(mod10000019)P(0) = F_2^{F_2} = 2^2 = 4\pmod {10000019}P(0)=F2F2​​=22=4(mod10000019), as MEX(2,2)=0MEX(2, 2) = 0MEX(2,2)=0, P(1)=F1F1=11=1(mod10000019)P(1) = F_1^{F_1} = 1^1 = 1\pmod {10000019}P(1)=F1F1​​=11=1(mod10000019), as MEX(1,1)=1MEX(1, 1) = 1MEX(1,1)=1, and P(2)=F1F2=12=1(mod10000019)P(2) = F_1^{F_2} = 1^2 = 1\pmod {10000019}P(2)=F1F2​​=12=1(mod10000019), as MEX(1,2)=2MEX(1, 2) = 2MEX(1,2)=2. In the second test case, P(0)=F1F1⋅F1F2⋅F1F3⋅F2F2⋅F2F3⋅F3F3=11⋅12⋅13⋅22⋅23⋅33=864(mod10000019)P(0) = F_1^{F_1} \cdot F_1^{F_2} \cdot F_1^{F_3} \cdot F_2^{F_2} \cdot F_2^{F_3} \cdot F_3^{F_3} = 1^1 \cdot 1^2 \cdot 1^3 \cdot 2^2 \cdot 2^3 \cdot 3^3 = 864\pmod {10000019}P(0)=F1F1​​⋅F1F2​​⋅F1F3​​⋅F2F2​​⋅F2F3​​⋅F3F3​​=11⋅12⋅13⋅22⋅23⋅33=864(mod10000019), as MEX(1,1)=MEX(1,2)=MEX(1,3)=MEX(2,2)=MEX(2,3)=MEX(3,3)=0MEX(1, 1) = MEX(1, 2) = MEX(1, 3) = MEX(2, 2) = MEX(2, 3) = MEX(3, 3) = 0MEX(1,1)=MEX(1,2)=MEX(1,3)=MEX(2,2)=MEX(2,3)=MEX(3,3)=0, P(1)=1(mod10000019)P(1) = 1\pmod {10000019}P(1)=1(mod10000019), P(2)=1(mod10000019)P(2) = 1\pmod {10000019}P(2)=1(mod10000019), and P(3)=1(mod10000019)P(3) = 1\pmod {10000019}P(3)=1(mod10000019). In the third test case, P(0)=F2F2⋅F4F4⋅F4F5⋅F5F5=22⋅55⋅58⋅88=2295735(mod10000019)P(0) = F_2^{F_2} \cdot F_4^{F_4} \cdot F_4^{F_5} \cdot F_5^{F_5} = 2^2 \cdot 5^5 \cdot 5^8 \cdot 8^8 = 2295735\pmod {10000019}P(0)=F2F2​​⋅F4F4​​⋅F4F5​​⋅F5F5​​=22⋅55⋅58⋅88=2295735(mod10000019), as MEX(2,2)=MEX(4,4)=MEX(4,5)=MEX(5,5)=0MEX(2, 2) = MEX(4, 4) = MEX(4, 5) = MEX(5, 5) = 0MEX(2,2)=MEX(4,4)=MEX(4,5)=MEX(5,5)=0, P(1)=F1F1⋅F1F2⋅F1F3⋅F2F3⋅F3F3=11⋅12⋅13⋅23⋅33=216(mod10000019)P(1) = F_1^{F_1} \cdot F_1^{F_2} \cdot F_1^{F_3} \cdot F_2^{F_3} \cdot F_3^{F_3} = 1^1 \cdot 1^2 \cdot 1^3 \cdot 2^3 \cdot 3^3 = 216\pmod {10000019}P(1)=F1F1​​⋅F1F2​​⋅F1F3​​⋅F2F3​​⋅F3F3​​=11⋅12⋅13⋅23⋅33=216(mod10000019), as MEX(1,1)=MEX(1,2)=MEX(1,3)=MEX(2,3)=MEX(3,3)=1MEX(1, 1) = MEX(1, 2) = MEX(1, 3) = MEX(2, 3) = MEX(3, 3) = 1MEX(1,1)=MEX(1,2)=MEX(1,3)=MEX(2,3)=MEX(3,3)=1, P(2)=F1F4⋅F2F4⋅F3F4=15⋅25⋅35=7776(mod10000019)P(2) = F_1^{F_4} \cdot F_2^{F_4} \cdot F_3^{F_4} = 1^5 \cdot 2^5 \cdot 3^5 = 7776\pmod {10000019}P(2)=F1F4​​⋅F2F4​​⋅F3F4​​=15⋅25⋅35=7776(mod10000019), as MEX(1,4)=MEX(2,4)=MEX(3,4)=2MEX(1, 4) = MEX(2, 4) = MEX(3, 4) = 2MEX(1,4)=MEX(2,4)=MEX(3,4)=2, P(3)=F3F5=38=6561(mod10000019)P(3) = F_3^{F_5} = 3^8 = 6561\pmod {10000019}P(3)=F3F5​​=38=6561(mod10000019), as MEX(3,5)=3MEX(3, 5) = 3MEX(3,5)=3, P(4)=F1F5⋅F2F5=18⋅28=256(mod10000019)P(4) = F_1^{F_5} \cdot F_2^{F_5} = 1^8 \cdot 2^8 = 256\pmod {10000019}P(4)=F1F5​​⋅F2F5​​=18⋅28=256(mod10000019), as MEX(1,5)=MEX(2,5)=4MEX(1, 5) = MEX(2, 5) = 4MEX(1,5)=MEX(2,5)=4, and P(5)=1(mod10000019)P(5) = 1\pmod {10000019}P(5)=1(mod10000019).

This is a companion discussion topic for the original entry at https://toph.co/p/f