#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#define P pair<int,int>
#define INF 1e8 + 5
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
int n;
ll q_pow(ll a, ll k){
	ll res = 1;
	while(k){
		if(k&1){
			res = (res*a)%mod;
		}
		k >>= 1;
		a = (a*a)%mod;
	}
	return res%mod;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		ll n,k;
		cin >> n >> k;
		cout<<q_pow(n,k)<<endl;
	}	
}