Link to this code: https://cses.fi/paste/c3f778335e404bc4881157/
/*
  2024 cùng những điều ước.
*/

#include <bits/stdc++.h>
using namespace std; 

#define pb push_back
#define sz(x) (int)(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

typedef long long ll; 
typedef pair<int, int> ii; 

const ll LINF = 1e18; 
const int INF = 1e9;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); 

template<typename T>
bool maximize(T& a, const T& b) {
	if (b < a) return false; 
	a = b; 
	return true; 
}

template<typename T>
bool minimize(T& a, const T& b) {
	if (a < b) return false;
	a = b; 
	return true; 
}

const int MOD = 1e9 + 7;   

ll binpow(ll a, ll b) {
	ll ans = 1;  
	for (; b > 0; b >>= 1) {
		if (b & 1) ans = ans * a % MOD;  
		a = a * a % MOD; 
	}
	return ans; 
}

signed main() {
	ios::sync_with_stdio(0); cin.tie(0); 
	int t; cin >> t; 

	while (t--) {
		int a, b; 
		cin >> a >> b; 
		cout << binpow(a, b) << '\n'; 
	}
	return 0;  
}