import sys input = sys.stdin.readline T = int(input()) mod = 10 ** 9 + 7 for _ in range(T): X, K = map(int, input().split()) inv = pow(K, mod - 4, mod - 1) print(pow(X, inv, mod))