#include<bits/stdc++.h>

#define int long long
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()

const double eps=1e-7,PI=3.1415926;
const int N=1e6+10,M=1e9+7;

using namespace std;

int n,q,m,k,x,y,a[N],mx=-1,mn=1e9,sum;
string s,s1,s2;
map < int , int > mp;
vector < int > vec;

int POW(int a,int b){
    if (b==0)return 1;
    int ret=POW(a,b/2);
    ret=(ret*ret)%M;
    if (b&1)return (ret*a)%M;
    return ret;
}

int dp(int i,int sum,int add){
    if (i==n)return (sum==(n-1)*((1<<k)-1)&&add==0);
    int ret=0;
    for (int j=0;j<(1<<k);j++){
        ret=(ret+dp(i+1,sum+j,add&j))%M;
    }
    return ret;
}

int32_t main(){
    cin>>q;
    while (q--){
        cin>>n>>k;
        cout<<POW(n,k)<<endl;
    }
    return 0;
}
