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

#define ff                   first
#define ss                   second
#define ll                 long long int
#define ld                   long double
#define pii                  pair<ll,ll>
#define pb                   push_back
#define rep(i,a,b)           for(int i=a;i<b;i++)
#define t(x)                 int t; cin>>t; while(t--)
#define vi                   vector<int>
#define mii                  map<int,int>
#define min3(a, b, c)        min(min(a, b), c)
#define min4(a, b, c, d)     min(min(a, b), min(c, d))
#define max3(a, b, c)        max(max(a, b), c)
#define max4(a, b, c, d)     max(max(a, b), max(c, d))
#define ps(x,y)              fixed<<setprecision(y)<<x
#define setbits(x)           __builtin_popcountll(x)
#define zrobits(x)           __builtin_ctzll(x)
#define all(x)               x.begin(),x.end()
#define M                  1000000007
#define FIO                  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                      rng(chrono::steady_clock::now().time_since_epoch().count());

ll power(ll x, ll y, ll p)
{
    ll res = 1;     // Initialize result

    x = x % p; // Update x if it is more than or
    // equal to p

    if (x == 0) return 0; // In case x is divisible by p;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res * x) % p;

        // y must be even now
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}

int main()
{
    FIO;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    t(x)
    {
        ll n, k;
        cin >> n >> k;
        cout << power(n, k, M) << endl;


    }
}


