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=(ans*exponentiation(x,i,mod))%mod
print(ans%mod)
I am getting tle in test 3 and test 4 and WA in test 1 and test 2. Please help.