#include using namespace std; using LL = long long; using ULL = unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) LL ExtGcd(LL a, LL b, LL & x, LL & y) { if (b == 0) { x = 1; y = 0; return a; } LL g = ExtGcd(b, a % b, y, x); y -= a / b * x; return g; } ULL inv1000000006(ULL a) { LL M = 1000000006; LL x, y; ExtGcd((LL)a, 1000000006, x, y); x = ((x % M) + M) % M; return (ULL)x; } ULL powm(ULL a, ULL i, ULL M) { if (i == 0) return 1; ULL r = powm(a * a % M, i >> 1, M); if (i & 1) r = r * a % M; return r; } void loop() { ULL x, k; cin >> x >> k; ULL n = powm(x, inv1000000006(k), 1000000007); cout << n << endl; } int main() { int T; cin >> T; while (T--) loop(); return 0; }