#include<iostream>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
void solve(int a,int b)
{
    ll res=1;
    while(b)
    {
        if(b&1) res=res*a%mod;
        b>>=1;
        a=(ll)a*a%mod;
    }
    cout<<res<<endl;
}
int main()
{
    int t;
    scanf("%d", &t);
    while(t--)
    {
        int n,m;
        scanf("%d%d", &n, &m);
        solve(n,m);
    }
    return 0;
}