#include<bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pri_queue priority_queue
#define mp map

#define FOR(i,a,b) for(int i=1;i<=b;i++)
#define FOD(i,a,b) for(int i=a;i>=b;i--)

#define MOD 1e7+7
#define MOD1 1e9+9
#define PI 3.1415926535897932384626433832795
using namespace std;
const long long mod = 1e9 + 7;
const int N = 1e5+5;
long long fac[N];
 
int power(int n, int k){
  long long res = 1;
  if(k == 0) return 1;
  res = power(n, k/2) % mod;
  if(k % 2 == 0) return res % mod * res % mod;
  else return n % mod * res % mod *res % mod;
}
 
signed main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while(t--){
    int n, k;
    cin >> n >> k;
    cout << power(n, k) << '\n';
  }
  return 0;
}