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