P = 10 ** 9 + 7 T = int(input()) for _ in range(T): x, k = map(int, input().split()) print(pow(x, pow(k, -1, P-1), P))