#include using namespace std; using ll = long long; constexpr char newl = '\n'; constexpr ll MOD = 1000000007; ll modpow(ll x, ll n, ll mod = MOD) { ll res = 1; while (n > 0) { if (n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int t; cin >> t; for (int i = 0; i < t; i++) { ll x, K; cin >> x >> K; if (x == 0) { cout << 0 << newl; continue; } constexpr ll hoge = 500000003 - 1; ll ans = modpow(x, modpow(K, hoge - 1, MOD - 1)); cout << ans << newl; } return 0; }