  #include <bits/stdc++.h>
  using namespace std;
  #define ll long long
  
  ll mod = 1e9 + 7;
  
  ll power(ll x,ll y){
    ll ans = 1;
    while(y){
      if(y&1) ans *= x;
      y>>=1;
      x *= x;
      x %= mod;
      ans %= mod;
    }
    return ans;
  }

  void solve(){
    ll m,n,tt=1,t,i,j;
    cin >> n >> m;
    cout << power(n,m) <<"\n";

  }

  int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #endif

      ll t;
      cin >>t;
      while(t--) solve();
      
      return 0;
  }