#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdlib>
const long long MOD=1e9+7;
using namespace std;
long long fastPower(long long base, long long power) {
    long long result = 1;
    while (power > 0) {
        if (power & 1) {//此处等价于if(power%2==1)
            result = result * base % MOD;
        }
        power >>= 1;//此处等价于power=power/2
        base = (base * base) % MOD;
    }
    return result;
}
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		long long n;
		long long k;
		cin>>n>>k; 
		cout<<fastPower(n,k)%MOD<<'\n';
	}
	return 0;
}

