// Author:- Pratik Kinger
// Birla Institute of Technology
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<ll, ll>
#define vi vector<ll>
#define vii vector<pii>
#define mi map<ll, ll>
#define mii map<pii, ll>
#define f(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define FIO                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define all(a) (a).begin(), (a).end()
#define fi first
#define si second
#define sz(x) (ll) x.size()
#define endl '\n'
#define mod 1000000007
#define mset(m, v) memset(m, v, sizeof(m))
using namespace std;
const ll MOD = 1000000000 + 7;
//------------------------------CODE--HERE--------------------------
//----------global--variables-------------------
//------------end-------------------------------
ll powermod(ll a, ll b, ll modi)
{
    a %= modi;
    ll res = 1;
    while (b)
    {
        if (b % 2)
        {
            res = (res * a) % modi;
        }
        b /= 2;
        a = (a * a) % modi;
    }
    return res;
}
void solve()
{
    int n,k;
    cin>>n>>k;
    cout<<powermod(n,k,MOD)<<endl;
}
//------------------------------
int main()
{
    //FAST INPUT OUTPUT
    FIO;

//INPUT OUTPUT
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}