#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
// #include <ext/pb_ds/detail/standard_policies.hpp>
#define ll long long
// #define mp make_pair
#define F first
#define S second
#define db long double
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
using namespace std;
// using namespace __gnu_pbds;
 
// typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_multiset;
 
 ll mod=1e9 +7;
 
ll expo(ll base,ll exponent,ll mod){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
 
// vector<bool>  prime(90000002,true);
// void Sieve() 
// { 
   
//     for (int p=2; p*p<=90000001; p++) 
//     { 
//         // If prime[p] is not changed, then it is a prime 
//         if (prime[p] == true) 
//         { 
//             for (int i=p*p; i<=90000001; i += p) 
//                 prime[i] = false; 
//         } 
//     } 
// }
 
// const ll M=3000006;
// ll f[M],inv[M];
 
// void compute(){
//     f[0]=1;
//     rep(i,1,M-1){
//         f[i]=(1LL*i*f[i-1])%mod;
//     }
//     inv[M-1]=expo(f[M-1],mod-2,mod);
//     for(ll i=M-2;i>=0;i--){
//         inv[i]=(1LL*(i+1)*inv[i+1])%mod;
//     }
// }
// ll C(ll n,ll r){
//     return (1LL*((1LL*f[n]*inv[r])%mod)*inv[n-r])%mod;
// }

int kmp(const string &T, const string &P) {
  if (P.empty()) return 0;

  vector<int> pi(P.size(), 0);
  for (int i = 1, k = 0; i < P.size(); ++i) {
    while (k && P[k] != P[i]) k = pi[k - 1];
    if (P[k] == P[i]) ++k;
    pi[i] = k;
  }

  for (int i = 0, k = 0; i < T.size(); ++i) {
    while (k && P[k] != T[i]) k = pi[k - 1];
    if (P[k] == T[i]) ++k;
    if (k == P.size()) return i - k + 1;
  }

  return -1;
}

int main()
{
	int t=1,cntr=1;
	cin>>t;
	while(t--)
	{
		ll i,j,k,n;
		cin>>n>>k;
		ll ans=1;
		rep(i,1,k)
		{
			ans*=n;
			ans%=mod;
		}
		cout<<ans<<"\n";
	}

// 	system("pause");
	return 0;
}