#include <bits/stdc++.h>
using namespace std;

#define int int64_t
#define MOD 998244353
#define inf 9e18
#define tikoo (int) (1e9 + 7)

template<typename T, typename T1> T max(T a, T1 b) { if (b > a) a = b; return a; }
template<typename T, typename T1> T min(T a, T1 b) { if (b < a) a = b; return a; }
int fastpow(int a, int b, int m = tikoo) { int res = 1; a %= m;
    while (b > 0) { if (b & 1) res = (res * a) % m; a = (a * a) % m; b >>= 1; } return res; }

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        cout << fastpow(n, k) << "\n";
    }
    return 0;
}
