#include<bits/stdc++.h>
#define int long long
#define endl "\n"
using namespace std;
const int MOD=1e9+7;
int powmod(int a, int b)
{
int d,kq=1,d1;
while (b>1)
{
d=a; d1=1;
while (d1<=b/2)
{
d=(d*d)%MOD; d1=d1*2;
}
b=b-d1; kq=(kq*d)%MOD;
}
if (b==1) kq=(kq*a)%MOD;
return kq;
}
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n,a,b; cin>>n; while (n--)
{
cin>>a>>b; cout<<powmod(a,b)<<endl;
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBpbnQgbG9uZyBsb25nCiNkZWZpbmUgZW5kbCAiXG4iCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNvbnN0IGludCBNT0Q9MWU5Kzc7CmludCBwb3dtb2QoaW50IGEsIGludCBiKQp7CglpbnQgZCxrcT0xLGQxOwoJd2hpbGUgKGI+MSkKCXsKCQlkPWE7IGQxPTE7CgkJd2hpbGUgKGQxPD1iLzIpCgkJewoJCQlkPShkKmQpJU1PRDsgZDE9ZDEqMjsKCQl9CgkJYj1iLWQxOyBrcT0oa3EqZCklTU9EOwoJfQoJaWYgKGI9PTEpIGtxPShrcSphKSVNT0Q7CglyZXR1cm4ga3E7Cn0Kc2lnbmVkIG1haW4oKQp7Cglpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApO2Npbi50aWUoMCk7Y291dC50aWUoMCk7CglpbnQgbixhLGI7IGNpbj4+bjsgd2hpbGUgKG4tLSkKCXsKCQljaW4+PmE+PmI7IGNvdXQ8PHBvd21vZChhLGIpPDxlbmRsOwoJfQoJcmV0dXJuIDA7Cn0K