#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops") 
#pragma GCC optimize "trapv"
 
#include<bits/stdc++.h>  
#define ll long long int 
#define ff first  
#define ss second  
#define mkp make_pair 
#define pb push_back  
#define pf push_front  
#define inf 1000000000
#define maxn 100005
#define mod  1000000007 
#define mod1 1000000009
  
using namespace std;    

 
void solve(){   
     int n,k; 
     cin>>n>>k; 

     ll res=1; 

     for(int i=0;i<k;++i){  
         res=(res*1LL*n)%mod;
     } 

     cout<<res<<'\n';

}


int main(){ 

  ios_base::sync_with_stdio(false); 
  cin.tie(NULL);  
 
    #ifndef ONLINE_JUDGE 
       freopen("input.txt","r",stdin);  
       freopen("output.txt","w",stdout); 
    #endif   
   
   int t; 
   cin>>t; 
   while(t--)
    solve();    

 
     
return 0;  
 
}    

// xqvbmyzlj 
// xyqvbmzlj


