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

#define pb push_back
#define ld long double
#define int long long

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

int32_t main()
{
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif // LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--){
        int n, k;
        cin >> n >> k;
        int now = 1;
        for (int i = 0; i < k; i++){
            now = (now * n) % (int)(1e9 + 7);
        }
        cout << now << endl;
    }
    return 0;
}
