for _ in range(int(input())):
x,y,mod=map(int,input().split())
ans=x
def exponentiation(x,y,mod):
result=1
while(y):
if y%2==1:
result=result*x%mod
if y==1:
break
x=x*x%mod
y=y>>1
return result
for i in range(2,y+1):
ans=exponentiation(ans,i,mod)%mod
print(ans%mod)
i am getting TLE in the last two test cases. Is it because I am using Python or i have written something wrong in my code?. I think my code is correct.