#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define ms(arr,a) memset(arr,a,sizeof arr)
#define debug(x) cout<<"< "#x" = "<<x<<" >"<<endl
const int mod=1e9+7;
int quick_pow(int a,int n)
{
int ret=1;
while(n)
{
if(n&1)ret=1LL*ret*a%mod;
a=1LL*a*a%mod;
n>>=1;
}
return ret;
}
int n,k,ek;
int main()
{
//freopen("Input.txt","r",stdin);
//freopen("Output.txt","w",stdout);
int t;scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&k);
ek=quick_pow(2,k);
int ans=ek;
for(int i=(n&1)+2;i<=n;i=i+2)
{
ans=(1LL*ans+1LL*ek*(ek-2)%mod*quick_pow(ek-1,i-2)%mod)%mod;
//debug(ans);
}
printf("%d
",ans);
}
//freopen("CON","w",stdout);
//system("start Output.txt");
}