for _ in[0]*int(input()):x,k=map(int,input().split());print(pow(x,pow(k,1000000006),1000000007))