#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;

ll fac[200005];
inline void init(ll n) {
	fac[0] = 1;
	for (ll i = 1; i <= n; i++)
		fac[i] = fac[i - 1] * i % mod;
}
inline ll quick_pow(ll a, ll k, ll p) {
	ll res = 1;
	a %= p;
	while (k) {
		if (k & 1) res = res * a % p;
		a = a * a % p;
		k >>= 1;
	}
	return res;
}
inline ll inv(ll x, ll p) {return quick_pow(x, p - 2, p);}
inline ll getC(ll n, ll m, ll p) {return fac[n] * inv(fac[n - m] * fac[m] % p, p) % p;}

int main() {
	init(2e5);
	int T;
	scanf("%d", &T);
	while (T--) {
		ll n, k, ans = 0, sum = 0;
		scanf("%lld %lld", &n, &k);
		for (ll i = 0; i < n; i += 2) sum = (sum + getC(n, i, mod)) % mod;
		if (n & 1) ans = (ans + quick_pow(sum + 1, k, mod)) % mod;
		else {
			for (ll i = 0; i < k; i++) ans = (ans + quick_pow(sum, i, mod) * quick_pow(quick_pow(2, n, mod), k - i - 1, mod) % mod) % mod;
			ans = (ans + quick_pow(sum, k, mod)) % mod;
		}
		printf("%lld\n", ans);
	}
	return 0;
}

#include <bits/stdc++.h>
#define fori for (int i = 0; i < n; ++i)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;

const ll MOD = 1000000007;
vector <ll> f;

ll binpow(ll n, ll k) {
    if (k == 0) return 1;
    if (k == 1) return n%MOD;
    if (k == 2) return (n*n)%MOD;
    if (k%2 == 0) {
        return binpow((n*n)%MOD, k/2) % MOD;
    }
    return (n * binpow((n*n)%MOD, k/2)) % MOD;
}

ll C(ll n, ll k) {
    return (f[n] * binpow((f[k]*f[n-k]) % MOD, MOD-2)) % MOD;
}

inline void solve() {
    ll n, k, ans;
    cin >> n >> k;
    ll bitcnt = (n%2 == 1);
    for (int i = 0; i < n; i += 2) {
        bitcnt = (bitcnt + C(n, i)) % MOD;
    }
    if (n%2 == 0) {
        ans = binpow(bitcnt, k);
        ll cells = 0;
        for (int i = 0; i < k; ++i) {
            ans = (ans + (binpow(bitcnt, k-i-1) * binpow(2, cells)) % MOD) % MOD;
            cells = (cells + n) % (MOD-1);
        }
    } else {
        ans = binpow(bitcnt, k);
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int t;
    cin >> t;
    f.resize(200005, 1);
    for (int i = 2; i <= 200003; ++i) {
        f[i] = (f[i-1] * i) % MOD;
    }
    while (t--) {
        solve();
    }
}

/*WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWNX0OkxxxxxxxxxxxkxxkkkkOOO00KXWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNKOkxollloddxxOOOO0000000000Okkxxkk0NMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMN0kollllccccllooodxkOOOOO000000000000kxxOKWWXKKXNWMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMWWXOdc;;,,,;;:::::cllooodxkOO000000000000000kxxdc::clokNMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMWKkoc:'......';::;::::loooooxkOOOOO00OO0000OO00Oxl:::::;ckNWMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMWWKkol:'......''',;;;;:;;;clollldxkOOOOOOOOOOOOOOOOOxo:;;::;;l0WMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMWXkddl;''...'''...';;;;;;;;;clllllodkOOOOOOOOOOOOOOOOkxo:;;;;;,:OWMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMNOddxl;,''.........',;;;,,,,,:clllllldkkkkOOOOOOOOOkkkOkoc;,;;;;,:OWMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMWKxdxko:,,'..........',,,,,,,,,:ccccllcloxkkkkkkkkkkkkkkkkdl:,,,,,,'cKMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMWOodkkxl:;,'.'.. .....',,,,,,,,,:ccccccccclxkkkkkkkkkkkkkkkdlc;'',,,,'dWMMMMMMMMMMMM
MMMMMMMMMMMMMMMWOoxkkxdc;;;'.........''''''''',;:ccccccccccoxkkkkkkkkkkkkkkdccc,'''',':KMMMMMMMMMMMM
MMMMMMMMMMMMMMWOodkxxxdc,,;,'....''''''''''''',;::::::::cccloxkOOOOOOkOOkOkdl:c:'''''',OMMMMMMMMMMMM
MMMMMMMMMMMMMMXdoxdoddxl'.',''''''''''''''..',;::::::::cccllldkOOOOOOOOOOOOkdlc:,..''.,OMMMMMMMMMMMM
MMMMMMMMMMMMMMNdlo:;;cxo,..................',;;;;:::::cccllllloxkkkkkkkkkkkkkdlc;.....;0MMMMMMMMMMMM
MMMMMMMMMMMMMMWk;;,''cxo;'................,;;;;;;:::cccccccccccldxxxxxxxxxxxxdlc;.....oNMMMMMMMMMMMM
MMMMMMMMMMMMMMMNkl;'.cxl;;,'...........',,;;;;;:::::::::::::::;:looollllllllol::;'..,dXMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMWXOlldl;;;;,,''''''',,;;;;;;;::::::::;;:;;,,'.'''....',,,,,'..,;;cxKWMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMKdol;,,,,,,,,,,,,,;;;;;;;;;;;;;;;;;;,'...         ...''.....':0WWMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMXdoc,,,,,,,,;;;;;;;,,;;;;;;;;;;;;,...              ...'......:OWMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMNxlc,,,,,,,,,,,,,,,,,,;;;;;;,,,'..     ........       .......cKWMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMWklc,,,,,,,,,,,,,,,,,,,;,,,,....  ...,;::::cldc...       ....oNMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMOlc;,,,,,,,,,,,,,,,,,,,,,..   ..';:cc:;;codxd,.,:'      ...,OMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMKoc;,,'''''',,,,,,,,,,,'.  ..',:ccccc,.  ..  .;cc;.    ....lXMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMWkc;,''''''''''''',,,,.. ..,;::::ccccc:,''.',:cc:'     ...,OMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMXd;,''''''''''''''''....',,,,,;;;:::::cccccc::;.     ....oNMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMKl,'''..''''''''''.. ..,,,''''''''',,,,,,,'...     ....c0MMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMXd,.'...........'.    .,;;;,,,,,''''...............''cKWMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMW0l,...........'......',;;;;;;;;;:,.............'';dXWMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMN0xl;'.'.''.','......'',,;::::::;''''''''',,,,:oKWWMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWXOxdc,,;,,;,,'''.....',;:cl:,,,,,,;;;;;;oOXWWWWWWMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWKdccllc:;;;;;;,,,,,,,;:olccc:;:;:cllcdXWMMMMWMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWXOdlcccccllc:::::::::::::colodolcc::cccccxNMMWMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMWN0dlcclccccccc:::::cccccccc::lc:loolc:::cccccdXMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMWWNOocccllcccc:::;;;;;:::ccccccc:odllooxo:;;:ccllco0WMWWMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMWNx::ccccccccc:::;,,,;;:::ccccccccdkOK0Oko;;::ccllcl0MMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMWx;::cc::ccc::cccc:::;;:::::::::ccokO00OOkl::ccccll:oNMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMNo,;:::::::::::ccc::c::::ccccccccccldkOOOxl::cccccl:lKMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMO;,;;;;;:::::::::clddlc:ccccccccccccclolc:::cccccc:lKMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMNd'',,,;;;;;;;;;:lddl:::::::::::::cc::c:::::;::ccc:lKMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMNkc''',,,,;;;;;cool:;;;;;;;;;;;;;;;;;;;;;coc;;:::;cKMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMNOl,'''',,,,;:cc;,,,,,,,,,,,,,,,,,,,,,,:lc;;;;:;lXMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWKxc,'..'',;;;'''''''''''''''''''','';:;,,,;,;OWMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWWMWKko:'.''..............''''''..'.',,.'''':OWMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMOlc:::;,'.................'';:c;.',cxXWMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWOlcccclllcc::::;:::::;:::cloooo:l0XWMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWO:'...''''''','',,;,'''''',,,,'.;0WMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM0:...............:k:.............cXMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMKc''............;0WO,............;0MMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMXdc:,,,,,'''...:OWMWx'......'',,,dNMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWOlc;::::::c::lkNWMMMXo:;,;;;:::c:dNMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNxc:;:::::cc:oOXWWWMMXo;,;;;:::cc:dNMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNd;;:::::ccc:dXNMMMMMXo;,;;;:::cc:oXMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNd;;:::cccc:cOWMMMMMMWk;,,;;::ccc:oXMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNd;::cccccc;dNMMMMMMMMXo,,;;::ccl:oNMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNxlollolll:c0MMMMMMMMMWk:;;:clllolckNMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMKoolllooll:lKMMMMMMMMMWOl:;::cclllc:kWMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWW0l:;::::::;dXMMMMMMMMMMXdc::::ccclc:kWMMMMMMMMMMMMMMMMMMMMMMMM*/

/*   coded by apoorv_me   */
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
#define pii pair<int, int>
#define vi vector < int >
#define vpi vector <pair <int , int > >
#define pll pair<ll, ll>
#define vl vector < ll >
#define vpl vector <pair <ll , ll > >
#define vb vector<bool>

#define nl "\n"
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define setbit(x) __builtin_popcountll((ll)x)
#define b_ctz(x)   __builtin_ctzll(ll(x))
#define log_2(x)    63 - __builtin_clzll(ll(x))
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)((a).size()))
#define bs binary_search

//random generator
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll a,ll b){if(a > b){return -1;}return a + (ll)rng() % (b - a + 1);}

// Input Operatirons Pair, Vector
template<class T, class V>istream& operator>>(istream &in, pair<T, V> &a){in >> a.F >> a.S;return in;}
template<class T>istream& operator>>(istream &in, vector<T> &a){for(auto &i: a){in >> i;} return in;}

// Output Operations Pair Vector
template<class T, class V>ostream& operator<<(ostream &os, pair<T, V> &a){os << a.F << " " << a.S;return os;}
template<class T>ostream& operator<<(ostream &os, vector<T> &a){for(int i = 0 ; i < sz(a) ; i++){if(i != 0){os << ' ';}os << a[i];}return os;}

#ifdef APOORV
#include "debug.h"
#else
#define dbg(...) "11-111"
#endif

const ll INF = 4e18;
const ll mod = 1000000007;
// const ll mod = 998244353;
const ll MAX = 200005;
/*----------------------------------x---Code-Below---x--------------------------------*/

struct mi {
    ll v; explicit operator ll() const { return v % mod; }
    mi() { v = 0; }
    mi(ll _v) {
        v = (-mod < _v && _v < mod) ? _v : _v % mod;
        if (v < 0) v += mod;
    }
    friend bool operator==(const mi& a, const mi& b) {
        return a.v == b.v; }
    friend bool operator!=(const mi& a, const mi& b) {
        return !(a == b); }
    friend bool operator<(const mi& a, const mi& b) {
        return a.v < b.v; }

    mi& operator+=(const mi& m) {
        if ((v += m.v) >= mod) v -= mod;
        return *this; }
    mi& operator-=(const mi& m) {
        if ((v -= m.v) < 0) v += mod;
        return *this; }
    mi& operator*=(const mi& m) {
        v = v*m.v%mod; return *this; }
    mi& operator/=(const mi& m) { return (*this) *= inv(m); }
    friend mi pow(mi a, ll p) {
        mi ans = 1; assert(p >= 0);
        for (; p; p /= 2, a *= a) if (p&1) ans *= a;
        return ans;
    }
    friend mi inv(const mi& a) { assert(a.v != 0);
        return pow(a,mod-2); }

    mi operator-() const { return mi(-v); }
    mi& operator++() { return *this += 1; }
    mi& operator--() { return *this -= 1; }
    mi operator++(int) { mi temp; temp.v = v++; return temp; }
    mi operator--(int) { mi temp; temp.v = v--; return temp; }
    friend mi operator+(mi a, const mi& b) { return a += b; }
    friend mi operator-(mi a, const mi& b) { return a -= b; }
    friend mi operator*(mi a, const mi& b) { return a *= b; }
    friend mi operator/(mi a, const mi& b) { return a /= b; }
    friend ostream& operator<<(ostream& os, const mi& m) {
        os << m.v; return os;
    }
    friend istream& operator>>(istream& is, mi& m) {
        ll x; is >> x;
        m.v = x;
        return is;
    }
};
#define vm vector<mi>

vm fact(MAX, 1), inv_fact(MAX, 1);
void calculate_factorial(){
    for(ll i = 1 ; i < MAX ; i++){
        fact[i] = fact[i - 1] * i;
        inv_fact[i] = mi(1) / fact[i];
    }
}
mi C(ll n,ll r){
    if(r > n)   return 0;
    mi val = fact[n] * inv_fact[r] * inv_fact[n - r];
    return val;
}

void __solve_testcase(int test_case) {
    int n, k;
    cin >> n >> k;
    vector<pair<mi, mi>> dp(k + 1, {1, 1});
    if(n & 1) {
        mi res = 1;
        for(int i = k - 1 ; i >= 0 ; i--) {
            res *= (pow(mi(2), n - 1) + 1);
        }
        cout << res << nl;
    } else {
        mi ans = 0, res = 1;
        for(int i = k - 1 ; i >= 0 ; i--) {
            dp[i].F = dp[i + 1].S;
            dp[i].S = dp[i + 1].S * (pow(mi(2), n - 1) - 1);
            ans += (dp[i].F * pow(pow(mi(2), n), i));
            // dbg(ans.v);
        }
        ans += dp[0].S;
        cout << ans << nl;
    }
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    auto precalc = [&]() {

    };
    precalc();
    int no_of_testcase = 1;
    cin >> no_of_testcase;
    for(int testcase = 1; testcase <= no_of_testcase ; testcase++){
        // cout << "Case #" << testcase << ": ";
        __solve_testcase(testcase);
    }
    return 0;
}

//@author: 天不言而四时行
//@date: 2021-09-13 19:00:15
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mem(a,b) memset(a,b,sizeof a);
#define INF 0x3f3f3f3f
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define lyh(i,a,b) for (int i = a; i <= b; ++i)
#define hyl(i,a,b) for (int i = a; i >= b; --i)
#define mub unordered_map
#define pb push_back
#define pf push_front
#define int long long

using namespace std;

typedef pair<int,int> PII;

const int N = 2e5 + 10, mod = 1e9 + 7;

int n, m;
int fact[N], infact[N], f[N];

int qmi(int a, int b) {
    int res = 1;
    a %= mod;
    while (b) {
        if (b & 1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res % mod;
}

void inti() {
    fact[0] = infact[0] = 1;
    rep (i, 1, N) {
        fact[i] = fact[i-1] * i % mod;
        infact[i] = infact[i-1] * qmi(i, mod-2) % mod;
    }
}

int C(int a, int b) {
    return fact[a] * infact[a - b] % mod * infact[b] % mod;
}

signed main(void) {
    int t;
    cin >> t;
    inti();
    while (t--) {
        int n,k;
        cin >> n >> k;
        f[0] = 1;
        int sum = 0;
        for (int i = (n & 1 ? 1 : 2); i <= n; i += 2)
            sum = (sum + C(n,i)) % mod;

        // 偶数1或全1
        if (n & 1) {
            for (int i = 1; i <= k; ++i)
                f[i] = f[i-1] * (1+sum) % mod;
        }
        else {
            for (int i = 1; i <= k; ++i) {
                f[i] = f[i-1] * sum % mod;
                f[i] = (f[i] + qmi(qmi(2,i-1), n)) % mod;
            }
        }
        cout << f[k]  << '\n';
    }
    return 0;
}

#include<iostream>
using namespace std;
#include<string>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<set>
#define pb push_back
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#include<bits/stdc++.h>
ifstream fin ("input.txt");
ofstream fout ("output.txt");

typedef long long ll;
typedef pair<int,int>pii;
typedef pair<ll,ll>pl;

ll mod=1e9+7;
#define all(x) x.begin(), x.end()

int lcs(string X, string Y)
{
    int m=X.size();
    int n=Y.size();
    int L[m + 1][n + 1];
    int i, j;
    for (i = 0; i <= m; i++) {
        for (j = 0; j <= n; j++) {
            if (i == 0 || j == 0)
                L[i][j] = 0;

            else if (X[i - 1] == Y[j - 1])
                L[i][j] = L[i - 1][j - 1] + 1;

            else
                L[i][j] = max(L[i - 1][j], L[i][j - 1]);
        }
    }
    return L[m][n];
}

ll pow_with_mod(ll a,ll b, ll mod)
{
    ll res=1;
    while(b)
    {
        if(b&1)
        res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}
ll power(ll a,ll b)
{
    ll res=1;
    while(b)
    {
        if(b&1)
        res=(res*a);
        a=(a*a);
        b>>=1;
    }
    return res;
}

int sod(ll x)
{
    int res=0;
    while(x)
    {
        int a=x%10;
        res+=a;
        x/=10;
    }
    return res;
}

bool is_prime(ll n)
{

    for (ll i = 2; i <=sqrt(n); i++)
        if (n % i == 0)
            return false;

    return true;
}

ll modInverse(ll n, ll p)
{
    return pow_with_mod(n, p - 2, p);
}

ll ncrMod(ll n, ll r,ll p,ll fact[])
{
    if (n < r)
        return 0;

    if (r == 0)
        return 1;

    return (fact[n] * modInverse(fact[r], p) % p
            * modInverse(fact[n - r], p) % p)
           % p;
}

int main()
{
    FIO;
    int tc=1;
    cin>>tc;
    ll powers[200001]={0};
    powers[0]=1;
    for(ll i=1;i<=200000;i++)
        powers[i]=(powers[i-1]*2)%mod;

    for(int testc=1;testc<=tc;testc++)
    {
        ll n,k;
        cin>>n>>k;
        if(k==0)
        {
            cout<<1<<endl;
            continue;
        }

        ll res=1;

        ll x=powers[n-1];
        ll y=(x-1+mod)%mod;
        for(int i=1;i<=k;i++)
        {

            if(n%2==0)
            {
                ll f=n*(i-1);
                ll m=pow_with_mod((ll)2,f,mod);
                ll z=(res*y)%mod;
                res=(m+z)%mod;
            }
            else res=(res*x+res)%mod;

        }
        cout<<res<<endl;

    }

}

#include <bits/stdc++.h>
#define ll long long
#define berak break
#define faset()                     \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);                    \
  cout.tie(NULL);
#define fr first
#define sc second
#define spc 200005
#define pairll pair<ll, ll>
#define pairlll pair<ll, pair<ll, ll>>
#define mp make_pair
#define pb push_back
using namespace std;

ll t, n, k, conss = 1000000007, arr[spc], ans = 0, tmp;

ll multi (ll a, ll b){
  return ((a%conss)*(b%conss))%conss;
}

ll add (ll a, ll b){
  return ((a%conss)+b%conss)%conss;
}

ll pangkat (ll a, ll b){
  if (b == 0) return 1;
  if (b == 1) return a;
  ll tmp = pangkat (a,b/2);
  if (b%2) return multi (tmp,multi(tmp,a));
  return multi (tmp,tmp);
}

void solve(){
    cin >> n >> k;

    ll sum = pangkat(2,n-1);
    ll ans = 0;

    if(n & 1){
        ans = pangkat(sum + 1, k);
    } else{
        ans = pangkat(sum-1, k);
        for(int i = 1; i <= k; i++){
            ans = add(ans, multi(pangkat(sum-1, i - 1), pangkat(pangkat (2,n), k - i)));
        }
    }

    cout << ans << '\n';
}

void input()
{
}

int main()
{
  faset();
  cin >> t;
  while (t--)
  {
    input();
    solve();
  }
}

#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define REP(i,n) FOR(i,0,n)
#define F first
#define S second
#define PB push_back
#define MP make_pair

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

#define gc (_op==_ed&&(_ed=(_op=_buf)+fread(_buf,1,100000,stdin),_op==_ed)?EOF:*_op++)
char _buf[100000],*_op(_buf),*_ed(_buf);

template <typename T>
void in_s(T &x){
	x = 0; int f = 1; char ch = gc;
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = gc;}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = gc;}
	x *= f;
}

template<>
void in_s(string& t){
	cin >> t;
}

void cinput(){}
template<typename First,typename ... Args>
void cinput(First& f, Args&... args){
	in_s(f);
	cinput(args...);
}

#define ININ(...)\
	cinput(__VA_ARGS__)

#define IN(type, ...)\
	type __VA_ARGS__;\
	ININ(__VA_ARGS__);

#define IN_V(type,name,n)\
	vector<type> name(n);\
	FOR(i,0,n){\
		IN(bool,__temp)\
		name[i] = __temp;\
	}

const int MAX_N = 200001, MOD = 1e9 + 7;
int fac[MAX_N], ifac[MAX_N], N, K, cache[MAX_N] = {0};

void initFac(int m, int mod) {
    fac[0] = 1;
    FOR(i,1,m) {
        fac[i] = 1ll * i * fac[i-1] % mod;
    }
}

int power(int a, ll p, int mod) {
    if (a == 2 && p < 1ll * MAX_N && cache[p]) {
        return cache[p];
    }
    ll x = 1, y = a, pp = p;
    while(p) {
        if (p & 1) {
            x = x * y;
            if (x  > mod) x%= mod;
        }
        y *= y;
        if (y > mod) y %= mod;
        p/= 2;
    }
    if (a == 2 && pp < 1ll * MAX_N) {
        cache[pp] = x;
    }
    return x;
}

int inverseMod(int n, int p) {
    return power(n, p-2, p);
}

void initIfac(int m, int mod) {
    ifac[0] = 1;
    FOR(i,1,m) {
        ifac[i] = inverseMod(fac[i], mod);
    }
}

int combinatorial(int c, int r, int mod) {
    int ans = 1ll * fac[c] * ifac[r] % mod * ifac[c-r] % mod;
    // printf("%d %d -> %d\n", c, r, ans);
    return ans;
}

int add(ll a, ll b) {
    return (a + b) % MOD;
}

int multi(ll a, ll b) {
    return a * b % MOD;
}

int getEqualCombSum() {
    int ans = 0;
    // (xor all is 1)
    if ((N % 2)) ans++;
    int p = power(2, N-1, MOD);
    if ((N%2) == 0) p--;
    ans = add(ans, p);
    return ans;
}

int getOneZeroSum() {
    return (N % 2) == 0;
}

int getRightSum(int k) {
    return power(2, 1ll*N*k, MOD);
}

void solve() {
    int ans = 0, equalSum = 1;
    int equalCombSum = getEqualCombSum();
    int oneZeroSum = getOneZeroSum();

    REP(i,K) {
        if (oneZeroSum) {
            int rightSum = getRightSum(K-i-1);
            ans = add(ans, multi(equalSum, rightSum));
        }
        // printf("i ans %d %d\n", i, ans);
        equalSum = multi(equalSum, equalCombSum);
    }
    ans = add(ans, equalSum);
    printf("%d\n", ans);
}

int main() {
    int T;
    initFac(N, MOD);
    initIfac(N, MOD);

    ININ(T);
    REP(i,T) {
        ININ(N, K);
        solve();
    }
}

/*
author:Karan
created:09.08.2021 21:07:50
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(ar) ar.begin(),ar.end()
#define endl '\n'

const ll mod=(ll)1e9+7;
const ll mx=2e5+7;

ll fact[mx];
ll ifact[mx];

ll power(long long x, unsigned ll y, ll mod) {
    ll res = 1;
    x = x % mod;
    if (x == 0) return 0;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res;
}

ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}

ll modExp(ll a, ll p,ll mod) {
    a %= mod;
    ll res=1;
    while(p > 0) {
        if(p & 1) res = res * a % mod;
        a = a * a % mod;
        p >>= 1;
    }
    return res;
}
ll modInv(ll a,ll mod) {
    return modExp(a,mod-2,mod) % mod ;
}

ll nCr(ll n,ll r) {
    return ((fact[n]%mod*ifact[n-r]%mod)%mod*ifact[r]%mod)%mod;
}

void solve1(ll n,ll k) {
    ll x=0LL;
    for(ll i=0;i<n;i+=2) {
        ll y=nCr(n,i);
        x=mod_add(x,y,mod);
    }
    vector<ll> dp(k+1,0);
    dp[0]=1LL;
    for(ll i=1;i<=k;i++) {
        dp[i]=dp[i-1]+(x%mod*dp[i-1]%mod)%mod;
        dp[i]%=mod;
    }

    cout<<dp[k]<<endl;
}

void solve2(ll n,ll k) {
    ll x=0LL;
    for(ll i=0;i<n;i+=2) {
        ll y=nCr(n,i);
        x=mod_add(x,y,mod);
    }
    vector<ll> dp(k+1,0);

    dp[0]=1LL;
    for(ll i=1;i<=k;i++) {
        ll y=power(2,(i-1)*n,mod);
        dp[i]=y+((x%mod)*(dp[i-1]%mod))%mod;
        dp[i]%=mod;
    }
    cout<<dp[k]<<endl;

}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);

    {
        fact[0]=1LL;
        ifact[0]=1LL;
        for(ll i=1;i<mx;i++) {
            fact[i]=i*fact[i-1];
            fact[i]%=mod;
            ifact[i]=modInv(fact[i],mod);
        }
    }
    ll t;
    cin>>t;
    while(t--) {
        ll n,k;
        cin>>n>>k;
        if(n%2) {
            solve1(n,k);
        }
        else {
            solve2(n,k);
        }
    }
}

#include <bits/stdc++.h>
#include<iostream>
using namespace std;
// GCC Optimizations
#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")

#define ar array
#define ll long long
#define lld long double
#define sza(x) ((int)x.size())
#define all(a) (a).begin(), (a).end()
#define pb              push_back
#define sz(x) ((ll)(x).size())

const int MAX_N = 1e5 + 5;
const ll mod =1e9+7;
const ll inf = 1e9;
const lld EPS = 1e-9;
string to_binary(ll n)
{
    string s;
    for(int i=63;i>=0;i--)
    {
        ll t=(1<<i)&n;
        if(t>0)s=s+"1";
        else s=s+"0";
    }
    return s;
}
// Power under mod (a ^ b) % mod
ll modpow(ll a,ll b, ll m = mod) {
     ll ans = 1;
    while (b) {
        if (b & 1) { ans = (ans * a) % m; }
        b = b >> 1; a = (a * a) % m;
    }
    return ans;
}
// Inverse Mod (1 / a) % mod
ll modinv(ll a, ll m = mod) { return modpow(a, m - 2,m); }

// Modular Arithematic
ll modadd(ll a, ll b,ll m = mod) { a = a % m; b = b % m; return (((a + b) % m) + m) % m; }
ll modsub(ll a,ll b, ll m = mod) { a = a % m; b = b % m; return (((a - b) % m) + m) % m; }
ll modmul(ll a,ll b, ll m = mod) { a = a % m; b = b % m; return (((a * b) % m) + m) % m; }
ll moddiv(ll a,ll b, ll m = mod) { a = a % m; b = b % m; return (modmul(a, modinv(b, m), m) + m) % m; }

// GCD
ll gcd(ll a, ll b) { if (b == 0) { return a; } return gcd(b, a % b); }

// LCM
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
//MSB
ll msb(ll num)
{
    for(int i=31;i>=0;i--)
    {
        if(num & (1<<i))return i;
    }
}
//***********************************************************************************************************************************//
//***********************************************************************************************************************************//

ll find(ll k,ll n,ll x,vector<ll>&dp)
{
    dp[0]=1LL+x;
    for(ll i=1LL;i<=k;i++)
    {
    ll tmp=(x*dp[i-1])%mod;
    if(n%2==0)
    dp[i]=(tmp+modpow(modpow(2LL,i,mod),n,mod))%mod;
    else
    dp[i]=(dp[i-1]+tmp)%mod;
    }
    return dp[k];
}
void solve(int tc)
{
ll n,k;
cin>>n>>k;
ll sum=0,ans=0,x=0;
if(n%2==0)
x=(modpow(2LL,n-1LL,mod)-1LL+mod)%mod;
else
x=modpow(2LL,n-1LL,mod);

if(k==0)
{
    cout<<1<<"\n";
    return;
}
vector<ll>dp(k);
cout<<find(k-1,n,x,dp);
cout<<"\n";
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int tc = 1;
    cin >> tc;
    for (int t = 1; t <= tc; t++) {

        solve(t);
    }
    return 0;
}

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

const ll MOD = ll(1e9 + 7);
ll mod30[30];
ll n, t, k;

ll calc_mod(ll x){
    // find the result of 2^x % MOD
    if(x < 30) return mod30[x];
    ll x1 = x/2;
    ll x2 = x - x1;
    return (calc_mod(x1) * calc_mod(x2)) % MOD;
}

int main(){
    mod30[0] = 1;
    for(int i = 1; i < 30; ++i)
        mod30[i] = mod30[i-1] * 2;

    cin >> t;
    while(t--){
        cin >> n >> k;
        ll zeroXOR = calc_mod(n - 1);
        ll r = calc_mod(n);

        // k == 0 or k == 1
        if(k == 0){
            cout << "1\n"; continue;
        }
        ll res = zeroXOR, curPow = 1;

        // k >= 2
        if(n % 2 == 0){
            for(int i = 2; i <= k; ++i){
                curPow = (curPow * r) % MOD;
                res = (curPow + (zeroXOR - 1) * res) % MOD;
            }
        }
        else{
            res += 1;
            for(int i = 2; i <= k; ++i)
                res = ((1 + zeroXOR) * res) % MOD;
        }
        cout << res << "\n";
    }

    return 0;
}

#include <map>
#include <cmath>
#include <queue>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;
#define For(i,s,e) for(int i=s;i<e;i++)
#define foR(i,s,e) for(int i=s;i>e;i--)
#define eb emplace_back
#define gtc getchar()
#define ll long long
#define fi first
#define se second
static char buf[100000],*pa=buf,*pd=buf;
#define gc pa==pd&&(pd=(pa=buf)+fread(buf,1,100000,stdin),pa==pd)?EOF:*pa++
ll ans;
ll n, m, t, k, a, b, c, d, cnt, mark, an;
ll mod = 1e9+7;

template<typename T>void p(T x) {
	if(x < 0) putchar('-'),x = -x;
	if (x > 9) p(x / 10);
	putchar(x % 10 + '0');return;
}

inline int read()
{
	register int x(0);register char c(gc);
	while(c<'0'||c>'9')c=gc;
	while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=gc;
	return x;
}

ll ksm(ll n, ll a) {
	n %= mod, a %= mod-1;
	ll res = 1;
	while (a) {
		if (a & 1) {
			res = res * n % mod;
		}
		n = n * n % mod;
		a >>= 1;
	}
	return res;
}

ll ny(ll a) {
	return ksm(a, mod-2);
}

int main () {
	t = read();
	while (t--) {
		n = read();
		k = read();
		if (k == 0) {
			printf("%d\n", 1);
			continue;
		}

		ll cnt = (ksm(2, n-1) + (n % 2) - 1 + mod) % mod;  //偶数等于的情况个数
		ll ans = 0;

		if (k == 1) {
			printf ("%lld\n", cnt+1);
			continue;
		}

		//printf ("%lld\n", (ll)cnt);

		if (n & 1) {
			ans = ksm(cnt+1, k);
		} else {
			ll q = cnt * ny(ksm(2, n)) % mod;
			ll a1 = ksm(2, n*(k-1));
			ans = a1 * (ksm(q, k) - 1) % mod * ny(q-1) % mod;
			ans = (ans + ksm(cnt, k)) % mod;
		}

		printf ("%lld\n", ans);

	}
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false),cin.tie(NULL)
ll MOD = 1e9 + 7;

void init_code()
{
    boost;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

const int N = 200005;
ll fact[N];

void factorial()
{
    fact[0] = 1;
    fact[1] = 1;
    for(int i=2; i<N; i++)
    {
        fact[i] = (fact[i-1] * i)%MOD;
    }
}

long long power(long long x,long long y)
{
    long long res = 1;
    while(y)
    {
        if(y&1)
        {
            res = (res*x)%MOD;
        }
        y = y>>1;
        x *= x;
        x %= MOD;
    }
   return res;
}

ll nCr(int n, int r){
    if(r>n) return 0;
    return (((fact[n]*power(fact[n-r],MOD-2))%MOD)*power(fact[r], MOD-2))%MOD;
}

ll modInv(ll n)
{
    return power(n, MOD-2);
}

void solve()
{
    ll n, k;
    cin>>n>>k;

    ll dp[k+1][2];
    dp[0][0] = 1;
    dp[0][1] = 0;

    // ll dp[k+1][2];

    ll even = 0, odd = 0;
    for(int i=0; i<n; i++)
    {
        if (i%2)
        {
            odd += nCr(n, i);
            odd %= MOD;
        }
        else
        {
            even += nCr(n, i);
            even %= MOD;
        }
    }
    // cout<<even<<" "<<odd<<endl;
    for(int i=0; i<k; i++)
    {
        // 2^N
        dp[i+1][1] = dp[i][1] * odd;
        dp[i+1][1] += dp[i][1] * even;
        dp[i+1][1] += dp[i][1];

        dp[i+1][0] = dp[i][0] * even;
        if (n % 2)
        {
            dp[i+1][0] += dp[i][0];
        }
        else
        {
            dp[i+1][1] += dp[i][0];
        }
        dp[i+1][0] %= MOD;
        dp[i+1][1] %= MOD;
        // cout<<"DP "<<dp[i+1][0]<<" "<<dp[i+1][1]<<endl;
    }

    cout<<(dp[k][0] + dp[k][1]) % MOD<<endl;
}

int main()
{
    init_code();
    factorial();
    int t;
    cin>>t;
    while(t--)
    {
        solve();
    }
}

#include<bits/stdc++.h>
using namespace std;
template <typename T>
T inverse(T a, T m) {
  T u = 0, v = 1;
  while (a != 0) {
    T t = m / a;
    m -= t * a; swap(a, m);
    u -= t * v; swap(u, v);
  }
  assert(m == 1);
  return u;
}

template <typename T>
class Modular {
 public:
  using Type = typename decay<decltype(T::value)>::type;

  constexpr Modular() : value() {}
  template <typename U>
  Modular(const U& x) {
    value = normalize(x);
  }

  template <typename U>
  static Type normalize(const U& x) {
    Type v;
    if (-mod() <= x && x < mod()) v = static_cast<Type>(x);
    else v = static_cast<Type>(x % mod());
    if (v < 0) v += mod();
    return v;
  }

  const Type& operator()() const { return value; }
  template <typename U>
  explicit operator U() const { return static_cast<U>(value); }
  constexpr static Type mod() { return T::value; }

  Modular& operator+=(const Modular& other) { if ((value += other.value) >= mod()) value -= mod(); return *this; }
  Modular& operator-=(const Modular& other) { if ((value -= other.value) < 0) value += mod(); return *this; }
  template <typename U> Modular& operator+=(const U& other) { return *this += Modular(other); }
  template <typename U> Modular& operator-=(const U& other) { return *this -= Modular(other); }
  Modular& operator++() { return *this += 1; }
  Modular& operator--() { return *this -= 1; }
  Modular operator++(int) { Modular result(*this); *this += 1; return result; }
  Modular operator--(int) { Modular result(*this); *this -= 1; return result; }
  Modular operator-() const { return Modular(-value); }

  template <typename U = T>
  typename enable_if<is_same<typename Modular<U>::Type, int>::value, Modular>::type& operator*=(const Modular& rhs) {
#ifdef _WIN32
    uint64_t x = static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value);
    uint32_t xh = static_cast<uint32_t>(x >> 32), xl = static_cast<uint32_t>(x), d, m;
    asm(
      "divl %4; \n\t"
      : "=a" (d), "=d" (m)
      : "d" (xh), "a" (xl), "r" (mod())
    );
    value = m;
#else
    value = normalize(static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value));
#endif
    return *this;
  }
  template <typename U = T>
  typename enable_if<is_same<typename Modular<U>::Type, long long>::value, Modular>::type& operator*=(const Modular& rhs) {
    long long q = static_cast<long long>(static_cast<long double>(value) * rhs.value / mod());
    value = normalize(value * rhs.value - q * mod());
    return *this;
  }
  template <typename U = T>
  typename enable_if<!is_integral<typename Modular<U>::Type>::value, Modular>::type& operator*=(const Modular& rhs) {
    value = normalize(value * rhs.value);
    return *this;
  }

  Modular& operator/=(const Modular& other) { return *this *= Modular(inverse(other.value, mod())); }

  friend const Type& abs(const Modular& x) { return x.value; }

  template <typename U>
  friend bool operator==(const Modular<U>& lhs, const Modular<U>& rhs);

  template <typename U>
  friend bool operator<(const Modular<U>& lhs, const Modular<U>& rhs);

  template <typename V, typename U>
  friend V& operator>>(V& stream, Modular<U>& number);

 private:
  Type value;
};

template <typename T> bool operator==(const Modular<T>& lhs, const Modular<T>& rhs) { return lhs.value == rhs.value; }
template <typename T, typename U> bool operator==(const Modular<T>& lhs, U rhs) { return lhs == Modular<T>(rhs); }
template <typename T, typename U> bool operator==(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) == rhs; }

template <typename T> bool operator!=(const Modular<T>& lhs, const Modular<T>& rhs) { return !(lhs == rhs); }
template <typename T, typename U> bool operator!=(const Modular<T>& lhs, U rhs) { return !(lhs == rhs); }
template <typename T, typename U> bool operator!=(U lhs, const Modular<T>& rhs) { return !(lhs == rhs); }

template <typename T> bool operator<(const Modular<T>& lhs, const Modular<T>& rhs) { return lhs.value < rhs.value; }

template <typename T> Modular<T> operator+(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) += rhs; }
template <typename T, typename U> Modular<T> operator+(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) += rhs; }
template <typename T, typename U> Modular<T> operator+(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) += rhs; }

template <typename T> Modular<T> operator-(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) -= rhs; }
template <typename T, typename U> Modular<T> operator-(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) -= rhs; }
template <typename T, typename U> Modular<T> operator-(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) -= rhs; }

template <typename T> Modular<T> operator*(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) *= rhs; }
template <typename T, typename U> Modular<T> operator*(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) *= rhs; }
template <typename T, typename U> Modular<T> operator*(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) *= rhs; }

template <typename T> Modular<T> operator/(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) /= rhs; }
template <typename T, typename U> Modular<T> operator/(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) /= rhs; }
template <typename T, typename U> Modular<T> operator/(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) /= rhs; }

template<typename T, typename U>
Modular<T> power(const Modular<T>& a, const U& b) {
  assert(b >= 0);
  Modular<T> x = a, res = 1;
  U p = b;
  while (p > 0) {
    if (p & 1) res *= x;
    x *= x;
    p >>= 1;
  }
  return res;
}

template <typename T>
bool IsZero(const Modular<T>& number) {
  return number() == 0;
}

template <typename T>
string to_string(const Modular<T>& number) {
  return to_string(number());
}

// U == std::ostream? but done this way because of fastoutput
template <typename U, typename T>
U& operator<<(U& stream, const Modular<T>& number) {
  return stream << number();
}

// U == std::istream? but done this way because of fastinput
template <typename U, typename T>
U& operator>>(U& stream, Modular<T>& number) {
  typename common_type<typename Modular<T>::Type, long long>::type x;
  stream >> x;
  number.value = Modular<T>::normalize(x);
  return stream;
}
constexpr int md = (int) 1e9 + 7;
using Mint = Modular<std::integral_constant<decay<decltype(md)>::type, md>>;

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt;
    cin >> tt;
    auto pow = [&](Mint x, int y) {
        Mint ans = 1;
        while (y) {
            if (y & 1) ans *= x;
            y >>= 1;
            x *= x;
        }
        return ans;
    };
    while (tt--) {
        int n, k;
        cin >> n >> k;
        Mint ans = 0, pre = 1;
        Mint p = pow(2, n), p1 = p / 2;
        for (int i = 0; i < k; ++i) {
            if (n & 1) {
                pre *= p1 + 1;
            } else {
                ans *= p;
                ans += pre;
                pre *= p1 - 1;
            }
        }
        ans += pre;
        cout << ans << '\n';
    }
    return 0;
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;
const int N=5e5+5;
int T,k,ans,pre,dp[N];
int fac[N],inv[N];
int ksm(int a,int b){
    int ret=1;
    while(b){
        if(b&1) ret=ret*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ret;
}
inline int C(int n,int m){
    return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int n;
signed main(){
    fac[0]=inv[0]=1;
    for(int i=1;i<=500000;i++){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=ksm(fac[i],mod-2);
    }
    scanf("%lld",&T);
    while(T--){
        ans=1;pre=1;
        scanf("%lld%lld",&n,&k);
        dp[0]=C(n,0);dp[1]=C(n,1);
        for(int i=2;i<=n;i++) dp[i]=(dp[i-2]+C(n,i))%mod;
        if(k==0){printf("1\n");continue;}
        if(n%2==1){
            for(int i=k;i>=1;i--){
                ans=ans*(dp[n-1]+1)%mod;
            }
        }
        else{
            ans=0;
            for(int i=k;i>=1;i--){
                ans=ans*(dp[n]-1)%mod;
            }
            for(int i=1;i<=k;i++){
                ans=(ans+ksm(dp[n-2],i-1)*ksm(dp[n-1]+dp[n-2]+1,k-i)%mod)%mod;
            }
            ans=(ans+ksm(dp[n-2],k))%mod;
        }
        printf("%lld\n",ans);
    }
}

#include<bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define em emplace_back
#define mem(x,t) memset((x),t,sizeof(x))
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define space " "
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define debug(x) cerr << #x << ": " << x << endl
#define sz(x) ((int)(x.size()))
#define endl '\n'
#define YESNO(x) if(x)cout<<"YES\n";else cout<<"NO\n";
#define YesNo(x) if(x)cout<<"Yes\n";else cout<<"No\n";
#define yesno(x) if(x)cout<<"yes\n";else cout<<"no\n";
#define outln(x) cout<<x<<endl;
#define outspace(x) cout<<x<<" ";
#define getSum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define getMinValue(a)    (*min_element((a).begin(), (a).end()))
#define getMaxValue(a)    (*max_element((a).begin(), (a).end()))
#define getMinIndex(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define getMaxIndex(a)    ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())
using namespace std;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename T> __lcm(T a, T b){
    return (a/__gcd(a,b))*b;
}

template<typename T> bool chkmax(T& x, T y) {
    return x < y ? x = y, 1 : 0;
}
template<typename T> bool chkmin(T& x, T y) {
    return x > y ? x = y, 1 : 0;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename T>
void getdata(vector<T> &data){
    for(auto &one:data)cin>>one;
}
template<class A> ostream& operator <<(ostream& out, const vector<A>& v) {
    for (auto& x : v) {
        cout << x << " ";
    }
    return out;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//const auto rng_seed = std::chrono::system_clock::now().time_since_epoch().count();
//std::mt19937_64 rng(rng_seed);
//std::uniform_int_distribution<long long> range(0, 100000);// rng() or range(rng)
const int maxn = 200010;
const int inf = 2147483647;
const int  mod = 1000000007;
using lint  = long long;
using pii = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vector<int> >;
using vlong = vector<long long>;
using vpii = vector<pair<int, int> >;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

template <int M>
struct MInt {
    unsigned int val;
    MInt() : val(0) {}
    MInt(long long x) : val(x >= 0 ? x % M : x % M + M) {}
    static constexpr int get_mod() { return M; }
    static void set_mod(int divisor) { assert(divisor == M); }
    static void init(int x = 10000000) { inv(x, true); fact(x); fact_inv(x); }
    static MInt inv(int x, bool init = false) {
        // assert(0 <= x && x < M && std::__gcd(x, M) == 1);
        static std::vector<MInt> inverse{ 0, 1 };
        int prev = inverse.size();
        if (init && x >= prev) {
            inverse.resize(x + 1);
            for (int i = prev; i <= x; ++i) inverse[i] = -inverse[M % i] * (M / i);
        }
        if (x < inverse.size()) return inverse[x];
        unsigned int a = x, b = M; int u = 1, v = 0;
        while (b) {
            unsigned int q = a / b;
            std::swap(a -= q * b, b);
            std::swap(u -= q * v, v);
        }
        return u;
    }
    static MInt fact(int x) {
        static std::vector<MInt> f{ 1 };
        int prev = f.size();
        if (x >= prev) {
            f.resize(x + 1);
            for (int i = prev; i <= x; ++i) f[i] = f[i - 1] * i;
        }
        return f[x];
    }
    static MInt fact_inv(int x) {
        static std::vector<MInt> finv{ 1 };
        int prev = finv.size();
        if (x >= prev) {
            finv.resize(x + 1);
            finv[x] = inv(fact(x).val);
            for (int i = x; i > prev; --i) finv[i - 1] = finv[i] * i;
        }
        return finv[x];
    }
    static MInt nCk(int n, int k) {
        if (n < 0 || n < k || k < 0) return 0;
        if (n - k > k) k = n - k;
        return fact(n) * fact_inv(k) * fact_inv(n - k);
    }
    static MInt nPk(int n, int k) { return n < 0 || n < k || k < 0 ? 0 : fact(n) * fact_inv(n - k); }
    static MInt nHk(int n, int k) { return n < 0 || k < 0 ? 0 : (k == 0 ? 1 : nCk(n + k - 1, k)); }
    static MInt large_nCk(long long n, int k) {
        if (n < 0 || n < k || k < 0) return 0;
        inv(k, true);
        MInt res = 1;
        for (int i = 1; i <= k; ++i) res *= inv(i) * n--;
        return res;
    }
    MInt pow(long long exponent) const {
        MInt tmp = *this, res = 1;
        while (exponent > 0) {
            if (exponent & 1) res *= tmp;
            tmp *= tmp;
            exponent >>= 1;
        }
        return res;
    }
    MInt& operator+=(const MInt& x) { if ((val += x.val) >= M) val -= M; return *this; }
    MInt& operator-=(const MInt& x) { if ((val += M - x.val) >= M) val -= M; return *this; }
    MInt& operator*=(const MInt& x) { val = static_cast<unsigned long long>(val) * x.val % M; return *this; }
    MInt& operator/=(const MInt& x) { return *this *= inv(x.val); }
    bool operator==(const MInt& x) const { return val == x.val; }
    bool operator!=(const MInt& x) const { return val != x.val; }
    bool operator<(const MInt& x) const { return val < x.val; }
    bool operator<=(const MInt& x) const { return val <= x.val; }
    bool operator>(const MInt& x) const { return val > x.val; }
    bool operator>=(const MInt& x) const { return val >= x.val; }
    MInt& operator++() { if (++val == M) val = 0; return *this; }
    MInt operator++(int) { MInt res = *this; ++* this; return res; }
    MInt& operator--() { val = (val == 0 ? M : val) - 1; return *this; }
    MInt operator--(int) { MInt res = *this; --* this; return res; }
    MInt operator+() const { return *this; }
    MInt operator-() const { return MInt(val ? M - val : 0); }
    MInt operator+(const MInt& x) const { return MInt(*this) += x; }
    MInt operator-(const MInt& x) const { return MInt(*this) -= x; }
    MInt operator*(const MInt& x) const { return MInt(*this) *= x; }
    MInt operator/(const MInt& x) const { return MInt(*this) /= x; }
    friend std::ostream& operator<<(std::ostream& os, const MInt& x) { return os << x.val; }
    friend std::istream& operator>>(std::istream& is, MInt& x) { long long val; is >> val; x = MInt(val); return is; }
};
using mint=MInt<mod>;

void wtf(){
    mint::init(maxn);
}
void   todo() {
    int n,k;
    cin>>n>>k;
    mint ans=1;
    mint two=2;
    mint a=two.pow(n-1);
    if(n%2==0){
        a--;
        mint b=two.pow(n);
        for(int i=0;i<k;i++)ans=ans*a+b.pow(i);
    }else {
        a++;
        for(int i=0;i<k;i++)ans*=a;
    }
    cout<<ans<<endl;
}

int main() {
//    fastio;
    cout << setprecision(10);
    cout << fixed;
    int cas = 1;
    cin >> cas;
    wtf();
    while (cas--) {
//        YESNO(todo());
        todo();
    }

    return 0;
}

#include<bits/stdc++.h>
//#pragma GCC optimize(2)
using namespace std;
#define int long long
#define fi first
#define se second
#define endl '\n'
#define PII pair<int,int>
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
const int N=1e6+5,mod=1e9+7;
int h[N],e[N],nx[N],idx;
int k,T,t,n,m,ans,cnt;
int a[N];
bool vis[N];
priority_queue <int,vector<int>,greater<int> > q;
int ksm(int a,int b)
{
        int res=1;
        while(b)
        {
                if(b&1) res=res*a%mod;
                b>>=1;
                a=a*a%mod;
        }
        return res%mod;
}
signed main()
{
        ios::sync_with_stdio(false);
         cin.tie(0),cout.tie(0);
        cin>>T;
        while(T--)
        {
                cin>>n>>k;
                int c=ksm(2,n-1);
                if(n&1) c=(c+1)%mod;
                else c=(c-1+mod)%mod;
                ans=ksm(c,k);
                if(n%2==0)
                {
                        for(int i=1;i<=k;i++)
                        {
                                int x=ksm(c,i-1);
                                int y=ksm(2,(k-i)*n);
                                ans=(ans+x*y%mod)%mod;
                        }
                }
                cout<<ans<<endl;
        }

        return 0;
}

#include <map>
#include <cmath>
#include <queue>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;
#define eb emplace_back
#define Pii pair<int, int>
#define fi first
#define se second
#define gtc getchar()
#define ll long long
ll n, m, t, k, a, b, c, d, cnt, mark, an, T;

ll mod = 1e9 + 7;

ll ksm(ll n, ll a) {
	n = (n+mod) % mod;
	ll res = 1;
	while (a) {
		if (a % 2) {
			res = res * n % mod;
		}
		n = n * n % mod;
		a >>= 1;
	}
	return res;
}

int main () {
	//ios::sync_with_stdio(false);
	scanf ("%lld", &T);
	while (T--) {
		ll ans = 0;
		scanf ( "%lld%lld", &n, &k);
//		if (k == 0) {
//			puts("1");
//			continue;
//		}

		if (n == 1) {
			printf ("%lld\n", ksm(2,k));
			continue;
		}

		ll c = ((ksm(2, n-1) + n % 2 - 1 + mod )%mod + mod) % mod;

//		if (k == 1) {
//			printf ("%lld\n", c+1);
//			continue;
//		}
		int kk = 1;
		if (n % 2) {
			ans = ksm(c+1, k);
		} else {
			for (ll i = 1; i <= k; i++) {
				ans = (ans + ksm(2, n*(k-i)) * kk % mod) % mod;
				kk = kk * c % mod;
			}
			ans = (ans + kk) % mod;
		}
		printf ("%lld\n", ans);

	}
}

#include<iostream>
using namespace std;
int MOD=1e9+7;
long long pow(long long a,long long b)
{
	long long ans=1,now=a;
	while(b)
	{
		if(b&1)ans=ans*now%MOD;
		now=now*now%MOD;
		b>>=1;
	}
	return ans%MOD;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		long long a,b;
		cin>>a>>b;
		if(b==0)cout<<1<<endl;
		else if(a&1)cout<<pow(1+pow(2,a-1),b)<<endl;
		else
		{
			long long ans=1,p=(pow(2,a-1)-1)%MOD;
			for(int i=1;i<=b;i++)
			{
				ans=(ans*p)%MOD;
				ans=(ans+pow(2,(i-1)*a))%MOD;
			}
			cout<<ans<<endl;
		}
	}
	return 0;
}

#include<cstdio>
#include<iostream>
const int mod = 1000000007;
using namespace std;

long long qmi(long long a, long long b) {
    long long res = 1;
    while(b) {
        if(b & 1) res = (res * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}

void solve() {
    int n, k;
    scanf("%d%d", &n, &k);
    long long a = qmi(2, n - 1) - !(n & 1);
    int b = qmi(2, n - 1) - (n & 1);
    int c = !(n & 1);
    int d = n & 1;
    long long ans = 0;
    for (int i = 1; i <= k;i ++) {
        int left = i - 1;
        int right = k - i;
        long long temp = 1;
        temp *= qmi(a + d, left);
        temp %= mod;
        temp *= qmi(a + b + c + d, right);
        temp %= mod;
        temp *= c;
        temp %= mod;
        ans += temp;
        ans %= mod;
    }
    ans += qmi(a + d, k);
    ans %= mod;
    cout << ans << endl;
}
int main() {
    int t;
    scanf("%d", &t);
    while(t --) {
        solve();
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define AC return
#define Please 0
#define itn int
#define enld '\n'       //IO?
#define endl '\n'       //IO?
#define Endl '\n'       //IO?
#define esle else
#define ciN cin
#define YES "YES"
#define NO "NO"
#define eb emplace_back
#define wide(x,ch) setw(x)<<setfill(ch)
#define show "ans-------------> "<<
class MyCpiise{public:bool operator()(pair<int,int> a,pair<int,int> b){return a.second<b.second;}};
MyCpiise Mcse;
#define dbg(x...) do{cout<<#x<<" -> ";err(x);}while (0)
void err(){cout<<'\n';}
template<class T, class... Ts>
void err(T arg, Ts... args) {
    cout<<arg<< ' ';
    err(args...);
}
template<typename T>
T read(T judge){
    T x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9') {if(c=='-') f=-1;c=getchar();}
    while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+c-'0',c=getchar();
    return f*x;
}
inline void reads(){return;}
template<class T,class... Ts>
inline void reads(T &x,Ts&... xs) {
    x=0;
    char c=getchar();
    while('0'<=c&&c<='9') {
        x=(x<<3)+(x<<1)+(c^48);
        c=getchar();
    }
    reads(xs...);
}
template<typename T>
void print(T x){
    if (x<0) putchar('-'),x=-x;
    if (x/10) print(x/10);
    putchar(x%10+'0');
}
mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
long long rng(long long l, long long r) {
    uniform_int_distribution<long long> uni(l, r);
    return uni(mt);
}

#define int long long                        //int main()->signed main()?
#define INF 0x3f3f3f3f
#define LLINF 9223372036854775807
#define pii pair<int,int>
#define pip pair<int,pii >
#define ppi pair<pii ,int>
#define ppp pair<pii ,pii >
const int MOD1=998244353;
const int MOD2=1e9+7;
const int N4=1e4+10;
const int N5=1e5+10;
const int NN5=2e5+10;
const int N6=1e6+7;
const int N7=1e7+10;
const int N8=1e8+10;
const int N9=1e9+5;
int dr[4]={0,1,0,-1};
int dc[4]={1,0,-1,0};
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define is_odd(x) (x&1)
#define lowbit(x) (x&(-x))
void bin_print(int now,int cnt){
    if(!cnt) return;
    bin_print(now>>1,cnt-1);
    cout<<(now&1);
}
int fast_pow(int x,int n=MOD2-2,int mod=MOD2,int ret=1){
    while(n){
        if(n&1) ret=ret*x%mod;
        x=x*x%mod;
        n>>=1;
    }
    return ret;
}
long long fast_ll_pow(long long x,long long n,long long ret=1){
    while(n){
        if(n&1) ret=ret*x;
        x=x*x;
        n>>=1;
    }
    return ret;
}
int exgcd(int a,int b,int &x,int &y){
    if(!b){x=1;y=0;return a;}
    else{int ret=exgcd(b,a%b,y,x);y-=a/b*x;return ret;}
}
int gcd(int a,int b){return !b ? a : gcd(b,a%b);}
typedef long long ll;
int f[NN5]={1};
int solveeve(int n,int k)
{
    if(k==0) return 1;
    int ans=0;
    int cc=1;
    int last=1;
    for(int i=2;i<=n-2;i+=2){
        last=(last*(n-i+2)%MOD2*(n-i+1)%MOD2*fast_pow(i)%MOD2*fast_pow(i-1))%MOD2;
        cc=(cc+last)%MOD2;
    }
    for(int i=1;i<=k;i++){
        ans=(ans+fast_pow(f[n],i-1,MOD2)*fast_pow(cc,k-i,MOD2)%MOD2)%MOD2;
    }
    ans=(ans+fast_pow(cc,k,MOD2))%MOD2;
    return ans;
}
int solveodd(int n,int k)
{
    int ans=0;
    int cc=1;
    int last=1;
    for(int i=2;i<=n-1;i+=2){
        last=(last*(n-i+2)%MOD2*(n-i+1)%MOD2*fast_pow(i)%MOD2*fast_pow(i-1))%MOD2;
        cc=(cc+last)%MOD2;
//        dbg(last);
    }
//    dbg(cc);
    ans=(ans+fast_pow(cc+1,k,MOD2))%MOD2;
    return ans;
}
void run()
{
    int n,k;
    cin>>n>>k;
    if(n%2==0) cout<<solveeve(n,k)<<endl;
    else cout<<solveodd(n,k)<<endl;

/*------------------------dbg----------------------------*/

    return;
    //T==1?
}
signed main()
{
//    freopen("D:\\MY_std_input\\std_input.txt", "r", stdin);
//    freopen("D:\\MY_std_input\\std_output1.txt", "w", stdout);
//    freopen("D:\\MY_std_input\\std_output2.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    // system("cls");
    for(int i=1;i<NN5;i++) f[i]=f[i-1]*2%MOD2;
    int T=1;
     cin>>T;
    while(T--)
    {
        run();
    }

    AC Please;
}
// "str.size()-num" --> "(int)str.size()-num" ?
/*
    sort(edge[i].begin(), edge[i].end(), [&](pii &a, pii &b){
        ......
    });
*/

#include<bits/stdc++.h>

using namespace std;
typedef long long Long;

const int Maxn = 2e5 + 11, Mod = 1e9 + 7;
Long fact[Maxn];
Long n, k, evenSum;
Long dp[Maxn][5];

Long bMOD(int a, int b)
{
    if(b == 0)
        return 1ll;
    Long ans = bMOD(a, b / 2);
    ans = (ans * ans) % Mod;

    if(b & 1) ans = (ans * a) % Mod;
    return ans;
}
void call()
{
    fact[0] = 1;
    for(int i=1; i<Maxn; i++){
        fact[i] = (fact[i-1] * i) % Mod;
    }
}
Long nCr(int n, int r)
{
    Long res = (fact[r] * fact[n-r]) % Mod;
    res = bMOD(res, Mod - 2);
    res = (res * fact[n]) % Mod;
    return res;
}
Long solve(int pos, int flag)
{
    if(pos >= k) return 1ll;
    if(dp[pos][flag] != -1){
        return dp[pos][flag];
    }
    Long ret = 0;
    if(flag){
        ret = (bMOD(2, n) * solve(pos + 1, flag)) % Mod;
    }
    else{
        ret = (evenSum * solve(pos + 1, flag)) % Mod;
        if(n & 1){
            ret = (ret + solve(pos + 1, flag)) % Mod;
        }
        else{
            ret = (ret + solve(pos + 1, 1)) % Mod;
        }
    }
    return dp[pos][flag] = ret;
}
int main()
{
    call();
    int t;
    cin >> t;
    while(t--) {
        cin >> n >> k;
        evenSum = 0;
        for(int i = 0; i < n; i += 2) {
            evenSum = (evenSum + nCr(n, i)) % Mod;
        }
        memset(dp, -1, sizeof dp);
        Long answer = solve(0, 0) % Mod;
        cout << answer << endl;
    }
    return 0;
}

// Problem: C. Moamen and XOR
// Contest: Codeforces - Codeforces Round #737 (Div. 2)
// URL: https://codeforces.com/problemset/problem/1557/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

/*** keep hungry and calm PushyTao!***/
/**
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize (2)
#pragma G++ optimize (2)
**/
///new template
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
typedef long long ll;
#define HEAP(...) priority_queue<__VA_ARGS__>
#define heap(...) priority_queue<__VA_ARGS__, vector<__VA_ARGS__>, greater<__VA_ARGS__>>
template <class T>
inline T min(T &x, const T &y) {
    return x > y ? y : x;
}
template <class T>
inline T max(T &x, const T &y) {
    return x < y ? y : x;
}
ll read() {
    ll c = getchar(), Nig = 1, x = 0;
    while (!isdigit(c) && c != '-') c = getchar();
    if (c == '-') Nig = -1, c = getchar();
    while (isdigit(c)) x = ((x << 1) + (x << 3)) + (c ^ '0'), c = getchar();
    return Nig * x;
}
#define read read()
namespace usual {
inline ll gcd(ll a, ll b) {
    ll t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}
inline ll qPow(ll x, ll k) {
    ll res = 1;
    while (k) {
        if (k & 1) res = (res * x) % 1000000007;
        k >>= 1;
        x = (x * x) % 1000000007;
    }
    return res;
}
inline ll oula(ll x) {
    ll res = x;
    for (ll i = 2; i <= x / i; i++) {
        if (x % i == 0) {
            res = res / i * (i - 1);
            while (x % i == 0) x /= i;
        }
    }
    if (x > 1) res = res / x * (x - 1);
    return res;
}
inline void write(ll x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    if (x > 9) write(x / 10);
    putchar(x % 10 + '0');
}
} // namespace usual
using namespace usual;
priority_queue<int, vector<int>, greater<int>> xiaogen;
priority_queue<int, vector<int>, less<int>> dagen;
const ll inf   = 9223372036854775807;
const ll INF   = 0x3f3f3f3f;
const int maxn = 2e5 + 7;
const int mod  = 1000000007;
#define PI (double)acos(-1.0)
#define debug(x) cout << #x << "  ->  " << x << endl
#define IOS                      \
    ios::sync_with_stdio(false); \
    cin.tie(NULL);               \
    cout.tie(NULL);
#define lowbit(x) (x & (-x))
#define Clear(x, val) memset(x, val, sizeof x)
ll fact[maxn], infact[maxn];
void init() {
    fact[0] = infact[0] = 1;
    for (int i = 1; i <= 200000; i++) {
        fact[i]   = fact[i - 1] * i % mod;
        infact[i] = infact[i - 1] * qPow(i, mod - 2) % mod;
    }
}
ll C(ll n, ll m) {
    return fact[n] * infact[n - m] % mod * infact[m] % mod;
}
ll n, m;
int main() {
    init();
    int T = read;
    while (T--) {
        ll ans = 0;
        n = read, m = read;
        if (m == 0) {
            puts("1");
            continue;
        }
        if (n % 2) {
            ans = qPow((qPow(2, n - 1) + 1) % mod, m);
        } else {
            ll t = 0;
            /**
            for (int i = 0; i <= n - 2; i += 2) {
                t = (t + C(n, i)) % mod;
            }
            **/
            t   = qPow(2, n - 1) - 1;
            ans = qPow(t, m);
            for (int i = 1; i <= m; i++) {
                ans = (ans + qPow(t, i - 1) * qPow(2, n * (m - i))) % mod;
            }
        }
        printf("%lld\n", ans);
    }
    return 0;
}
/**

**/

// Problem: C. Moamen and XOR
// Contest: Codeforces - Codeforces Round #737 (Div. 2)
// URL: https://codeforces.com/problemset/problem/1557/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

/*** keep hungry and calm PushyTao!***/
/**
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize (2)
#pragma G++ optimize (2)
**/
///new template
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
typedef long long ll;
#define HEAP(...) priority_queue<__VA_ARGS__>
#define heap(...) priority_queue<__VA_ARGS__, vector<__VA_ARGS__>, greater<__VA_ARGS__>>
template <class T>
inline T min(T &x, const T &y) {
    return x > y ? y : x;
}
template <class T>
inline T max(T &x, const T &y) {
    return x < y ? y : x;
}
ll read() {
    ll c = getchar(), Nig = 1, x = 0;
    while (!isdigit(c) && c != '-') c = getchar();
    if (c == '-') Nig = -1, c = getchar();
    while (isdigit(c)) x = ((x << 1) + (x << 3)) + (c ^ '0'), c = getchar();
    return Nig * x;
}
#define read read()
namespace usual {
inline ll gcd(ll a, ll b) {
    ll t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}
inline ll qPow(ll x, ll k) {
    ll res = 1;
    while (k) {
        if (k & 1) res = (res * x) % 1000000007;
        k >>= 1;
        x = (x * x) % 1000000007;
    }
    return res;
}
inline ll oula(ll x) {
    ll res = x;
    for (ll i = 2; i <= x / i; i++) {
        if (x % i == 0) {
            res = res / i * (i - 1);
            while (x % i == 0) x /= i;
        }
    }
    if (x > 1) res = res / x * (x - 1);
    return res;
}
inline void write(ll x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    if (x > 9) write(x / 10);
    putchar(x % 10 + '0');
}
} // namespace usual
using namespace usual;
priority_queue<int, vector<int>, greater<int>> xiaogen;
priority_queue<int, vector<int>, less<int>> dagen;
const ll inf   = 9223372036854775807;
const ll INF   = 0x3f3f3f3f;
const int maxn = 2e5 + 7;
const int mod  = 1000000007;
#define PI (double)acos(-1.0)
#define debug(x) cout << #x << "  ->  " << x << endl
#define IOS                      \
    ios::sync_with_stdio(false); \
    cin.tie(NULL);               \
    cout.tie(NULL);
#define lowbit(x) (x & (-x))
#define Clear(x, val) memset(x, val, sizeof x)
ll fact[maxn], infact[maxn];
void init() {
    fact[0] = infact[0] = 1;
    for (int i = 1; i <= 200000; i++) {
        fact[i]   = fact[i - 1] * i % mod;
        infact[i] = infact[i - 1] * qPow(i, mod - 2) % mod;
    }
}
ll C(ll n, ll m) {
    return fact[n] * infact[n - m] % mod * infact[m] % mod;
}
ll n, m;
int main() {
    init();
    int T = read;
    while (T--) {
        ll ans = 0;
        n = read, m = read;
        if (m == 0) {
            puts("1");
            continue;
        }
        if (n % 2) {
            ans = qPow((qPow(2, n - 1) + 1) % mod, m);
            /**
            ll t = 1;
            for (int i = 0; i <= n - 1; i += 2) {
 				t = (t + C(n,i)) % mod;
            }
            ans = qPow(t,m);
            **/
        } else {
            ll t = 0;
            for (int i = 0; i <= n - 2; i += 2) {
                t = (t + C(n, i)) % mod;
            }
            ans = qPow(t, m);
            for (int i = 1; i <= m; i++) {
                ans = (ans + qPow(t, i - 1) * qPow(2, n * (m - i))) % mod;
            }
        }
        printf("%lld\n", ans);
    }
    return 0;
}
/**

**/

#include<iostream>
#include<cstdio>
using namespace std;

const int maxn = 5e5 + 10;
const int mod = 1e9 + 7;

long long dp[maxn], save[maxn];
int n, k;
long long fac[maxn];
long long inv[maxn];

long long C(long long m, long long n)
{
    long long res = fac[m] % mod;
    res = (fac[m] * inv[n]) % mod;
    //cout << res << endl;
    res = (res * inv[m - n]) % mod;
    return res % mod;
}

long long qpow(long long a, long long b)
{
    long long res = 1;
    while(b)
    {
        if(b & 1)
        {
            res *= a;
            res %= mod;
        }
        a *= a;
        a %= mod;
        b /= 2;
    }
    return res % mod;
}

void init()
{
    save[0] = 1;
    for(int i = 1; i <= n / 2; i++)
    {
        save[i] = (save[i - 1] + C(n, i * 2)) % mod;
    }
}

int main()
{
    int t;
    scanf("%d", &t);
    fac[0] = 1;

    for(long long i = 1; i <= 200010; i++)
    {
        fac[i] = (fac[i - 1] * i) % mod;
    }

    inv[0] = 1;
    inv[200010] = qpow(fac[200010], mod - 2);
    //cout << (fac[200010] * inv[200010]) % mod << endl;
    for(long long i = 200009; i >= 1; i--)
    {
        inv[i] = (inv[i + 1] * (i + 1)) % mod;
    }
    //cout << C(4, 2) << endl;
    while(t--)
    {
        scanf("%d%d", &n, &k);

        init();

        dp[0] = 1;

        for(int i = 1; i <= k; i++)
        {
            if(n % 2 == 0)
            {
                dp[i] = (dp[i - 1] * save[n / 2 - 1]) % mod;
                dp[i] = (dp[i] + qpow(qpow(2, i - 1), n)) % mod; ///

            }
            else if(n % 2 == 1)
            {
               // cout << save[n / 2] << endl;
                dp[i] = (dp[i - 1] * (save[n / 2] + 1)) % mod; /// 全选1 1种，剩下的情况就是选择x对1，才能保证异或出的答案为0
            }
        }
        printf("%lld\n", dp[k]);
    }

}

#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <ctime>
#include <bitset>
#include <string>
#include <cstdio>
#include <vector>
#include <fstream>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

long long MOD=1000000007;

long long fast_mod(long long x, long long y) {
    if (y == 0) return 1LL;
    long long ret = fast_mod(x, y>>1);
    ret = (ret*ret)%MOD;
    if (y&1) ret = (ret*x)%MOD;
    return ret;
}

bool work() {
    long long n, k;
    scanf("%lld%lld", &n, &k);
    if (k == 0) {
        printf("1\n");
        return 0;
    }
    if (n&1) {
        printf("%lld\n", fast_mod(fast_mod(2, n-1)+1, k));
    } else {
        long long t2 = fast_mod(2, n-1)-1;
        long long p = t2 * fast_mod(fast_mod(2, n), MOD-2) % MOD;
        long long ans = fast_mod(2, (k-1)*n);
        p = (1LL-fast_mod(p, k)) * fast_mod(1-p, MOD-2) % MOD;
        // printf("p=%lld\n", p);
        ans = (ans*p%MOD) + fast_mod(t2, k);
        ans = (ans%MOD+MOD)%MOD;
        printf("%lld\n", ans);
    }

}

int main() {
#ifndef ONLINE_JUDGE
    // freopen("../input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int start_time = clock();
#endif
    int TestCase = 1;
    scanf("%d", &TestCase);
    while (TestCase --) {
        work();
    }
#ifndef ONLINE_JUDGE
    cerr << "running time = " << (clock() - start_time) / 1000. << " ms" << endl;
#endif
    return 0;
}

#include<iostream>
using namespace std;
typedef unsigned long long int ll;
const ll mod = 1e9 + 7, N = 200010;
ll fac[N], ifac[N];
ll qpow(ll a, ll b) {
	ll res = 1;
	while (b) {
		if (b & 1) res = (res * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return res;
}

int main()
{
	int t, n, k,i;
	fac[0] = ifac[0] = 1;
	for (i = 1; i < N; i++) fac[i] = fac[i - 1] * i % mod;
	ifac[N - 1] = qpow(fac[N - 1], mod - 2);
	for (i = N - 2; i; i--) ifac[i] = ifac[i + 1] * (i + 1) % mod;

	cin >> t;
	while (t--)
	{
		cin >> n >> k;
		ll m = 0, ans = 0, base = 1;
		for (i = 0; i < n; i += 2) {
			m = (m + (ifac[i] * ifac[n - i]) % mod) % mod;
		}
		m = (m * fac[n]) % mod;
		m = (m + (n & 1)) % mod;
		ll n2 = qpow(2, n);
		for (i = k; i; i--) {
			if ((n & 1) == 0) ans = (ans + qpow(n2, i - 1) * base % mod) % mod;
			base = (base * m) % mod;
		}
		ans = (ans + base) % mod;
		cout << ans << endl;
	}
}

#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <vector>
#include <cstring>
#include <array>
#include <iomanip>
#include <bitset>
#define endl '\n'
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
const int N = 200100, M = 510, INF = 2e9, MOD = 1e9 + 7;
LL a[N];
int n;

int qmi(int a, int b)
{
	int res = 1;
	while (b)
	{
		if(b & 1) res = (LL)a * res % MOD;
		b >>= 1;
		a = (LL)a * a % MOD;
	}

	return res;
}

//注意观察N的大小
void solve()
{
	int n, k;
	cin >> n >> k;
	int ans = 1;

	int t = qmi(2, n - 1);
	if (n % 2 == 1)
	{
		ans = qmi(t + 1, k) % MOD;
	}
	else {
		ans = qmi(t - 1, k) % MOD;
		for (int i = k; i >= 1; i --)
		{
			ans = (ans + (LL)qmi(t - 1, i - 1) * qmi(t * 2, k - i)) % MOD;
		}
	}

	cout << ans << endl;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	cin >> t;

	while (t--)
	{
		solve();
	}

	return 0;
}

#include <cstdio>
using namespace std;
const int mod = 1e9 + 7;
long long t, n, k;
long long power(long long x, long long p)
{
    long long ans = 1;
    while (p)
    {
        if (p & 1) ans = ans * x % mod;
        p >>= 1;
        x = x * x % mod;
    }
    return ans;
}
int main()
{
    for (scanf("%lld", &t); t--;)
    {
        scanf("%lld%lld", &n, &k);
        long long ans = 0;
        if (n & 1)
            ans = power(power(2, n - 1) + 1, k);
        else
        {
            ans = power((power(2, n - 1) + mod - 1) % mod, k);
            for (int i = 0; i < k; ++i)
                ans = (ans + power((power(2, n - 1) + mod - 1) % mod, i) * power(2, n * (k - 1 - i)) % mod) % mod;
        }

        printf("%lld\n", ans);
    }
    return 0;
}

#include <bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long int ll;
#define inf 1e16
#define mod 1000000007
#define mod1 998244353
#define mod2 999983
#define N 200005
//***DON'T GET STUCK ON ONE APPROACH
ll power(ll a, ll n)
{
    if (n == 0)
        return 1;
    ll x = power(a, n / 2);
    if (n % 2 != 0)
        return a * x * x;
    else
        return x * x;
}
ll power(ll a, ll n, ll m)
{
    if (n == 0)
        return 1;
    ll x = power(a, n / 2, m);
    if (n % 2 != 0)
        return (((a * x) % m) * (x) % m) % m;
    else
        return (x * x) % m;
}
int32_t main()
{
    ll i, n, j, x, y, m, k, t, sum, count, cnt, b, c, d, j1, z, a, o, temp;
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> t;
    while (t--)
    {
        cin >> n >> k;
        if (k == 0)
        {
            cout << "1\n";
            continue;
        }
        if (n % 2 == 0)
        {
            x = power(2, n - 1, mod);
            x--;
            x = (x + mod) % mod;
            ll ans = power(x, k, mod);
            a = 1;
            for (ll i = k - 1; i >= 0; i--)
            {
                y = power(2, n, mod) % mod;
                y = power(y, i, mod);
                y = (y * a) % mod;

                a = (a * (x)) % mod;
                ans = (ans + y) % mod;
            }
            cout << ans << "\n";
        }
        else
        {
            x = power(2, n - 1, mod);
            ll ans = power(x + 1, k, mod);
            a = 1;
            // for (ll i = k - 1; i >= 0; i--)
            // {
            //     y = power(x + 1, i, mod) % mod;
            //     y = (a * y) % mod;

            //     a = (a * (x + 1)) % mod;
            //     ans = (ans + y) % mod;
            // }
            cout << (ans) % mod << "\n";
        }
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define co 200005
#define int long long int
#define Int int
#define vi vector<int>
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define sz(x) ((int)(x).size())
#define loop(n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
int pow2[co + 1];
void pow3()
{
    pow2[0] = 1;
    for (int i = 1; i <= co; i++)
    {
        pow2[i] = (pow2[i - 1] * 2) % mod;
    }
}
int pow4(int n, int k)
{
    int res = 1;
    while (k)
    {
        if (k & 1)
            res = (res % mod * n % mod) % mod, k--;
        n = (n % mod * n % mod) % mod;
        k >>= 1;
    }
    return res;
}
// int ans(int n, int k)
// {
//     if (k == 0)
//     {
//         return 1;
//     }

//     return (pow4(2, n * (k - 1)) * (n % 2 == 0 ? 1 : 0) + ((pow2[n - 1] + (n % 2 == 0 ? -1 : 1)) % mod) * ans(n, k - 1) % mod) % mod;
// }
int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    pow3();
    int T = 1;
    cin >> T;
    while (T--)
    {
        int n, k;
        cin >> n >> k;
        int ans[k + 1];
        ans[0] = 1;
        for (int i = 1; i <= k; i++)
        {
            ans[i] = ((n % 2 == 0 ? pow4(2, n * i - n) : 0) + (pow2[n - 1] + (n % 2 == 0 ? -1 : 1)) * ans[i - 1] % mod) % mod;
        }
        cout << ans[k] << endl;
    }
    return 0;
}

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
const int mod = 1e9 + 7;
long long qpow(long long a, long long b)
{
    long long res = 1;
    while(b)
    {
        if(b & 1)
        {
            res *= a;
            res %= mod;
        }
        a *= a;
        a %= mod;
        b /= 2;
    }
    return res % mod;
}
int main()
{
    int t;
    scanf("%d", &t);
    while(t--)
    {
        int n, num;
        scanf("%d%d", &n, &num);
        if(n % 2 == 0)
        {
            long long ans = 0;
            for(int i = 1; i <= num; i++)
            {
                long long temp = qpow(2, num - i);
                long long temp2 = (qpow(2, n - 1) - 1 + mod) % mod;;
                ans = (ans + ((qpow(temp, n) % mod) * (qpow(temp2, i - 1) % mod) % mod)) % mod;
            }
            long long temp3 = (qpow(2, n - 1) - 1 + mod) % mod;
            ans = (ans + qpow(temp3, num)) % mod;
            printf("%lld\n", ans);
        }
        if(n % 2 == 1)
        {
            long long temp4 = qpow(2, n - 1);
            long long ans1 = qpow(temp4 + 1, num);
            printf("%lld\n", ans1);
        }

    }
}

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define co 200005
#define int long long int
#define Int int
#define vi vector<int>
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define sz(x) ((int)(x).size())
#define loop(n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
// int pow2[co + 1];
// void pow3()
// {
//     pow2[0] = 1;
//     for (int i = 1; i < co; i++)
//     {
//         pow2[i] = (pow2[i - 1] * 2LL) % mod;
//     }
// }
int pow4(int n, int k)
{
    int res = 1;
    while (k)
    {
        if (k & 1)
        {
            res = (res % mod * n % mod) % mod;
            k--;
        }
        n = (n % mod * n % mod) % mod;
        k >>= 1;
    }
    return res;
}
int ans(int n, int k)
{
    if (k == 0)
    {
        return 1;
    }
    return (pow4(2, n * (k - 1)) * (n % 2 == 0 ? 1 : 0) + (pow4(2, n - 1) + (n % 2 == 0 ? -1 : 1)) * ans(n, k - 1) % mod) % mod;
}
int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // pow3();
    int T = 1;
    cin >> T;
    while (T--)
    {
        int n, k;
        cin >> n >> k;
        cout << ans(n, k) << endl;
    }
    return 0;
}

#include<bits/stdc++.h>

#define ll long long
#define MOD 1000000007

using namespace std;

long long fact[200001];

long long POW(long long a,long long b){
    long long res=1;
    while(b>0){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b/=2;
    }
    return res;
}

void solve(){
    int n,k;
    cin>>n>>k;
    long long ans=0,s=1,S=POW(2,n-1)+(n%2?1:-1);
    for(int i=0;i<k;i++){
        if(n%2==0) ans=(ans+s*POW(2,n*(k-i-1LL))%MOD)%MOD;
        s=s*S%MOD;
    }
    ans=(ans+s)%MOD;
    cout<<ans<<'\n';
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    fact[0]=1;
    for(int i=1;i<=200000;i++) fact[i]=(fact[i-1]*i)%MOD;
    int t;
    cin>>t;
    while(t--) solve();
}

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);cout<<setprecision(25);
#define pb push_back
typedef long long int ll;
ll mod=1000000007;
using namespace std;
long long binpow(long long a, long long b, long long m=mod) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int32_t main()
{
   IOS;
   ll T=1;
   cin>>T;
   while(T--)
   {
	 int n, k;
    cin >> n >> k;
    if (k == 0){
        cout << 1 << "\n";
        continue;
    }
    int ans = 0;
    if (n % 2 == 1){
        int pow2 = binpow(2, n - 1) + 1;
        ans = (binpow(pow2, k)) % mod;
    }
    else{
        int pow2 = binpow(2, n - 1) - 1;
        int pow22 = binpow(2, n);
        for (int i = 0; i <= k; i++) ans = (ans + (binpow(pow2, i) * binpow(pow22, k - i - 1)) % mod) % mod;
    }
    cout << ans << "\n";
   }
}

#include <iostream>
#include <cstdio>
#define ll long long
using namespace std;

const int mod = 1e9 + 7;

ll pow(ll a, ll b){
    int res = 1;
    while(b){
        if(b & 1) res = (ll) res * a % mod;
        b >>= 1;
        a = (ll) a * a % mod;
    }
    return res;
}
int main(){
    int t;
    cin >> t;
    while(t--){
        int n, k;
        ll res = 0;
        scanf("%d%d", &n, &k);
        if(k == 0){
            cout << 1 << endl;
            continue;
        }
        for(int i = 0, j = 1; i < k; i++){
            if(n % 2 == 0){
                res = (res + pow(2ll, (ll)(k - i - 1) * n) * j ) % mod;
                j = (pow(2ll, n-1) - 1) * j % mod;
            }
            else j = (ll)j * ( pow(2, n-1) + 1) % mod;
            if(i == k-1) res = (res + j) % mod;
        }
        cout << (res + mod) % mod << endl;
    }
    return 0;
}

#include <climits>
#include <cstring>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = pow(10,9) + 7;
double eps = 1e-12;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define INF 2e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())

bool isPowerOfTwo(int n)
{
   if(n==0){
   return false;
   }
   return (ceil(log2(n)) == floor(log2(n)));
}

bool isPrime(int n) {

  if (n == 1) {
    return false;
  }

  for (int i = 2; i*i <= n; i++) {
    if (n % i == 0) return false;
  }

  return true;
}

ll lcm(ll a,ll b){
    return (1ll*a*b/__gcd(a,b));
}

#define MAXN 200000
const ll N = 1 << 18;
const ll M = 1e9 + 7;
ll seg[2 * N];
void update(int v, int tl, int tr, ll pos, ll new_val)
{
    if (tl == tr)seg[v] = new_val;
    else
    {
        int tm = (tl + tr) / 2;
        if (pos <= tm)update(v * 2, tl, tm, pos, new_val);
        else update(v * 2 + 1, tm + 1, tr, pos, new_val);
        seg[v] = __gcd(seg[v * 2], seg[v * 2 + 1]);
    }
}

ll sum(int v, int tl, int tr, int l, int r)
{
    if (l > r)return 0;
    if (l == tl && r == tr)return seg[v];
    int tm = (tl + tr) / 2;
    return __gcd(sum(v * 2, tl, tm, l, min(r, tm))
                 , sum(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}

ll abs1(ll x, ll y){
  if(x>y)return x-y;
  else return y-x;
}
ll di[4] = {1,0,-1,0};
ll dj[4] = {0,-1,0,1};

struct cmp{
  bool operator() (const p64 p1,const p64 p2) const {
    ll lena = p1.second - p1.first + 1;
		ll lenb = p2.second - p2.first + 1;
		if (lena == lenb) return p1.first < p2.first;
		return lena > lenb;
  }
};

bool check(string s,ll k,ll m){
  int c[2] = {0,0};
  forn(i,m){
    c[s[i]-'a']++;
  }
  if( k>= min(c[0],c[1])) return 1;
  forn(i,s.size()-m){
    c[s[i]-'a']--;
    c[s[i+m] - 'a']++;
    if(k >= min(c[0],c[1]))return 1;
  }
  return 0;
}

ll power(ll a, ll n)
{
    ll res = 1;

    while(n){

        if(n%2){

            res = (res * a) % MOD;

            n--;
        }
        else{

            a = (a*a) % MOD;

            n/=2;

        }
    }

    return res;
}

void solve(){
  ll n,k;
  cin>>n>>k;
  ll dp[k+1];
  memset(dp,0,sizeof(dp));
  dp[0] = 1;
  forsn(i,1,k+1){
    if(n%2 == 0){
      dp[i] = (power(2,(i-1)*n)%MOD + (((power(2,(n-1))%MOD - 1)%MOD)*(dp[i-1]%MOD))%MOD)%MOD;
      dp[i]%=MOD;
    }else{
      dp[i] = (power(2,(n-1))%MOD + 1)%MOD*dp[i-1]%MOD;
      dp[i]%=MOD;
    }
  }
  cout<<dp[k]<<endl;
  return;
}

int main()
{
  #ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
  #endif
  fast_cin();
  ll t;
  cin >> t;
  for(int it=1;it<=t;it++) {
      //  cout<<"Case #"<<it<<": ";
    solve();
      //  cout<<endl;
  }
  return 0;
}

#include<bits/stdc++.h>

using namespace std;

typedef pair<int, int> PII;
typedef long long LL;

const int N = 2e5 + 50, MOD = 1e9 + 7;

LL fact[N], infact[N], dp[N][2];

int qmi(int a, int k, int p)    // 快速幂模板
{
    int res = 1;
    while (k)
    {
        if (k & 1) res = (LL)res * a % p;
        a = (LL)a * a % p;
        k >>= 1;
    }
    return res;
}

int C(int a, int b) {
  if (a < b) return 0;
  return 1ll * ((1ll * fact[a] * infact[b]) % MOD) * infact[a - b] % MOD;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  fact[0] = infact[0] = 1;
  for (int i = 1; i < N; i ++ )
  {
    fact[i] = (LL)fact[i - 1] * i % MOD;
    infact[i] = (LL)infact[i - 1] * qmi(i, MOD - 2, MOD) % MOD;
  }
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    int cnt = 0;
    for (int i = 0; i < n; i+=2) {
      cnt = (0ll + cnt + C(n, i)) % MOD;
    }
    int tt = 1;
    for (int i = 0; i < n; i++) {
      tt = 1ll * tt * 2 % MOD;
    }
    dp[1][0] = dp[0][1] = 1;
    for (int i = 1; i <= k; i++) {
      if (n & 1) {
        dp[i][1] = 1ll * (cnt + 1) * dp[i - 1][1] % MOD;
      } else {
        dp[i][1] = 1ll * cnt * dp[i - 1][1] % MOD;
        if (i > 1) {
          dp[i][0] = 1ll * dp[i - 1][0] * tt % MOD;
          dp[i][0] = (0ll + dp[i][0] + dp[i - 1][1]) % MOD;
        }
      }
    }
    if (n & 1) {
      cout << dp[k][1] << endl;
    } else {
      cout << (0ll + dp[k][1] + dp[k][0]) % MOD << endl;
    }
  }
  return 0;
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<math.h>
#include<iomanip>
#include<utility>
#include<stack>
#include<list>
#include<fstream>
#define SYNC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define F(i,m,n) for(int i=m;i<=n;i++)
#define f(i,m,n) for(int i=m;i>=n;i--)
#define debug(n) if(deb==1) cout<<#n<<"="<<n<<endl
#define deb(n) if(deb==1) cout<<#n<<"="<<n<<"   "
#define div(ch) if(deb==1) { for(int i=1;i<=40;i++) cout<<#ch; cout<<endl; }
#define mm(A,n) memset(A,n,sizeof(A))
#define lowbit(x) (x&(-x))
#define ch(x) (int(x-'A')+1)
using namespace std;
typedef long long LL;
const int maxn = 2e5 + 10;
const int maxm = 1e6 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-9;
bool deb = 1;

LL qpow(LL x, LL y) {
	if (!y) return 1;
	LL res = 1;
	if (y & 1) res = x;
	return res * qpow(x * x % mod, y >> 1) % mod;
}

void oper() {
	LL n, k;
	cin >> n >> k;
	LL ans;
	if (n % 2 == 1) ans = qpow(qpow(2, n - 1) + 1, k);
	else {
		ans = qpow((qpow(2, n - 1) - 1), k);
		for (LL i = 1; i <= k; i++) {
			ans = (ans + qpow(qpow(2, n - 1) - 1, k - i) * qpow(qpow(2, n), i - 1)) % mod;
		}
	}
	cout << ans << endl;
}

int main() {
	SYNC;
	int t = 1;
	cin >> t;
	while (t--)
		oper();
	return 0;
}
/*Avoid Stereotypes, Think More, and Code Less.*///
/*Instead of focusing on troublesome old ideas, it's
better to learn or think about efficient new methods*/

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
const ll maxn = 4e5+100;
const ll p = 1e9+7;

long long fac[2*maxn+5];
ll ksm(ll x, ll n, ll mod){
    ll res = 1;
    while (n){
        if (n & 1){
            res = res * x % mod;
        }

        x = x * x % mod;
        n >>= 1;
    }

    return res%mod;
}
void pre(ll n){
    fac[0] = 1;
    for (int i = 1; i <= n; i++)
    {
        fac[i] = fac[i - 1] * i % p;
    }
}
ll solve(ll n,ll m){
    return fac[n] * ksm(fac[m], p - 2, p) % p * ksm(fac[n - m], p - 2, p) % p;
}
signed main(){
    int t;
    cin>>t;
    pre(maxn);
    while(t--)
    {
        ll n,k;
        cin>>n>>k;
        if(n%2==1){
            ll sum = 0;
            for(int i=0;i<=n;i+=2){
                sum = (sum+ solve(n,i)%p)%p;
            }
            ll ans = ksm(sum+1,k,p)%p;
            cout<<(ans)%p<<endl;
        }
        else{
            ll sav1 = 0; // & 0 ^ 0
            ll jiechen = 1;
            for(int i=0;i<n;i+=2){
                sav1 += solve(n,i);sav1%=p;
            }
            int ans = 0;
            for(int i=1;i<=k;i++){
                ans += jiechen*ksm(2,(k-i)*n,p);ans %=p;
                jiechen *= sav1;jiechen%=p;

            }
            ans+=jiechen;
            ans%=p;
            cout<<ans<<endl;
        }
    }
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll qp(ll x,ll p)
{
	ll ans=1;
	x%=mod;
	while(p)
	{
		if(p&1)
		{
			ans*=x;
			ans%=mod;
		}
		x*=x;
		x%=mod;
		p>>=1;
	}
	return ans;
}
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		ll n,k;
		scanf("%lld%lld",&n,&k);
		ll ans;
		if(n%2==1)
		{
			ans=qp(qp(2,n-1)+1,k);
		}
		else
		{
			ans=qp(qp(2,n-1)-1,k);
			ans%=mod;
			for(int i=0;i<k;i++)
			{
				ans+=((qp(qp(2,n),i)%mod)*(qp(qp(2,n-1)-1,(k-1-i))%mod))%mod;
				ans%=mod;
			}
		}

		ans%=mod;
		printf("%lld\n",ans);
	}

return 0;
}

#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll T,n,k,ans;
ll quick(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1)res=res*a%mod;
		b>>=1;
		a=a*a%mod;
	}
	return res%mod;
}
void slove(){
	scanf("%lld%lld",&n,&k);
	ll c=quick(2,n-1);
	if(n&1) c=(c+1)%mod;
	else c=(c-1+mod)%mod;
	ans=quick(c,k);
	if(n%2==0){
		for(int i=1;i<=k;i++){
			ll x=quick(c,i-1);
			ll y=quick(2,(k-i)*n);
			ans=(ans+x*y%mod)%mod;
		}
	}
	printf("%lld\n",ans);
}
int main(){
	cin>>T;
	while(T--)slove();
	return 0;
}

%:include<bits/stdc++.h>
using namespace std;
%:define int long long
%:define gc() getchar()
%:define pc(a) putchar(a)
%:define inf (1ll<<60)
inline int read()
{
    int x=0,f=1;
    char c=gc();
    while(c>'9'||c<'0')
    {
        if(c=='-') f=-f;
        c=gc();
    }
    while(c>='0'&&c<='9') x=x*10+c-'0',c=gc();
    return x*f;
}
int nnu[25];
inline void write(int x)
{
    if(!x)
    {
        pc('0');
        return;
    }
    if(x<0) pc('-'),x=-x;
    int tp=0;
    while(x) nnu[++tp]=x%10,x/=10;
    while(tp) pc(nnu[tp--]+'0');
    return;
}
%:define ma 500005
int tim[ma],inv[ma];
const int mod=1e9+7;
inline int ksm(int di,int mi=mod-2)
{
	int ans=1;
	while(mi)
	{
		if(mi&1) ans=ans*di%mod;
		mi>>=1,di=di*di%mod;
	}
	return ans;
}
inline int C(int n,int m){return tim[n]*inv[m]%mod*inv[n-m]%mod;}
inline void work()
{
	int n=read(),k=read();
	int bt1=0,bt2=0;
	for(int i=0;i<n;i+=2) bt1=(bt1+C(n,i))%mod;
	if(n%2==1) bt1=(bt1+1)%mod;
	else bt2++;
	int ans=0;
	int now=1;
	for(int i=0;i<k;i++)
	{
		ans=(ans+now*bt2%mod*ksm(2,(k-i-1)*n)%mod)%mod;
		now=now*bt1%mod;
	}
	ans=(ans+now)%mod;
	write(ans),pc('\n');

}
signed main()
{
	tim[0]=inv[0]=1;
	for(int i=1;i<=2e5;i++)
		tim[i]=tim[i-1]*i%mod,inv[i]=ksm(tim[i]);
	int T=read();
	while(T--) work();
}

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#define ordered_set tree<pii, null_type, less<pii >,rb_tree_tag, tree_order_statistics_node_update>
# define ll long long
#define ld long double
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()

using namespace std;
const int N = 2e5 + 500, mod = 1e9 + 7;

ll fact[1000009], inv[1000009];

ll fp(ll a, ll b) {
    if (b == 0)
        return 1;
    ll ans = fp(a, b / 2);
    ans = (ans * ans) % mod;
    if (b % 2 != 0)
        ans = (ans * (a % mod)) % mod;
    return ans;
}

void FacInv(ll n) {
    fact[0] = inv[0] = 1;
    for (ll i = 1; i <= n; i++) {
        fact[i] = ((i % mod) * fact[i - 1]) % mod;
        inv[i] = fp(fact[i], mod - 2);
    }
}

ll ncr(ll n, ll r) {
    if (r > n)return 0;
    return (((fact[n] * inv[r]) % mod) * inv[n - r]) % mod;
}

ll odd[N], even[N];

ll add(ll a, ll b) {
    a %= mod;
    b %= mod;
    return (a + b) % mod;
}

ll mul(ll a, ll b) {
    a %= mod;
    b %= mod;
    return (a * b) % mod;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    FacInv(N);
    int t;
    cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        for(int i=0;i<=n;i++)even[i]=odd[i]=0;
        even[0]=1;
        for (int i = 1; i <= n; ++i) {
            if (i & 1)odd[i] = ncr(n, i);
            else even[i] = ncr(n, i);
            even[i]=add(even[i-1],even[i]);
            odd[i]=add(odd[i-1],odd[i]);
        }
        ll ans = 0, eq = 1;
        //cerr << odd << " " << even << "\n";
        for (int i = 0; i < k; ++i) {
            ans = add(ans, mul(eq, mul(((n&1)?0:1), (fp(fp(2, n), k - i-1) + mod) % mod)));
            eq = mul(eq, add(((n&1)?even[n]:even[n-1]), n&1));
        }
        //cerr << eq << "\n";
        cout << add(ans, eq) << "\n";
    }
    return 0;
}

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

#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mod 1000000007
#define MOD1 998244353
#define inf 1e9
#define nl "\n"
#define ll long long
#define int ll
#define pi pair<int,int>
#define pb push_back
#define ppb pop_back
#define len(s) s.length()
#define mp make_pair
#define ff first
#define ss second
#define PI 3.141592653589793238462
#define set_bits __builtin_popcountll
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define Sort(x) sort(all(x))
#define vi vector<ll>
#define Vvi vector<vi>
#define For(i,start,end) for( int i=(start);i<(end);i++)
#define debug(x) cerr << #x<<" "; _print(x); cerr << endl;

typedef unsigned long long ull;
typedef long double lld;

//....................................................................................................................................
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
//template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
//template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
//template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
//template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
// void _print(pbds v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
//....................................................................................................................................

int gcdExtended(int a, int b, int *x, int *y)
{
    // Base Case
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }

    int x1, y1; // To store results of recursive call
    int gcd = gcdExtended(b%a, a, &x1, &y1);

    // Update x and y using results of recursive
    // call
    *x = y1 - (b/a) * x1;
    *y = x1;

    return gcd;
}

int modInverse(int b, int m)
{
    int x, y; // used in extended GCD algorithm
    int g = gcdExtended(b, m, &x, &y);

    // Return -1 if b and m are not co-prime
    if (g != 1)
        return -1;

    // m is added to handle negative x
    return (x%m + m) % m;
}

// Function to compute a/b under modulo m
int modDivide(int a, int b, int m)
{
    a = a % m;
    int inv = modInverse(b, m);
       return (inv*a)%m;
}

int bipower(int n){
	int ans=1,x=2;
	while(n>0){
		if(n%2){
			ans=(ans*x)%mod;
		}
		x=(x*x)%mod;
		n/=2;
	}
	return ans;
}

int power(int n,int k){
	if(n==0){
		return 0;
	}
	int ans=1,x=n;
	while(k>0){
		if(k%2){
			ans=(ans*x)%mod;
		}
		x=(x*x)%mod;
		k/=2;
	}
	return ans;
}
void solve(){
	int n,k;
	cin>>n>>k;
	int x=1;
	int factor=n%2;
	vi fact(n+10,1);
	For(i,2,n+1){
		fact[i]=fact[i-1]*i;
		fact[i]%=mod;
	}
	for(int i=2;i<n;i+=2){
		int div=fact[i]*fact[n-i];
		div%=mod;
		factor+=modDivide(fact[n],div,mod);
		factor%=mod;
	}
//	cout<<factor<<" ";
	for(int i=0;i<k;i++){
		x=((factor+1)*x)%mod;
		x%=mod;
		if(n%2==0){
			x+=power(power(2,i),n)%mod;
			x%=mod;
		}
	}
	int pw2=2,store=1;
	For(i,0,n){
//		store*=2;
//		store%=mod;
	}
//	pw2=store;
//	if((n%2)==0){
//		for(int i=1;i<=k;i++){
//			x+=power(power(2,i)-1,n);
//			x%=mod;
//			store*=pw2;
//			store%=mod;
//		}
//	}
	cout<<x<<nl;
	return;
}

signed main(){
    FAST();
    int tt=1;
	cin>>tt;
	while(tt--){
		solve();
	}
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int k, n, t;
long long fac[200020], fac1[200020], dp[200020];
const long long N=1e9+7;
long long powz(long long a, long long b){
    if (b==0) return 1;
    if (b==1) return a;
    long long c=powz(a, b/2);
    if (b%2==0) return (c*c)%N;
    return (((c*c)%N)*a)%N;
}
int main(){
    cin>>t;
    fac[1]=1;
    for (int i=2; i<=2e5+1; i++) {
        fac[i]=(fac[i-1]*1LL*i)%N;
    }
    for (int i=1; i<=2e5+1; i++) fac[i]=powz(fac[i], N-2);
    for (int i=1; i<=t; i++){
        cin>>n>>k;
        //if (n==k and n==2e5) cout<<226490044<<endl;
        fac1[1]=n;
        for (int j=n-1; j>=1; j--) fac1[n-j+1]=(fac1[n-j]*1LL*j)%N;
        long long res=1;
        for (int j=1; j<=n; j++){
            if ((j%2==0 and j<n) or (j==n and n%2==1)){
                res=(res+(fac1[j]*fac[j])%N)%N;
            }
        }
        dp[0]=1;
        for (int j=1; j<=k; j++){
            dp[j]=(res*dp[j-1])%N;
            if (n%2==0) dp[j]=(dp[j]+powz(powz(2, n), j-1))%N;
        }
        cout<<dp[k]<<endl;
    }
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const ll MOD = 1e9+7, mxN = 2e5+100;
ll fact[mxN], inv[mxN], invfact[mxN];

ll N, K;

ll FP(ll x, ll y) {
	if (y == 0)
		return 1;
	ll tmp = FP(x, y>>1);
	return (((tmp*tmp)%MOD)*(y&1 ? x%MOD : 1))%MOD;
}

ll nCr(ll n, ll r) {
	return (fact[n] * ((invfact[r] * invfact[n-r])%MOD))%MOD;
}

void solve() {
	cin >> N >> K;

	ll f = 0;
	for (int i = 0; i <= N/2; ++i)
		f += nCr(N, 2*i);
	f += (N&1 ? 1 : -1);

	if (N&1) {
		cout << FP(f, K);
	}
	else {
		ll _2pw = FP(2, N);
		ll ans = FP(f, K);
		for (int i = 0; i < K; i++) {
			(ans += FP(_2pw, i) * FP(f, K - i - 1)) %= MOD;
		}
		cout << ans;
	}
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(0);

	fact[0] = inv[1] = fact[1] = invfact[0] = invfact[1] = 1;
	for (int i = 2; i < mxN; i++) {
		fact[i] = (fact[i - 1] * i) % MOD;
		inv[i] = MOD - (inv[MOD % i] * (MOD / i) % MOD);
		invfact[i] = (inv[i] * invfact[i - 1]) % MOD;
	}

	ll t;
	cin >> t;
	while(t--) {
		solve();
		cout << '\n';
	}
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pii pair <int,int>
#define vi vector <int>
#define vvi vector <vector <int>>
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ff first
#define ss second
#define setbits(x) __builtin_popcountll(x)    //count number of setbits in a number
#define ctz(x) __builtin_ctzll(x)             //count the trailing zeros
#define clz(x) __builtin_clzll(x)             //count the leading zeros
#define all(x) (x).begin(), (x).end()
const ld eps= 1e-9;
#define inf 1000000000000000001
#define mod 1000000007
//#define mod 998244353
//think of precomputation to reduce time complexity
//--------------------------------- code begins here ------------------------------//
int n, k;
int dp[200001];
int binaryexp(int a,int b,int p)
{
    if(b==0)
        return 1;
    if(b&1)
        return ((a%p)*(binaryexp(((a%p)*(a%p))%p, (b-1)/2, p)))%p;
    else
        return binaryexp(((a%p)*(a%p))%p, b/2, p);
}
int inverse_mod(int n, int p)
{
    return binaryexp(n,p-2,p);
}
int solve(int i)
{
    if(i==k)
        return 1;
    if(dp[i]!=-1)
        return dp[i];
    if(n&1)
    {
        dp[i]= ((binaryexp(2, n-1, mod)+1)*solve(i+1))%mod;
    }
    else
    {
        dp[i]= (binaryexp(binaryexp(2, n, mod), k-i-1, mod)+((binaryexp(2, n-1, mod)-1)*solve(i+1))%mod)%mod;
    }
    return dp[i];
}
int32_t main()
{
    fast
    int t=1;
    cin>>t;
    for(int tt=1; tt<=t; tt++)
    {
        cin>>n>>k;
        memset(dp, -1, sizeof(dp));
        cout<<solve(0)<<'\n';
    }
    return 0;
}

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;
const ll inv = 500000004;

ll fpow(ll a, ll b, ll p)
{
    ll ans = 1;
    for (; b; b >>= 1, a = (a * a) % p)
    {
        if (b & 1)
            ans = (ans * a) % p;
    }
    return ans;
}

long long dp[300005][2];

int t;
int main() {
    cin >> t;
    for(int i = 1; i<= t; i++) {
        long long n, k;
        cin >> n >> k;
        if(k == 0) {
            printf("1\n");
            continue;
        }
        long long p = fpow(2, n, mod);
        memset(dp, 0, sizeof(dp));
        dp[k + 1][0] = 1;dp[k + 1][1] = 0;
        for(int j = k; j >= 1; j--) {
            dp[j][1] = (((dp[j + 1][1] * p) % mod) + ((n & 1) ? 0 : dp[j + 1][0])) % mod;
            ll q = (p * inv) % mod;
            if (n & 1) {
                q = (q + 1) % mod;
            }
            else {
                q = (((q - 1) % mod) + mod) % mod;
            }
            dp[j][0] = (dp[j + 1][0] * q) % mod;
        }
        printf("%lld\n", (dp[1][1] + dp[1][0]) % mod);
    }
    // system("pause");
    return 0;
}

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

const int M = 1e9+7;
const int N = 2e5+7;
long long w[3][3];
long long dp[N];
long long all[N];
long long al;

long long power(long long x, long long y)
{
    if(y == 0) return 1;
    if(y % 2) return ( x * power(x, y-1) ) % M;
    long long k = power(x, y/2);
    return (k * k) % M;
}

int tc()
{
    int n, k;
    cin >> n >> k;
    memset(dp, 0, sizeof dp);
    w[0][0] = power(2, n) - 1;
    w[0][1] = 1;
    w[1][0] = power(2, n-1);
    w[1][1] = w[1][0];
    all[0] = 1;
    dp[0] = 1;
    int even = (n+1) % 2;
    int odd = n % 2;
    al = ( w[1][0] - even + M ) % M;
    al %= M;
    al += odd ;
    al %= M;
    al += even;
    al %= M;
    al += ( w[1][1] - odd + M) % M;
    al %= M;
    for(int i=1; i<=k; i++){
        dp[i] += (((w[1][0] - even + M) % M) * dp[i-1] ) % M; // 0 0
        dp[i] %= M;
        dp[i] += ((odd % M) * dp[i-1] ) % M; // 1 1
        dp[i] %= M;
        dp[i] += ((even % M) * all[i-1] ) % M; // 1 0
        dp[i] %= M;
        all[i] = (all[i-1] * al) % M;
    }
    cout << dp[k] << endl;
    return 0;
}

int main()
{
    long long t;
    cin >>t;
    while(t--){
        tc();
    }
    return 0;
}

#include <bits/stdc++.h>
#define m 1000000007LL
#define ll long long
using namespace std;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t, p[200005], a[200005];
	//vector<ll> a(200005);
	p[0]=1;
	for (ll i=1; i<200005; i++){
		p[i]=p[i-1]<<1;
		p[i]%=m;
	}
	cin >> t;
	while (t--){
		ll n, k, ans=1LL;
		cin >> n >> k;
		if (!k){
			cout << 1 << '\n';
			continue;
		}
		ll same = p[n-1];
		if (n%2)
			same++;
		else
			same--;
		same%=m;
		for (int i=0; i<k; i++){
			ans*=same;
			ans%=m;
		}
		if (n%2==0){
			ll s = 1LL;
			a[k-1]=1;
			for(int i=1; i<k; i++){
				a[k-1-i]=a[k-i]*p[n];
				a[k-1-i]%=m;
			}
			for (ll i=0; i<k; i++){
				ll tmp = s;
				tmp*=a[i];
				ans+=tmp%m;
				ans%=m;
				s*=same;
				s%=m;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = 1e9+7;
int N = 200005;
int power(int x, int y, int p = mod){
    int res = 1;
    x = x % p;
    if (x == 0) return 0;
    while (y > 0){
        if (y & 1)res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
void solve(){
    int n,k;cin>>n>>k;vector<int> a(k+1), total(k+1);
	total[0]=1;
	a[0]=1;
	for(int i=1;i<=k;i++) {
	a[i]= (a[i-1]*power(2,n-1))%mod;
	if(n%2==0)a[i] = (a[i] + (total[i-1]-a[i-1]+mod)%mod)%mod;
	if(n%2==1)a[i] = (a[i] + a[i-1])%mod;
	total[i]=(total[i-1]*power(2,n))%mod;
	}
	cout<<a[k]<<endl;
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    cin >> t;
    while(t--) {
    solve();
    }
return 0;
}

#include <bits/stdc++.h>
#define m 1000000007LL
#define ll long long
using namespace std;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t, p[200005];
	vector<ll> a(200005);
	p[0]=1;
	for (ll i=1; i<200005; i++){
		p[i]=p[i-1]<<1;
		p[i]%=m;
	}
	cin >> t;
	while (t--){
		ll n, k, ans=1LL;
		cin >> n >> k;
		if (!k){
			cout << 1 << '\n';
			continue;
		}
		if (n==1){
			cout << p[k] << '\n';
			continue;
		}
		ll same = p[n-1];
		if (n%2)
			same++;
		else
			same--;
		same%=m;
		for (int i=0; i<k; i++){
			ans*=same;
			ans%=m;
		}
		if (n%2==0){
			ll s = 1LL;
			a[k-1]=1;
			for(int i=1; i<k; i++){
				a[k-1-i]=a[k-i]*p[n];
				a[k-1-i]%=m;
			}
			for (ll i=0; i<k; i++){
				ll tmp = s;
				tmp*=a[i];
				ans+=tmp%m;
				ans%=m;
				s*=same;
				s%=m;
			}
		}
		cout << ans << '\n';
	}
	return 0;
}

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ff first
#define ss second
#define endl "\n"
const ll mod=1000000007;
const ll N=2e5;
const ll INF=1e18;
const double pi=3.14159265358979323846;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_os;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update > new_oms;

void google(int t){
    cout<<"Case #"<<t<<": ";
}
ll value;
ll fact[N+1],invFact[N+1];
ll dp[N+1];
ll ans[2][N+1];
ll fast_pow(ll a, ll p) {
  ll res = 1;
  while (p) {
    if (p % 2 == 0) {
      a = a * 1ll * a % mod;
      p /= 2;
    } else {
      res = res * 1ll * a % mod;
      p--;
    }
  }
  return res;
}

void calc(int n){    //calculation of factorial and inverse-factorial
   fact[0] = invFact[0] = 1;
    for (int i = 1; i<=n; i++) {
        fact[i] = (fact[i - 1] * i) % mod;
        invFact[i] = fast_pow(fact[i], mod - 2);
    }
}

ll nCr(ll n, ll k) {
  if (k > n) {
        return 0;
    }
    return fact[n] * invFact[k] % mod * invFact[n - k] % mod;
}
ll fun(ll k,ll n,ll flag){

    if(k<=0)
        return 1;

    if(ans[flag][k]!=-1)
         return ans[flag][k];
    if(flag==0){
        ll v1=dp[n-1]%mod*fun(k-1,n,0)%mod%mod;
        ll v2=0;
        if(n%2==0)
             v2=fun(k-1,n,1);
        else
            v2=fun(k-1,n,0);
        return ans[flag][k]=(v1+v2)%mod;
    }
    else
       return ans[flag][k]=value*fun(k-1,n,1)%mod;
}

int main(){
FAST;

   calc(N);

    ll T,n;
    T=1;
    cin>>T;
    while(T--){

                ll k;
                cin>>n>>k;
                value=fast_pow(2,n);
                memset(ans,-1,sizeof(ans));
                for(ll i=0;i<=n;i++){
                    dp[i]=0;
                    if(i%2==0){
                      ll value=nCr(n,i);
                      dp[i]=value;
                    }
                    if(i-1>=0)
                         dp[i]+=dp[i-1];
                     dp[i]%=mod;
                }
                // for(ll i=0;i<=n;i++)
                //    cout<<dp[i]<<" ";

                // cout<<endl;
                cout<<fun(k,n,0)<<endl;

          }

       return 0;
}

#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdio>
#include <map>
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 100;
const int INF = 0x3f3f3f3f;
int Data[MAXN];
const int MOD = 1e9 + 7;
ll fastpow(ll base, ll power){
    ll ans = 1;
    while(power){
        if(power & 1) ans = ans * base % MOD;
        base = base * base % MOD;
        power >>= 1;
    }
    return ans;
}
int main(){
    ios::sync_with_stdio(false);
    ll n, k;
    int t;
    cin >> t;
    while(t--){
        cin >> n >> k;
        ll ans;
        ll a = fastpow(2, n - 1);
        if(n & 1){
            ans = fastpow(a + 1, k);
        }else{
            ans = fastpow(a - 1, k);
            for(int i=1;i<=k;i++){
                ans += fastpow(a - 1, i - 1) * fastpow(a * 2, k - i) % MOD;
                ans %= MOD;
            }
        }
        cout << ans << '\n';
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;

ll power(int base, int exp) {
    if (base == 0) return 0;
    if (exp == 0) return 1ll;
    ll ans = power(base, exp >> 1);
    ans = (ll)(ans * ans) % MOD;
    if (exp % 2) return (ans * (ll)base) % MOD;
    return ans;
}

int main() {
	int t; cin >> t;
	cout << fixed << setprecision(10);

	vector<int> pow2(N, 1);
	for (int i = 1; i < N; i++) pow2[i] = (pow2[i-1] << 1)%MOD;

	while (t--) {
	    int n, k; cin >> n >> k;
	    if (n%2) {
	       // cout << "ODD\n";
	        cout << power((pow2[n-1] + 1ll)%MOD, k) % MOD << "\n";
	    }
	    else {
	       // cout << "EVEN\n";
	        ll a = (pow2[n-1] - 1) % MOD;
	        ll ans = power(a, k) % MOD;
	        for (int i = 0, p = 1ll; i < k; i++, p = (p*1ll*pow2[n])%MOD) {
	            ll prod = (p * power(a, k-i-1)) % MOD;
	            ans = (ans + prod) % MOD;
	        }
	        cout << ans << "\n";
	    }
	}
}

#include<bits/stdc++.h>
//#pragma GCC optimize(2)
using namespace std;
#define int long long
const int N=1e6+5,mod=1e9+7;
int k,T,t,n,m,ans,cnt;
int ksm(int a,int b)
{
        int res=1;
        while(b)
        {
                if(b&1) res=res*a%mod;
                b>>=1;
                a=a*a%mod;
        }
        return res%mod;
}
signed main()
{
        cin>>T;
        while(T--)
        {
                cin>>n>>k;
                int c=ksm(2,n-1);
                if(n&1) c=(c+1)%mod;
                else c=(c-1+mod)%mod;
                ans=ksm(c,k);
                if(n%2==0)
                {
                        for(int i=1;i<=k;i++)
                        {
                                int x=ksm(c,i-1);
                                int y=ksm(2,(k-i)*n);
                                ans=(ans+x*y%mod)%mod;
                        }
                }
                cout<<ans<<endl;
        }

        return 0;
}

#include <bits/stdc++.h>
using namespace std;
int n, k;
long long  MOD = (1000*1000*1000)+7;
long long  fact[200042] ;
long long  powMod(long long i, long long power) {
    long long ans = 1;
    while(power != 0) {
        if(power % 2 == 1)
            ans = (ans * i) % MOD;
        i = (i * i) % MOD;
        power /= 2;
    }
    return ans;
}
long long  invMod(long long x) {
  return powMod(x, MOD-2);
}
long long choose (int a, int b)
{
	long long  res = fact[a];
	res = (res * invMod (fact[a - b])) % MOD;
	res = (res * invMod (fact[b])) % MOD;
	return res;
}
 long long nbCombis1(long long i) {
   long long res = 1;
   res = (res*(powMod(2, (i-1)*n)))  % MOD;
   return res;
 }
int main() {
  int t;
  cin >> t;
  fact[0] = 1;
  for (int i=1;i<=200000;i++) {
    fact[i] = (fact[i-1]*i)%MOD;
  }
  long long  dp[200042] ;

  while (t--) {
     cin >> n>>k;
    long long  nbCombis = 0;
    for (int i=0; i<= n; i+= 2) {
     nbCombis = (nbCombis + choose(n, i))%MOD;

    }
    long long nbCombis2 = 0;
    for (int i=1; i<= n; i+= 2) {
     nbCombis2 = (nbCombis2 + choose(n, i))%MOD;

    }

    dp[0] = 1;
    for (int i=1;i<=k;i++) {

      if ((n%2) == 0) {
        dp[i] = (dp[i-1]*(nbCombis-1) + nbCombis1(i))%MOD;

      }
      else {
        dp[i] = ((dp[i-1]) * (nbCombis+1))%MOD;
      }
     // cout << dp[i] << endl;
    }
   cout << dp[k] << endl;
  }
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll t = 1,n,m,k,q,l,r,a[10009],aa,b,c,u,v,x,y,z,f[200009],g[200009],wtf[200009],mod = 1e9 + 7;
string s;
struct st{ll x,y; /*bool operator < (const st &a) const{return x < a.x;};*/};
bool cmp(const st &a,const st &b){return a.x < b.x;}
inline ll read(){
	ll s = 0,w = 1;
	char ch = getchar();
	while (ch > '9' || ch < '0'){ if (ch == '-') w = -1; ch = getchar();}
	while (ch <= '9' && ch >= '0') s = (s << 1) + (s << 3) + (ch ^ 48),ch = getchar();
	return s * w;
}
ll qp(ll x,ll y){
	ll a = 1,b = x;
	while (y){
		if (y & 1) a = a * b % mod;
		b = b * b % mod,y >>= 1;
	}
	return a;
}
void init(){
	f[0] = g[0] = 1;
	for (ll i = 1;i <= 200000;i += 1) f[i] = f[i - 1] * i % mod;
	g[200000] = qp(f[200000],mod - 2);
	for (ll i = 199999;i > 0;i -= 1) g[i] = g[i + 1] * (i + 1) % mod;
}
ll C(ll x,ll y){return x < y ? 0 : f[x] * g[y] % mod * g[x - y] % mod;}
int main(){t = read(),init();
while (t --){
	n = read(),k = read(); ll ans = 0,pn = qp(2,n);
	wtf[0] = 1;
	for (ll i = 1;i <= k;i += 1) wtf[i] = wtf[i - 1] * pn % mod;
	if (n & 1){
		ll a1 = 0,a2 = 0; ans = wtf[k];
		for (ll i = 1;i < n;i += 2) a1 = (a1 + C(n,i)) % mod;
		a2 = (pn - a1 + mod) % mod;
		for (ll i = 1;i <= k;i += 1){
			ans = (ans - qp(a2,i - 1) * a1 % mod * (k - i >= 0 ? wtf[k - i] : 1) % mod + mod) % mod;
		}
	}
	else{
		ll a1 = 0,a2 = 0; ans = wtf[k];
		for (ll i = 1;i < n;i += 2) a1 = (a1 + C(n,i)) % mod;
		a2 = (pn - a1 + mod - 1 + mod) % mod;
		for (ll i = 1;i <= k;i += 1){
			ans = (ans - qp(a2,i - 1) * a1 % mod * (k - i >= 0 ? wtf[k - i] : 1) % mod + mod) % mod;
		}
	}
	printf("%lld\n",ans);
}
	return 0;
}

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

#define MOD 1000000007
#define ll long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);}
ll combination(ll n, ll r, ll m, ll *fact, ll *ifact) {ll val1 = fact[n]; ll val2 = ifact[n - r]; ll val3 = ifact[r]; return (((val1 * val2) % m) * val3) % m;}
ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}

void solve1(int n,int k){//for even

	ll *fact = new ll[n + 1];
	ll *ifact = new ll[n + 1];
	fact[0] = 1, ifact[0] = 1;
	for (ll i = 1; i <= n; i++) {
		fact[i] = (fact[i - 1] * i) % MOD;
		ifact[i] = mminvprime(fact[i], MOD);
	}
	ll y = 0;
	for (ll i = 0; i <= n - 2; i += 2) {
		ll x = combination(n, i, MOD, fact, ifact);
		y = mod_add(x, y, MOD);
	}

	ll dp[k+1];
	dp[0]=1;
	for(ll i = 1;i<=k;i++){
		ll opt1 =  expo(expo(2,i-1,MOD),n,MOD);
		ll opt2 =  mod_mul(y,dp[i-1],MOD);
		dp[i] = mod_add(opt1,opt2,MOD);
		//dp[i] = (opt1+opt2)%MOD;
	}

	cout << dp[k] << endl;
}

void solve2(int n,int k){//for odd

	ll *fact = new ll[n + 1];
	ll *ifact = new ll[n + 1];
	fact[0] = 1, ifact[0] = 1;
	for (ll i = 1; i <= n; i++) {
		fact[i] = (fact[i - 1] * i) % MOD;
		ifact[i] = mminvprime(fact[i], MOD);
	}
	ll y = 0;
	for (ll i = 0; i <= n - 1; i += 2) {
		ll x = combination(n, i, MOD, fact, ifact);
		y = mod_add(x, y, MOD);
	}

	ll dp[k+1];
	dp[0]=1;
	for(ll i = 1;i<=k;i++){
		ll opt1 =  dp[i-1];
		ll opt2 =  mod_mul(y,dp[i-1],MOD);
		dp[i] = mod_add(opt1,opt2,MOD);
	}

	cout << dp[k] << endl;
}

int32_t main(){
	fastio;
    int tc;
    cin>>tc;

    while (tc--) {
		int n, k;
		cin >> n >> k;
		if (k == 0) {
			cout << 1 << "\n";
			continue;
		}
		if (n % 2 == 0) {
			solve1(n, k);
		} else {
			solve2(n, k);
		}
	}

	return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <string>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
using namespace std;

typedef unsigned int uint;
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> ii;
typedef pair<int64, int64> ii64;
typedef vector<int> vint;
typedef vector<int64> vint64;
typedef vector<uint64> vuint64;
typedef vector<vint> vvint;
typedef vector<vint64> vvint64;
typedef vector<vuint64> vvuint64;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;

#define mp make_pair
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define fori(n) for(int i = 0; i < n; ++i)
#define forj(n) for(int j = 0; j < n; ++j)
#define fork(n) for(int k = 0; k < n; ++k)
#define INF9 (int64)(1e9)
#define INF18 (int64)(1e18)

template<typename T>
struct compF{
	bool operator()(const pair<T, T> &a, const pair<T, T> &b){
		return a.first < b.first;
	}
};

template<typename T>
struct compS{
	bool operator()(const pair<T, T> &a, const pair<T, T> &b){
		return a.second < b.second;
	}
};

template<typename T>
void printMatrix(const string &txt, vector<vector<T>> &a){
	cout << txt;
	fori(a.size()){
		forj(a[i].size())
			cout << a[i][j] << ' ';

		cout << endl;
	}
}

template<typename T>
void printVector(const string &txt, vector<T> &a){
	cout << txt;
	for (int i = 0; i < a.size(); ++i)
		cout << a[i] << ' ';
	cout << endl;
}

template<typename T>
void readVector(int n, vector<T> &a){
	if (a.size() < n)
		a.resize(n);

	fori(n) cin >> a[i];
}

template<typename T>
T lb(const set<T> &a, T x){
	auto it = a.lower_bound(x);
	if (it == a.end())
		return -1;
	return *it;
}

template<typename T>
T ub(const set<T> &a, T x){
	auto it = a.upper_bound(x);
	if (it == a.end())
		return -1;
	return *it;
}

template<typename T>
T rlb(const set<T> &a, T x){
	auto it = a.lower_bound(x);

	if (it == a.begin()){
		if (*it > x)
			return -1;
		return *it;
	}

	it = prev(it);
	return *it;
}

template<typename T>
T rub(const set<T> &a, T x){
	auto it = a.lower_bound(x);

	if (it == a.begin()){
		return -1;
	}

	it = prev(it);
	return *it;
}

template<typename T1, typename T2>
bool exist(map<T1, T2> &m, T1 x){
	if (m.find(x) == m.end())
		return false;

	return true;
}

int64 gcd(int64 a, int64 b){
	while (a != 0 && b != 0){
		if (b > a)
			b %= a;
		else
			a %= b;
	}

	return a + b;
}

int64 minFactor(int64 x){
	for (int64 i = 2; i * i <= x; ++i)
		if (x % i == 0)
			return i;

	return x;
}

int64 allFactors(int64 x, vint64 &prms, vint64 &prm_cnt){
	prms.clear();
	prm_cnt.clear();
	while (x > 1){
		int64 t = minFactor(x);
		prms.push_back(t);
		int s = prms.size() - 1;
		prm_cnt.push_back(0);
		while (x % t == 0){
			x /= t;
			++prm_cnt[s];
		}
	}

	return 0;
}

#define MOD 1000000007

int64 add(int64 a, int64 b){
	if (a > MOD) a %= MOD;
	if (b > MOD) b %= MOD;

	return (a + b) % MOD;
}

int64 sub(int64 a, int64 b){
	if (a > MOD) a %= MOD;
	if (b > MOD) b %= MOD;

	int64 x = a - b;
	while (x < 0)
		x += MOD;

	return x;
}

int64 mul(int64 a, int64 b){
	if (a > MOD) a %= MOD;
	if (b > MOD) b %= MOD;

	return (a * b) % MOD;
}

int64 pow_(int64 a, int64 b){
	if (b == 0)
		return 1ll;
	if (b % 2 == 0){
		int64 k = pow_(a, b / 2);
		return mul(k, k);
	}
	else{
		int64 k = pow_(a, b - 1);
		return mul(a, k);
	}
}

#define N 2*(int)(1e5)
int64 fact[N + 1], rfact[N + 1];

int64 comb(int n, int k){
	int64 denum = mul(rfact[k], rfact[n - k]);
	return mul(fact[n], denum);
}

int64 dp[N + 1];
int64 sums[N + 1];
int64 psums[N + 1];

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie();

	int t;
	cin >> t;

	fact[0] = fact[1] = rfact[0] = rfact[1] = 1;
	for (int i = 2; i <= N; ++i){
		fact[i] = mul(i, fact[i - 1]);
		rfact[i] = pow_(fact[i], MOD - 2);
	}

	while (t--){
		int n, k;
		cin >> n >> k;

		dp[0] = 1;

		for (int j = 0; j <= n; j += 2)
			sums[j] = comb(n, j);
		psums[0] = sums[0];

		for (int j = 2; j <= n; j += 2)
			psums[j] = add(psums[j - 2], sums[j]);

		for (int i = 1; i <= k; ++i){
			dp[i] = 0;

			int64 sum = 0;
			int lim = 2 * ((n + 1) / 2) - 2;
			/*
			for (int j = 0; j <= lim; j += 2){
				sum = add(sum, sums[j]);
			}*/
			sum = mul(psums[lim], dp[i - 1]);

			dp[i] = sum;

			if (n % 2 == 0){
				// 1/0
				dp[i] = add(dp[i], pow_(pow_(2, n), i - 1));
			}
			else{
				// 1/1
				dp[i] = add(dp[i], dp[i - 1]);
			}
		}

		//cout << ">>";
		cout << dp[k] << endl;
	}

	return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define fastio cin.tie(0); ios_base::sync_with_stdio(false); cout.tie(0)
#define endl "\n"
#define int long long
#define all(x) x.begin(), x.end()
using namespace std;

const int inf = 1e18 + 5, mod = 1e9 + 7;

int fpow(int a, int b){
 if(b == 0) return 1;
 if(b == 1) return a;
 int x = fpow(a, b/2);

 if(b&1) return ((x*x%mod)*a)%mod;
 else return (x*x)%mod;
}

vector<int> fac(200005);

int comb(int n, int r){
 return((fac[n] * fpow(fac[r], mod - 2)%mod) * fpow(fac[n-r], mod - 2))%mod;
}

int32_t main(){
  fastio;
  fac[0] = 1, fac[1] = 1;
  for(int i = 2; i < 200005; i++){
    fac[i] = (fac[i-1] * i) % mod;
  }

  int t;
  cin>>t;
  while(t--){
    int n, k;
    cin>>n>>k;

    int cnt = 0, curcnt = 1, ans = 0;

    for(int i = 0; i < n; i += 2){
        cnt = (cnt + comb(n, i))%mod;
    }
    if(n&1) cnt++;

    if(n%2 == 0){
        for(int i = 1; i <= k; i++){
            ans = (ans + (curcnt * fpow(2, n * (k - i))%mod))%mod;
            curcnt = (curcnt * cnt)%mod;
        }

        ans = (ans + curcnt)%mod;
    }
    else{
        for(int i = 1; i <= k; i++){
            curcnt = (curcnt * cnt)%mod;
        }

        ans = curcnt;
    }

    cout<<ans<<endl;
  }
  return 0;
}

/*
========= Plozia =========
	Author:Plozia
	Problem:
	Date:
========= Plozia =========
*/

#include <bits/stdc++.h>
#define int LL
typedef long long LL;

const int MAXN = 2e5 + 5;
const LL P = 1e9 + 7;
int t;
LL n, k, fact[MAXN], inv[MAXN], f[MAXN];

int Read()
{
	int sum = 0, fh = 1; char ch = getchar();
	for (; ch < '0' || ch > '9'; ch = getchar()) fh -= (ch == '-') << 1;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) sum = (sum << 3) + (sum << 1) + (ch ^ 48);
	return sum * fh;
}

LL ksm(LL a, LL b = P - 2, LL p = P)
{
	LL s = 1 % p;
	for (; b; b >>= 1, a = a * a % p)
		if (b & 1) s = s * a % p;
	return s;
}

LL C(LL n, LL m)
{
	return fact[n] * inv[m] % P * inv[n - m] % P;
}

void Solve()
{
	n = Read(), k = Read(); LL ans = 0;
	for (int i = 0; i <= k; ++i) f[i] = 0; f[0] = 1;
	for (int i = 0; i < n; i += 2) ans = (ans + C(n, i)) % P;
	if (n % 2 == 0)
	{
		f[1] = (ans + 1) % P;
		for (int i = 2; i <= k; ++i)
		{
			f[i] = (f[i - 1] * ans % P + ksm(2, (i - 1) * 1ll * n)) % P;
		}
		printf("%lld\n", f[k]);
	}
	else printf("%lld\n", ksm((ans + 1) % P, k));
}

signed main()
{
	fact[0] = inv[0] = inv[1] = 1;
	for (int i = 1; i <= 200000; ++i) fact[i] = fact[i - 1] * i % P;
	for (int i = 2; i <= 200000; ++i) inv[i] = ksm(fact[i]);
	t = Read(); while (t--) Solve(); return 0;
}

#include <cmath>
#include <cstdio>
#include <string>
#include <vector>
#include <iostream>
#include <stack>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <limits>
#include <iterator>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define ll long long
const ll mod = 1e9 + 7;

/*
Important STL Functions:

For sorted array:
1. lower_bound(arr.begin(),arr.end(),ele) : return iterator to first occurence of ele if it exists, else just greater element
2. upper_bound()
3. binary_search(arr.begin(),arr.start(),ele_to_be_searched) : return true if ele present else false

*/

// bool checkprime(long long n)
// {
//     if(n==1)
//         return false;
//     if(n==2 || n==3 || n==5 || n==7)
//         return true;
//     for(long long i=2; i*i<=n; i++)
//     {
//         if(n%i==0)
//             return false;
//     }
//     return true;
// }

ll binPow(ll a, ll b)
{
    if(b==0)
        return 1;
    if(b==1)
        return a;
    ll res=binPow(a,b/2);
    if(b%2==0)
    {
        return (res*res)%mod;
    }
    else
    {
        return (((res*res)%mod)*a)%mod;
    }
}

ll inv(ll a)
{
    return (binPow(a,mod-2))%mod;
}

ll binCoeff(ll a, ll b, vector<ll> &fact)
{
    return (((fact[a] * inv(fact[b]))%mod)*inv(fact[a-b]))%mod;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin>>t;

    vector<ll> fact(2e5 + 5,1);
    for(int i=2; i<=2e5; i++)
    {
        fact[i]=fact[i-1]*(ll)i;
        fact[i]=fact[i]%mod;
    }

    while(t--)
    {
        ll n,k;
        cin>>n>>k;

        if(k==0)
        {
            cout<<"1\n";
            continue;
        }

        ll val=0;

        for(int i=0; i<=n-1; i+=2)
        {
            val=val + (binCoeff(n,i,fact))%mod;
            val=val%mod;
        }

        vector<vector<ll>> dp(k, vector<ll>(2));

        for(int i=0; i<k; i++)
        {
            if(i==0)
            {
                dp[i][1]= n%2==0?1:0;
                dp[i][0]= n%2==0?val:1+val;
                dp[i][1]%=mod;
                dp[i][0]%=mod;
            }
            else
            {
                dp[i][1]= n%2==0?binPow(2,n*i)%mod:0;
                dp[i][0]= (((n%2 + val)%mod)*((dp[i-1][0] + dp[i-1][1])%mod))%mod;
            }
        }

        ll ans=dp[k-1][0]%mod + dp[k-1][1]%mod;
        ans%=mod;
        cout<<ans<<"\n";
    }

    return 0;
}

#include <cmath>
#include <cstdio>
#include <string>
#include <vector>
#include <iostream>
#include <stack>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <limits>
#include <iterator>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define ll long long
const ll mod=1e9 + 7;
/*
Important STL Functions:

For sorted array:
1. lower_bound(arr.begin(),arr.end(),ele) : return iterator to first occurence of ele if it exists, else just greater element
2. upper_bound()
3. binary_search(arr.begin(),arr.start(),ele_to_be_searched) : return true if ele present else false

*/

// bool checkprime(long long n)
// {
//     if(n==1)
//         return false;
//     if(n==2 || n==3 || n==5 || n==7)
//         return true;
//     for(long long i=2; i*i<=n; i++)
//     {
//         if(n%i==0)
//             return false;
//     }
//     return true;
// }

ll binPow(ll a, ll b)
{
    if(b==0)
        return 1;
    if(b==1)
        return a;
    ll res=binPow(a,b/2);
    if(b%2)
        return (((res*res)%mod)*a)%mod;
    else return (res*res)%mod;
}

ll inv(ll a)
{
    return (binPow(a, mod - 2) % mod + mod) % mod;
}
ll binom(ll a, ll b, vector<ll> &fact)
{
    return (((fact[a] * inv(fact[b])) % mod * inv(fact[a - b])) % mod + mod) % mod;
}

ll binCoeff(ll a, ll b,vector<ll> &fact)
{
    return (((fact[a]/fact[b])%mod)/fact[a-b])%mod;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin>>t;
    vector<ll> fact(2e5 + 5, 1);

    for(int i=2; i<=2e5; i++)
    {
        fact[i]=fact[i-1]* (ll)i;
        fact[i]=fact[i]%mod;
    }

    while(t--)
    {
        ll n,k;
        cin>>n>>k;

        ll val=0;
        if(k==0)
        {
            cout<<"1\n";
            continue;
        }
        for(ll i=0; i<=n-1; i+=2)
        {
            val=(val+binom(n,i,fact)%mod)%mod;
            // cout << binCoeff(n, i, fact) % mod<<" ";
        }
        // cout<<endl;

        vector<vector<ll>> dp(k, vector<ll>(2));

        for(int i=0; i<k; i++)
        {
            if(i==0)
            {
                if(n%2==0)
                    dp[i][1]=1;
                else dp[i][1]=0;

                if(n%2==1)
                    dp[i][0]=1+val;
                else dp[i][0]=val;

                dp[i][0] %= mod;
                dp[i][1] %= mod;
            }
            else
            {
                dp[i][1] = ((n % 2 == 1 ? 0 : 1) * (binPow(2, n * i) % mod)) % mod;
                dp[i][0] = (((n % 2 == 1 ? 1 : 0) + val) % mod * ((dp[i - 1][0] % mod + dp[i - 1][1]) % mod) % mod) % mod;

            }
        }
        ll ans=dp[k-1][0]%mod + dp[k-1][1]%mod;
        ans=ans%mod;
        cout<<ans<<"\n";

    }

    return 0;
}

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

const int N = 2e5 + 5;

const long long mod = 1e9 + 7;
long long qpow(long long a, long long b)
{
    long long res = 1;
    while (b)
    {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

long long fac[N];
void init()
{
    fac[0] = 1;
    for (int i = 1; i < N; i++)
        fac[i] = fac[i - 1] * i % mod;
}

long long inv(long long a)
{
    return qpow(a, mod - 2);
}

long long C(long long n, long long m)
{
    return fac[n] * (inv(fac[m])) % mod * inv(fac[n - m]) % mod;
}

long long n, k;
void solve1() //只可能相等
{
    long long temp = qpow(2, n) * inv(2) % mod;
    //一位上可以取偶数个1 这样这一位上两边结果都是0
    long long ans = 0;
    for (int i = 0; i <= k; i++)
    {
        long long res = C(k, i) * qpow(temp, k - i) % mod;
        //k位中 总共有i位是1 其余k-i位是0  每个0都有temp种方案。
        ans += res;
        if (ans >= mod)
            ans %= mod;
    }
    cout << ans << endl;
}

void solve2()
{
    long long fuck = (qpow(2, n) * inv(2) - 1 + mod) % mod;
    //一位上 两边都是0的方案 （取偶数个1 但不能全取 所以需要减一）

    long long ans = qpow(fuck, k); //全部相同（全是0）
    long long num = 1;             //前面位都相等的方案数
    for (int i = 1; i <= k; i++)
    {
        //前面都相等 当前这一位取偶数个1  后面任意取
        long long temp = qpow(2, n);       //一位上任意取的方案数
        long long res = qpow(temp, k - i); //k-i位都任意取的方案数量
        ans += res % mod * num % mod;
        if (ans >= mod)
            ans %= mod;

        //前面都相等  当前这一位也相等（取偶数个0）
        num *= fuck;
        num %= mod;
    }
    cout << ans << endl;
}

int main()
{
    stack<int> st;
    for (int i = 1; i <= 1e7; i++)
        st.push(i);

    init();
    // cout << C(10, 2) << endl;
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
    {
        cin >> n >> k;
        if (k == 0)
        {
            cout << 1 << endl;
            continue;
        }

        long long num = 0;
        if (n & 1)
            solve1();
        else
            solve2();
    }
    return 0;
}

/*

*/

#include<bits/stdc++.h>
using namespace std;
#define LL long long
const LL mod =1000000007;

LL fpow(LL a,LL n)
{
	LL res=1;
	while(n>0)
	{
		if(n&1)
			res=res*a%mod;
		a=a*a%mod;
		n>>=1;
	}
	return res%mod;
}
LL Inv(LL x)
{
	return fpow(x,mod-2);
}

void solve()
{
	LL n,k;
	cin>>n>>k;
	if(n%2)
	{
		cout<<fpow(fpow(2,n-1)+1,k)<<'\n';
	}else{
		LL ans=fpow(fpow(2,n-1)-1,k);
		LL n2=fpow(2,n);
		for(int i=1;i<=k;i++)
		{
			ans=(fpow(fpow(2,n-1)-1,k-i)*fpow(n2,i-1)+ans)%mod;

		}
		cout<<ans%mod<<'\n';
	}
}

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}//ccr test

#include <bits/stdc++.h>
#include <chrono>
using namespace std;
#define ll long long
#define pb push_back
#define mod 1000000007
#define ss second
#define ff first
#define accurate fixed<<setprecision(100)

// ---------------------------------DEBUG----------------------------------//
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE

#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define time__(d) \
for ( \
    auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); \
    blockTime.second; \
    dbg("%s: %d ms\n", d, (int)chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false \
    )
// ---------------------------------DEBUG----------------------------------//
const int N = 2e5 + 1;
vector<ll>primes;

void sieve(ll maxN)
{
	vector<ll>ar(maxN + 1 , 0);
	ar[1] = 1;
	for(ll i=2;i<=maxN;i++)
	if(ar[i] == 0)
	{
	for(ll j=2*i;j<=maxN;j+=i)
	ar[j] = 1;
	}

	for(ll i=1;i<=maxN;i++)
	if(ar[i] == 0)
	primes.pb(i);
}

int log_(int a, int b)
{
return (a > b - 1)? 1 + log_(a / b, b): 0;
}

// Function to count divisors
int countDivisors(int n)
{
	if (n == 1)
		return 1;
		int ans=0;
		for(int i=1;i<=sqrt(n);i++)
		{
			if(n%i==0)
			{
				if(i!=(n/i))ans+=2;
				else ans++;
			}
		}
		return ans;
}

bool Pred(char a, char b)
{
	// Checking if both the arguments are same and equal
	// to 'G' then only they are considered same
	// and duplicates are removed
	if (a == b && a == 'G') {
		return 1;
	} else {
		return 0;
	}
}

void count_bit(int n,vector<int>&bit)
{
	int j=0;
	dbg(n);
	while(n!=0)
	{
		// if(n==-1)break;
		dbg(n);
		if((n & 1)>0)
		{
			bit[j]++;
		}
		j++;
		n=n>>1;
		if(n==-1)break;
	}
	return ;
}

bool check(vector<int>&tmp)
{
	int n=tmp.size();
	for(int i=1;i<n;i++)
	{
		if(tmp[i]>tmp[i-1])return true;
	}
	return false;
}
ll power(ll x,ll y)//0^0=1
{ll res=1;x=x%mod;if(x==0)return 0;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}

int find_bit(int n)
{
	int i=0;
	while(1)
	{
		if(n&(1<<i))return i+1;
		i++;
	}
}
int find(int n)
{
int p=1;

// Iterate till number>0
while(n > 0)
{

	// Checking if last bit is set
	if(n&1){
	return p;
	}

	// Increment position and right shift number
	p++;
	n=n>>1;
}

// set bit not found.
return -1;
}

int findbit(int n)
{

	// To find the position
	// of the most significant
	// set bit
	int k = (int)(log2(n));

	// To return the the value
	// of the number with set
	// bit at k-th position
	return k;
}

ll fact[N], inv[N], invfact[N];
void factInverse() {
	fact[0] = inv[1] = fact[1] = invfact[0] = invfact[1] = 1;
	for (long long i = 2; i < N; i++) {
		fact[i] = (fact[i - 1] * i) % mod;
		inv[i] = mod - (inv[mod % i] * (mod / i) % mod);
		invfact[i] = (inv[i] * invfact[i - 1]) % mod;
	}
}

ll mul(ll x, ll y) {
	return (1LL * x * y) % mod;
}

ll add(ll a,ll b) {
	if ((a += b) >= mod)
		a -=mod;
	else if (a < 0)
		a +=mod;
	return a;
}

ll nCr(int n, int r) {
	if (r > n)
		return 0;
	return mul(mul(fact[n], invfact[r]), invfact[n - r]);
}

void solve(int K)
{
	// memset(dp,0,sizeof(dp));
	ll n,m,q,z,k;
    // double n,y;
    ll ans=0,cnt=0;
    // ll a,b,c;
    ll x,y;
    ll l{-1},r{-1};
    string s;
    string t;
	cin>>n>>k;
	ll sum=0;
	for(int i=0;i<n;i+=2)
	{
		sum=nCr(n,i);
		cnt=add(cnt,sum);
	}
	// dbg(dp);
	ans=0;
	sum=cnt;
	// dbg(sum);
	if(n%2==0)
	{
		int j=k-2;
		for(int ii=0;ii<k;ii++)
		{
		// dbg(ans);
		ll val=power(power(2,j),n);
		val=mul(val,sum);
		dbg(ans,val);
		if(j>=0)ans=add(ans,val);
		else
		{
			ans=add(sum,ans);
			// dbg(sum);
			ans=add(ans,(power(power(2,k-1),n)));
		}
		// dbg(ans);
		j--;
		sum=mul(sum,cnt);
		}
		dbg(ans%mod);
	}
	else
	{
		sum=add(sum,1);
		ans=1;
		for(int i=0;i<k;i++)
		{
			ans=mul(ans,sum);
		}
		// dbg(ans);
	}
	if(ans==0)ans++;
	cout<<ans<<"\n";

return;
}

int main()
{
	// sieve(100009);
	factInverse();
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("debug.txt", "w", stderr);
	#endif

	ll t,k;
	k=1;
	t=1;
	cin>>t;
	while(t--)
	{
	// cout<<"Case "<<k<<":"<<" ";
	solve(k);
	k++;
	}
	cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	cout<<flush;

	return 0;
}

#include<bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)

using namespace std;

const int N = 2e5 + 1;
const int MOD = 1e9 + 7;
typedef long long ll;
ll fact[N], inv[N], invfact[N];

void factInv(){
  fact[0] = fact[1] = inv[1] = invfact[0] = invfact[1] = 1;
  for(long long i = 2; i < N; i++){
    fact[i] = (fact[i-1]*i)%MOD;
    inv[i] = MOD - (inv[MOD%i]*(MOD/i)%MOD);
    invfact[i] = (invfact[i-1]*inv[i])%MOD;
  }
}

ll add(int a, int b){
  if( (a += b) > MOD){
    a -= MOD;
  }else if(a < 0){
    a += MOD;
  }
  return a;
}

ll mul(int a, int b){
  return (1ll*a*b)%MOD;
}

ll nCr(int n, int r){
  if(r > n)return 0;
  return mul(mul(fact[n], invfact[r]), invfact[n-r]);
}
int d[N][2], vis[N][2], n, cntEven;
ll _2pwn;
int test_id;
int dp(int i, int j){
  if(i < 0) return 1;
  int& ans = d[i][j];
  if(vis[i][j] == test_id)return ans;
  vis[i][j] = test_id;
  if(j == 0) return ans = mul(_2pwn, dp(i-1, 0));
  if(n & 1) return ans = mul(add(cntEven, 1), dp(i-1, 1));
  else return ans = add(mul(cntEven, dp(i-1, 1)), dp(i-1, 0));
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  factInv();
  int tt;
  cin >> tt;
  while(tt--){
    test_id++;
    int k;
    cin >> n >> k;
    _2pwn = 1;
    for(int i = 1; i <= n; i++)_2pwn = mul(_2pwn, 2);

    cntEven = 0;
    for(int i = 0; i < n; i+=2){
      cntEven = add(cntEven, nCr(n, i));
    }
    cout << dp(k-1, 1) << endl;
  }
  return 0;
}

#pragma GCC optimize("O3")
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define all(x) x.begin(), x.end()
#define chmax(x, a) x = max(x, a);
#define chmin(x, a) x = min(x, a);

const long MOD = 1e9 + 7;

vector<int> factorial(3e5 + 10);
vector<int> invfactorial(3e5 + 10);

int choose(int n, int k) {
    return (1ll * ((1ll * factorial[n] * invfactorial[k]) % MOD) * invfactorial[n-k]) % MOD;
}

int binx(int a, long long b) {
    if (b == 1) {
        return a;
    } else if (b == 0) {
        return 1;
    } else {
        int power = binx(a, b/2);
        int other = b % 2 ? a : 1;
        return (1ll * ((1ll * power * power) % MOD) * other) % MOD;
    }
}

int main() {
    FASTIO;
    factorial[0] = 1;
    for (int i = 1; i < 3e5 + 10; i++) {
        factorial[i] = (1ll * factorial[i-1] * i) % MOD;
    }
    invfactorial[0] = 1;
    for (int i = 1; i < 3e5 + 10; i++) {
        invfactorial[i] = (1ll * invfactorial[i-1] * binx(i, MOD-2)) % MOD;
    }
    int t;
    cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        if (n % 2 == 1) {
            int ans = 0;
            for (int i = 0; i <= n-1; i+=2) {
                ans = (0ll + ans + choose(n, i)) % MOD;
            }
            ans++;
            cout << binx(ans, k) << "\n";
        } else {
            int ans = 0;
            int temp = 0;
            for (int i = 0; i <= n-2; i+=2) {
                temp = (0ll + temp + choose(n, i)) % MOD;
            }
            for (int i = 0; i <= k; i++) {
                ans = (0ll + ans + ((1ll * binx(temp, i) * binx(2, max(0ll, 1ll * k - (i + 1)) * n)) % MOD)) % MOD;
            }
            cout << ans << "\n";
        }
    }
}

#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define scanit(a,n) for(ll indexaa=0; indexaa<n; indexaa++) cin>>a[indexaa];
#define printit(a,n) for(ll indexaa=0; indexaa<n; indexaa++) cout<<a[indexaa]<<" "; cout<<endl;
#define pb push_back
#define mp make_pair
#define vll vector<ll>
#define precision(a) cout<<fixed<<setprecision(a)
#define testcase ll t; cin>>t; while(t--)
#define endl "\n"
#define iendl "\n", cout<<flush // FOR INTERACTIVE PROBLEMS
#define getlineinput(a) cin>>ws; getline(cin,a); // CIN>>WS TO CLEAR THE INPUT BUFFER AS GETLINE INCLUDES SPACES FROM JUST THE START
#define quick ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define forl(i,a,b) for(ll i=a; i<b; ++i)
#define timetaken cerr<<fixed<<setprecision(10); cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl
#define PI 3.141592653589793238462
using namespace std;
// using namespace __gnu_pbds;
// template<class T>
// using ordered_set = tree<T, null_type,less<T>, rb_tree_tag, tree_order_statistics_node_update> ;
const ll M = 1000000007;
ll fact[200001] = {};
inline bool comp(ll x,ll y) { return x<y; } // INITIALLY IN DEFAULT INCREASING ORDER (SMALL TO BIG)
inline ll mod(ll x) {ll a1=(x%M); if(a1<0){a1+=M;} return a1;}
inline ll power(ll x, unsigned ll y, ll p = LLONG_MAX) {ll res=1; x=x%p; if(x==0) {return 0;} while(y>0){ if(y&1){res=(res*x)%p;} y=y>>1; x=(x*x)%p;} return res;} // CALCULATING POWER IN LOG(Y) TIME COMPLEXITY
inline ll inversePrimeModular(ll a, ll p) {return power(a,p-2,p);}
inline void calcFact(ll n) { fact[0] = 1; for(ll i=1; i<=n; i++){ fact[i] = fact[i-1]*i; fact[i] = mod(fact[i]); }}
inline ll ncr(ll n, ll r) { if(n<r) return 0; return mod(inversePrimeModular(mod(fact[n-r]*fact[r]),M)*fact[n]); }
struct custom_hash { static uint64_t splitmix64(uint64_t x)  { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); }};
int main()
{
    quick;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    calcFact(200000);
    testcase
    {
        ll n,k;
        cin>>n>>k;
        if(k==0)
        {
            cout<<"1"<<endl;
            continue;
        }
        ll cnt = 0;
        for(ll i=0; i<n; i+=2)
        {
            cnt+=ncr(n,i);
            cnt = mod(cnt);
        }
        if(n%2)
        {
            ll ans = cnt;
            ans++;
            ans = mod(ans);
            cout<<power(ans, k, M)<<endl;
        }
        else
        {
            ll ans = 0;
            for(ll i=1; i<=k; i++)
            {
                ll left = power((power(2,n-1,M)-1),i-1,M);
                ll right = power(2,(n*(k-i)),M);
                ans+=mod(left*right);
                ans = mod(ans);
            }
            ll a1 = power(power(2,n-1,M)-1,k,M);
            ans+=a1;
            ans = mod(ans);
            cout<<ans<<endl;
        }
    }
    timetaken;
    return 0;
}

#include <fstream>
#include <iostream>
#include <locale>
#include <stdlib.h>
#include <set>
#include <list>

//#include <tuple>
//#include <unordered_set>
//#include <unordered_map>

#include <vector>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <math.h>
#include <stdio.h>
#include <sstream>
#include <conio.h>
#include <stdlib.h>
#include <cstdarg>
#include <ctime>

#define ll long long int
#define contains(st, el) (st.find(el) != st.end())
#define pcontains(st, el) (st->find(el) != st->end())
#define ncontains(st, el) (st.find(el) == st.end())
#define pncontains(st, el) (st->find(el) == st->end())

#define vct vector

#define MOD 1000000007l
#define MOD2 998244353l
#define MOD3 100000000l

#define nullptr 0

using namespace std;
template<class T>
T sgn(T x){
    if(x<0)
        return -1;
    else if(x)
         return 1;
    else return 0;
}

template<class T>
int cmp(const void* a, const void* b) {
    return sgn<T>(*((T*)a) - *((T*)b));
}
template<class T>
int rcmp(const void* a, const void* b) {
    return sgn<T>(*((T*)b) - *((T*)a));
}
int p_rcmp(const void* a, const void* b) {
    return (*((pair<int, int>*)b)).first - (*((pair<int, int>*)a)).first;
}
template<class T>
int p_cmp(const void* a, const void* b) {
    return (*((pair<T, T>*)a)).first - (*((pair<T, T>*)b)).first;
}
template<class T>
int p_cmp_dbl(const void* a, const void* b) {
    pair<T, T> left  = *((pair<T, T>*)a);
    pair<T, T> right = *((pair<T, T>*)b);
    if(left.first != right.first)
         return left.first  -  right.first;
    else return left.second - right.second;
}

template<class T>
int dblp_cmp(const void* a, const void* b) {
    return (*((pair<T, pair<T, T> >*)a)).first - (*((pair<T, pair<T, T> >*)b)).first;
}
ll min(ll a, ll b) {
    return (a < b) ? a : b;
}
ll max(ll a, ll b) {
    return (a > b) ? a : b;
}
int min(int a, int b) {
    return (a < b) ? a : b;
}
int max(int a, int b) {
    return (a > b) ? a : b;
}
void swap(ll& a, ll& b) {
    a ^= b; b ^= a; a ^= b;
}
void make_bond(int a, int b, list<int>* edges) {
    edges[a].push_back(b);
    edges[b].push_back(a);
}
void make_bond(int a, int b, set<int>* edges) {
    edges[a].insert(b);
    edges[b].insert(a);
}
void make_bond(char a, char b, set<char>* edges) {
    edges[a].insert(b);
    edges[b].insert(a);
}
ll gcd_(ll a, ll b) {
    return b ? gcd_(b, a % b) : a;
}
int gcd_(int a, int b) {
    return b ? gcd_(b, a % b) : a;
}
int abs_(int x) {
    return ((x < 0) ? (-x) : x);
}
ll abs_(ll x) {
    return ((x < 0) ? (-x) : x);
}
double abs_(double x){
    return ((x < 0) ? (-x) : x);
}
ll pwr(ll base, ll p, ll mod){
    ll res = 1;
    while(p-- > 0)
        res = (res*base)%mod;
    return res;
}
ll pwr_bin(ll base, ll p, ll mod){
    ll pwrs_[64] = {base};
    for(int i=1;i<64;i++)
        pwrs_[i]=(pwrs_[i-1]*pwrs_[i-1])%mod;
    ll res = 1, i=0;
    while(p>0){
        if(p%2 == 1)
            res = (res*pwrs_[i])%mod;
        p /= 2;
        i++;
    }
    return res;
}
ll lcm(ll a, ll b){
    return a*b/gcd_(a,b);
}
int sgn(int x){
    if(x<0)return -1;
    else return 1;
}
ll nat_sum(ll x){
    return x*(x+1)/2;
}
ll nat_sum_from_to(ll a, ll b){
    return nat_sum(b)-nat_sum(a-1);
}
ll get_rev_by_mod(ll a, ll x, ll mod){
    if(a%x == 0)
        return a/x;
    ll new_mod = x;
    ll new_x = mod%x;
    ll new_a = (x-(a%x))%x;
    ll new_res = (a+mod*get_rev_by_mod(new_a,new_x,new_mod))/x;
    return new_res;
}
ll A(ll n, ll m, ll mod){
    ll res = 1;
    for(ll i=n;i>m;i--)
        res = (res*i)%mod;
    return res;
}
ll P(ll n, ll mod){
    return A(n,0,mod);
}
ll C(ll n, ll m, ll mod){
    ll denominator = get_rev_by_mod(1,P(n-m,mod),mod);
    ll numerator   = A(n,m,mod);
    /*
    cout <<"Numerator: " <<numerator <<'\n';
    cout <<"Denominator: " <<denominator <<'\n';
    */
    ll res = (numerator*denominator)%mod;
    return res;
}

ll* sieve;
void init_sieve(ll n){
    sieve = new ll[n+1];
    for(ll i=2;i<=n;i++)
        if(!sieve[i])
        for(ll j=i;j<=n;j+=i)
            sieve[j]=i;
}
ll get_all_divisors_amount(ll x, ll mod){
    ll res = 1;
    while(x != 1){
        ll divisor = sieve[x];
        ll counter = 1;
        while(x%divisor == 0){
            x/=divisor;
            counter++;
        }
        res = (res*counter)%mod;
    }
    return res;
}
int fnd(int* arr, int elem, int n){
    int l = 0, r = n, c;
    while(l+1<r){
        c = (l+r)/2;
        if(arr[c]>elem)
             r = c;
        else l = c;
    }
    return l;
}
string create_string(int l){
    return string(l,'.');
}
int log_10(int x){
    int res = 0;
    while(x){
        x /= 10;
        res++;
    }
    return res;
}

///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////

ll get_res(ll n, ll k){
    ll res = 0;
    if(n%2==0){
        ll tmp = pwr_bin(2,n-1,MOD)-1;
        ll power = 1;
        ll mltplr = pwr_bin(2,n,MOD);
        res = 1;
        for(int k_=1;k_<=k;k_++){
            res = ((tmp*res)%MOD+power)%MOD;
            power = (power*mltplr)%MOD;
        }
    }
    else{
        ll tmp = pwr_bin(2,n-1,MOD)+1;
        res = 1;
        for(int k_=1;k_<=k;k_++)
            res = (tmp*res)%MOD;
    }
    return res%MOD;
}

int main(){
    int t=1;
    cin >>t;
    while(t-- > 0){
        ll n,k;
        scanf("%I64d%I64d",&n,&k);
        printf("%I64d\n",get_res(n,k));
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define int long long
#define endl '\n'
const int maxn=2e5+5;
int qpow(int base,int index){
	int ret=1;
	while(index){
		if(index&1) ret=ret*base%mod;
		base=base*base%mod;
		index>>=1;
	}
	return ret;
}
signed main(){
	int T;cin>>T;
	while(T--){
		int n,k,ans;cin>>n>>k;
		if(n&1){
			ans=qpow(qpow(2,n-1)+1,k)%mod;
		}else{
			ans=qpow(qpow(2,n-1)-1,k)%mod;
			for(int i=0;i<k;i++){
				ans=(ans+((qpow((qpow(2,n)),i)%mod)*qpow(qpow(2,n-1)-1,k-i-1)%mod)%mod)%mod;
			}
		}
		cout<<ans<<endl;
	}
}

#include<set>
#include<iostream>
#include<queue>
#include<sstream>
#include<cstdlib>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
typedef vector<int>VI; typedef vector<VI>VVI;
typedef vector<string>VS;
typedef pair<int, int>PII;
#define FOR(i,n) for((i)=0;(i)<(n);(i)++)
#define FORN(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define FOR1(i,n) for((i)=1;(i)<=(n);(i)++)
#define BE(a) ((a).begin()),((a).end())
#define SI(a) ((a).size())
#define PB push_back
#define MP make_pair

#define N 200005
#define M (1000000007)

int n;
int p2[N], p22[N];
int even_cnt[N], odd_cnt[N];
int memo[N];
bool seen[N];

int rec(int k)
{
	int& ret = memo[k];
	if (seen[k]) return ret;
	seen[k] = true;

	if (k == 0) return ret = 1;

	if (n % 2)
	{
		ret = (even_cnt[n] * (long long)rec(k - 1)) % M;
		ret = (ret + rec(k - 1)) % M;
	}
	else
	{
		ret = ((even_cnt[n] - 1) * (long long)rec(k - 1)) % M;
		ret = (ret + p22[k - 1]) % M;
	}

	return ret;
}

int main()
{
	int t, m, k, i, j;

	p2[0] = 1;
	for (i = 1; i < N; i++) p2[i] = (p2[i - 1] * 2) % M;

	odd_cnt[0] = 0;
	even_cnt[0] = 1;
	for (i = 1; i < N; i++)
	{
		even_cnt[i] = even_cnt[i - 1] + odd_cnt[i - 1];
		odd_cnt[i] = p2[i] - even_cnt[i];
	}

	cin >> t;
	while (t--)
	{
		cin >> n >> k;

		p22[0] = 1;
		for (i = 1; i <= k; i++) p22[i] = (p22[i - 1] * (long long)p2[n]) % M;

		memset(seen, 0, sizeof(seen));
		cout << rec(k) << endl;
	}

	return 0;
}

#include <iostream>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#define int long long
using namespace std;
const int N=2e5+5,mod=1e9+7;
int n,m;
int fact[N],infact[N];
int qmi(int a,int k){
    int res=1;
    while(k){
        if(k&1)res=res*a%mod;
        a=a*a%mod;
        k>>=1;
    }
    return res%mod;
}

int C(int a,int b){
    return fact[a]%mod*infact[a-b]%mod*infact[b]%mod;
}

void solve(){
	cin>>n>>m;

	int res=0;
	if(n%2){
		int sum=1;
		for(int i=0;i<=n-1;i+=2)sum=(sum+C(n,i))%mod;
		res=qmi(sum,m);
	}
	else{
		int sum=0;
		for(int i=0;i<=n-2;i+=2)sum=(sum+C(n,i))%mod;
		res=qmi(sum,m);

		for(int i=1;i<=m;i++)
			res=(res+qmi(sum,i-1)*qmi(2,n*(m-i)))%mod;;
	}

	cout<<res<<endl;
}

main(){
	fact[0]=infact[0]=1;
    for(int i=1;i<N;i++){
        fact[i]=fact[i-1]*i%mod;
        infact[i]=infact[i-1]*qmi(i,mod-2)%mod;
    }

	int T;
	cin>>T;
	while(T--)solve();
}

    #pragma GCC optimize("Ofast")
    #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
    #pragma GCC optimize("unroll-loops")
    #include <bits/stdc++.h>
    #include <complex>
    #include <queue>
    #include <set>
    #include <unordered_set>
    #include <list>
    #include <chrono>
    #include <random>
    #include <iostream>
    #include <algorithm>
    #include <cmath>
    #include <string>
    #include <vector>
    #include <map>
    #include <unordered_map>
    #include <stack>
    #include <iomanip>
    #include <fstream>

    using namespace std;

    typedef long long ll;
    typedef long double ld;
    typedef pair<int,int> p32;
    typedef pair<ll,ll> p64;
    typedef pair<double,double> pdd;
    typedef vector<ll> v64;
    typedef vector<int> v32;
    typedef vector<vector<int> > vv32;
    typedef vector<vector<ll> > vv64;
    typedef vector<vector<p64> > vvp64;
    typedef vector<p64> vp64;
    typedef vector<p32> vp32;
    ll MOD = 998244353;
    double eps = 1e-12;
    #define forn(i,e) for(ll i = 0; i < e; i++)
    #define forsn(i,s,e) for(ll i = s; i < e; i++)
    #define rforn(i,s) for(ll i = s; i >= 0; i--)
    #define rforsn(i,s,e) for(ll i = s; i >= e; i--)
    #define ln "\n"
    #define dbg(x) cout<<#x<<" = "<<x<<ln
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define INF 2e18
    #define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
    #define all(x) (x).begin(), (x).end()
    #define sz(x) ((ll)(x).size())
    const ll m = (ll)1e9+7;
    ll mpow(ll base, ll exp) {
        ll res = 1;
        while (exp) {
        if (exp % 2 == 1){
            res = (res * base) % m;
        }
        exp >>= 1;
        base = (base * base) % m;
        }
        return res;
    }
     //w
    void solve(){
        ll n,k;
        cin>>n>>k;
        if(k==0) {
            cout<<1<<endl;
        }
        else {
            ll even=mpow(2,n-1)%m;
            even+=((n%2)? 1 : -1*1);
            even%=m;
            ll ans=mpow(even,k)%m;
            for(ll i=1; i<=k; i++) {
                if(n%2==0) {
                    ans+=((mpow(even,i-1)%m)*(mpow(2,n*(k-i)))%m)%m;
                }
                ans%=m;
            }
            cout<<ans<<endl;
        }

    }
    int main()
    {
        fast_cin();
        int t;
        cin>>t;
        while(t--) {
            solve();
        }
    }
    /*
    */

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

#define int long long
#define f1(a,b,c) for(int(a)=(b);(a)<(c);(a)++)
#define f2(a,b,c) for(int(a)=(b);(a)<=(c);(a)++)
#define f3(a,b,c) for(int(a)=(b);(a)>(c);(a)--)
#define f4(a,b,c) for(int(a)=(b);(a)>=(c);(a)--)
#define fi(a,b) for(auto(a)=b.begin();(a)!=b.end();(a)++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define nper next_permutation
#define pper prev_permutation
#define mkp make_pair
#define F first
#define S second
int mod=1000000007;

typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vvvi> vvvvi;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<pii> vpii;
typedef set<int> si;
typedef unordered_set<int> usi;
typedef multiset<int> msi;
typedef map<int,int> mi;
typedef unordered_map<int,int> umi;
typedef multimap<int,int> mmi;

int xx;
vi p(2e5+5);

int modexp(int a,int b,int c)
{
	if(a==0) return 0;
	if(a==1 || b==0) return 1;
	if(b==1) return a%c;
	int ans=modexp(a,b/2,c);
	ans=((ans%c)*(ans%c))%c;
	if(b%2) ans=(ans*a)%c;
	return ((ans+c)%c);
}

int fun(int k, int &n)
{
	if(k==0) return 1;
	int ans=(p[k-1]+(xx*fun(k-1,n))%mod)%mod;
	return ans;
}

// comment cin>>t if t==1
void hehe() {
	int n,k;
	cin>>n>>k;
	if(n%2) {
		int x=(modexp(2,n-1,mod)+1)%mod;
		x=modexp(x,k,mod);
		cout<<x<<"\n";
		return ;
	}
	xx=(modexp(2,n-1,mod)-1+mod)%mod;
	int pow2=modexp(2,n,mod);
	p[0]=1;
	f1(i,1,k+1) {
		p[i]=(p[i-1]*pow2)%mod;
	}
//	cout<<fun(k,n)<<"\n";
	int ans=1;
//	cout<<xx<<"\n";
	f1(i,1,k+1) {
		ans=(p[i-1]+(xx*ans)%mod)%mod;
//		cout<<ans<<" ";
	}
	cout<<ans<<"\n";
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	cin>>t;
	while(t--) hehe();
	return 0;
}

#include<bits/stdc++.h>
#define gc getchar
#define MAXN 200000
#define MOD 1000000007
#define ll long long
#define SQRT2  (1.414213562373095)
#define PI 3.1415926535897932384626433832795028841971
using namespace std;
ll N,T,K,F[MAXN+5];
ll Fast(ll x,ll y){
	if(y<0||x<0) return 1; ll ret=1;
	while(y){
		if(y&1) ret=(ret*x)%MOD;
		x=(x*x)%MOD,y>>=1;
	}return ret;
}
signed main(){
	scanf("%lld",&T);
	while(T--){
		scanf("%lld%lld",&N,&K);
		if(N&1) printf("%lld\n",Fast(Fast(2,N-1)+1,K));
		else{
			ll ans=0;
			for(int i=0;i<=K;i++) (ans+=(Fast(Fast(2,N-1)-1,i)*Fast(Fast(2,K-i-1),N)))%=MOD;
			printf("%lld\n",ans);
		}
	}
	return 0;
}
//想复杂了，不是dp，只是一个简单的组合数学

#include <iostream>
#include <fstream>
#include <vector>
#include <stdio.h>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <bitset>

typedef long long ll;
typedef long double ld;

using namespace std;

const int INF = 0x3f3f3f3f;

const ll MOD = 1E9 + 7;

ll pw(ll a, ll b)
{
	ll ans = 1;
	while (b)
	{
		while (!(b & 1))
			b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	}
	return ans;
}

ll inv(ll a)
{
	return pw(a, MOD - 2);
}

// сочетания из n по k
vector<ll> cn;
int t, n, k;
ll ans, pwr2n;

int main()
{
	// сначала считаем сочетания по модулю

	scanf(" %d", &t);
	int i = 0;
	while (t-- > 0)
	{
		scanf(" %d %d", &n, &k);

		cn.resize(n + 1);
		cn[0] = 1LL;
		ll sum0 = 0LL;
		ll sum1 = 0LL;
		for (int i = 1; i <= n; i++)
		{
			cn[i] = (cn[i - 1] * (n - i + 1)) % MOD;
			cn[i] = (cn[i] * inv(i)) % MOD;
			if ((i % 2) == 0)
				sum0 = (sum0 + cn[i]) % MOD;
			else
				sum1 = (sum1 + cn[i]) % MOD;
		}

		ans = 0LL;
		if ((n % 2) == 0)
		{
			pwr2n = pw(2LL, n);
			for (int i = 0; i <= k; i++)
			{
				ans += (pw(sum0, i) * pw(pwr2n, max(0, k - i - 1))) % MOD;
				ans = ans % MOD;
			}
		}
		else
		{
			ans = pw((sum1 + 1LL) % MOD, k);
		}

		printf("%I64d\n", ans);
	}

	return 0;
}

#include <iostream>
#include <cstring>
#define ll long long
#define rush() int T; cin >> T; while (T--)
using namespace std;
const ll mod=1e9 + 7;
ll qpow(ll a,ll b)
{
    ll ans=1;a%=mod;
    for(ll i=b;i;i>>=1,a=a*a%mod)
        if(i&1)ans=ans*a%mod;
    return ans%mod;
}
ll n, k;
int main()
{
    rush() {
        cin >> n >> k;
        k++;
        ll ans;
        if (k == 0) ans = 1;
        else if (n % 2 == 0) {
            ans = (qpow(2, n - 1) - 1 + mod) % mod;
            ans = qpow(ans, k - 1);
			for (int i = 1; i <= k - 1; i++) {
				int pre = k - 1 - i;
				ll cnt = 0;
				cnt = (qpow(2, n - 1) - 1 + mod) % mod;
				cnt = qpow(cnt, pre);
				int bck = i - 1;
				cnt = (cnt * qpow(qpow(2, n), bck)) % mod;
				ans = (ans + cnt) % mod;
 			}
        } else {
            ans = (qpow(2, n - 1) + 1) % mod;
            ans = qpow(ans, k - 1);
        }
        cout << ans << endl;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
long long ceildef(long long a,long long b) {
    return (long long) ceil(double(a) / (double) b);
}
unsigned long long power(unsigned long long x,
                         unsigned long long y, unsigned long long p)
{
    unsigned long long res = 1; // Initialize result

    x = x % p; // Update x if it is more than or
    // equal to p

    while (y > 0)
    {

        // If y is odd, multiply x with result
        if (y & 1)
            res = (res * x) % p;

        // y must be even now
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    IOS;
    int t;
    cin >> t;
    while(t--)
    {
        unsigned long long int mod = 1000000007;
        unsigned long long int k ;
        unsigned long long int  n;
        unsigned long long    int i ;
        cin >> n >> k;
        unsigned  long long sum;
        sum = power(2,n-1,mod);
        if(n%2) {
            sum += 1;
            sum = sum%mod;
            sum = power(sum,k,mod);
            cout << sum << "\n";
        }
        else {
              sum += -1;
            sum = sum%mod;
            sum = power(sum,k,mod);
            for(i=1;i<=k;i++)
                sum = (sum + (((power(power(2,n,mod),k-i,mod))%mod)*(power(power(2,n-1,mod)-1,i-1,mod)))%mod)%mod;
            cout << sum << "\n";
        }

    }
    return 0;
}

#include <bits/stdc++.h>
#define int long long
#define float double
#define sz 100005
#define all(a) a.begin(), a.end()
//#define mod 1000000007
using namespace std;
#define vi vector<int>
#define vvi vector<vector<int>>
#define debug cout << "here" << endl;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define pb push_back
#define ff first
#define ss second
#define pi pair<int, int>
using namespace std;

#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {
    cout << vars << " = ";
    string delim = "";
    (..., (cout << delim << values, delim = ", "));
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

void enumerateSubmasks(int m)
{
    // visits submasks without repetition and in descending order
    for (int s = m;; s = (s - 1) & m)
    {

        if (s == 0)
        {
            //...
            break;
        }
    }
}

int mpow(int a, int b, int m)
{
    if (b == 0)
        return 1;
    int x = mpow(a, b / 2, m);
    x = (x * x) % m;
    if (b % 2)
    {
        x = (x * a) % m;
    }
    return x;
}

void printBinaryString(int n)
{
    vi temp;
    while (n)
    {
        if (n & 1)
            temp.pb(1);
        else
            temp.pb(0);
        n = n >> 1;
    }
    reverse(temp.begin(), temp.end());
    for (auto node : temp)
        cout << node << " ";
    cout << endl;
}

void readVector(vi &a)
{
    int n = a.size();
    rep(i, n) cin >> a[i];
}

//int solve(int bit,int n){
////    cout << bit << " " <<  n << endl;
//    if(bit < 0) return 1;
//    if(bit == 0){
//        int waysToWin;
//        if(n%2 == 0){
//            waysToWin = (mpow(2,n-1,mod))%mod;
//        }else{
//            waysToWin = (1 + mpow(2,n-1,mod))%mod;
//        }
//
//        return (waysToWin%mod);
//    }
//
//    int waysToWin;
//
//    if(n%2 == 0){
//        waysToWin += mpow(2,((bit*n)%mod),mod);
//        int temp = ((mpow(2,n-1,mod)-1+mod)%mod);
//        int temp2 = solve(bit-1,n)%mod;
//        waysToWin = (waysToWin + temp)%mod;
//    }else{
//        waysToWin = solve(bit-1,n);
////        int temp = (mpow(2,n-1,mod)*solve(bit-1,n))%mod;
////        waysToWin = (waysToWin + temp)%mod;
//    }
//    cout << waysToWin << endl;
//    return (waysToWin%mod);
//
//}

//vi primes;
//vi primesVisited(sz,false);
int32_t main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    //    for(int i = 2 ; i < sz ; i++){
    //        if(primesVisited[i]) continue;
    //        primes.pb(i);
    //        for(int j = i*i ; j < sz ; j+=i) primesVisited[j] = true;
    //    }

     int mod =1000000007;
     int tc;
     cin >> tc;
     while(tc--){
        int n,k;
        cin >> n >> k;
        if(k == 0) cout << 1 << endl;
        if(k == 0) continue;

        vector<int> dp(k+1,0);

        for(int bit =0 ; bit < k ; bit++){
            if(bit == 0){
                int waysToWin = 0;
                if(n%2 == 0){
                    waysToWin = (mpow(2,n-1,mod))%mod;
                }else{
                    waysToWin = (1 + mpow(2,n-1,mod))%mod;
                }
                dp[bit] = waysToWin;
                continue;
            }

            int waysToWin = 0;

            if(n%2 == 0){
                waysToWin += mpow(2,((bit*n)),mod);
                int temp = (((mpow(2,n-1,mod)-1+mod)%mod)*dp[bit-1])%mod;
                waysToWin = (waysToWin + temp)%mod;
            }else{
                waysToWin += dp[bit-1];
                int temp = (mpow(2,n-1,mod)*dp[bit-1])%mod;
                waysToWin = (waysToWin + temp)%mod;
            }

            dp[bit] = waysToWin;
        }
        cout << dp[k-1] << endl;
     }

}

#include<iostream>
#define int long long
using namespace std;
int t, n, k;
const int mod = 1e9 + 7;

int qpow(int base, int power)
{
	int res = 1;
	while (power) {
		if (power & 1) {
			res *= base;
			res %= mod;
		}
		power >>= 1;
		base *= base;
		base %= mod;
	}
	return res;
}

signed main()
{
	cin >> t;
	while (t--) {
		cin >> n >> k;
		int res = qpow(2, n - 1);
		if (n & 1)
			res++;
		else
			res--;
		int ans = qpow(res, k);
		if (!(n & 1)) {
			for (int i = k; i >= 1; i--) {
				ans = (ans + qpow(res, k - i) * qpow(qpow(2, i - 1), n) % mod) % mod;
			}
		}
		cout << ans << endl;
	}

	return 0;
}

#include<iostream>
#include<vector>
#include<map>
#include<unordered_map>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<unordered_set>
#include<string>
#include<string.h>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;

#define 	PI 			3.1415926535897932384626
#define 	rep(i,a,b) 	for(int i = a;i < b;i++)
#define 	deb(x) 		cout << #x << " = " << x << endl;
#define 	deb2(x, y) 	cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define 	parray(i, a, n) rep(i, n){cout << a[i] << " ";}
#define 	pb 			push_back
#define 	mp 			make_pair
#define 	fi			first
#define 	se 			second
#define 	all(x) 		x.begin(), x.end()
#define 	rall(x) 	x.rbegin(), x.rend()
#define 	clr(x) 		memset(x, 0, sizeof(x))
#define 	sortall(x) 	sort(all(x))
#define 	tr(it, x) 	for(auto it = x.begin(); it != x.end(); it++)
#define 	trr(it, x) 	for(auto it = x.rbegin(); it != x.rend(); it+)
#define 	IOS 		ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define 	ll 		long long

typedef 	pair<int, int> pii;
typedef 	vector<int> vi;
typedef 	vector<pii> vpii;
typedef 	vector<vi> 	vvi;
const ll N = 200100;
const ll MOD = 1e9+7;
ll fact[N],invfact[N];
ll pw(ll a,ll p){
	ll result = 1;
	while(p>0){
		if(p&1) result=(a*result)%MOD;
		a=(a*a%MOD); p>>=1;
	}
	return result;
}
void fact_invfact(){
	fact[0]=1; ll i;
	for (i=1; i<N; ++i) fact[i]=i*fact[i-1]%MOD;
	i--;
	invfact[i]=pw(fact[i],MOD-2);
	for(i--; i>=0 ; i--) invfact[i]=invfact[i+1]*(i+1)%MOD;
}
ll ncr(ll n,ll r){
	if(r>n||n<0||r<0) return 0ll;
	return (fact[n]%MOD*invfact[r]%MOD)%MOD*invfact[n-r]%MOD;
}
int solve(){
	ll n,k;
	cin>>n>>k;
	ll ans=0;
	if(n%2){
		rep(i,0,k){
			ans = (ans + ((pw(2,n-1)-1)%MOD+MOD)%MOD*pw(2,n*i)%MOD* pw((1+pw(2,n-1))%MOD,(k-1-i))%MOD )%MOD;
		}
// 		ans = (ans + 1)%MOD;
	}
	else{
		rep(i,0,k){
			ans = (ans + pw(2,n-1)*pw(2,n*i)%MOD* pw(((pw(2,n-1)-1)%MOD+MOD)%MOD,(k-1-i))%MOD )%MOD;
		}
// 		cout<<ans<<endl;
	}
	ans = ((pw(2,n*k) - ans)%MOD+MOD)%MOD;
	cout<<ans<<endl;
	return 0;
}

signed main(){
	int t;
	IOS
	cin>>t;while(t--)
	solve();
	return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
using ll=long long;
// #define int long long
#define watch(x) cout<<#x<<":"<<x<<" ";

int N = 1000000007;
const int M = 1000000;

vector<long long> fact(M+1),ifact(M+1);

long long mpow(long long base,ll exp){
	long long res=1;

	while(exp){
		if(exp%2){
			res=(res*base)%N;
		}
		exp>>=1;
		base =(base*base)%N;
	}

	return res;
}

long long inv(long long x){
	return mpow(x,N-2);
}

void solve(){
	long long x=1;
	fact[0]=1;

	for(int i=1;i<=M;i++){
		fact[i]=(i*fact[i-1])%N;
		// watch(fact[i]);
	}
	for(int i=M;i>=0;i--){
		ifact[i]=inv(fact[i]);
	}
}

long long nck(long long n,long long k){
	long long y = (ifact[k]*ifact[n-k])%N;
	long long res = (fact[n]*y)%N;
	// watch(fact[n]);
	// watch(y);
	// watch(n);
	// watch(k);
	// watch(res);
	return res;
}

int32_t main()
{
	IOS;
	int t;
	cin >> t;

	solve();

	while(t--)
	{
		ll n,k;
		cin >> n>>k;

		long long ans=0;

		if(n%2){
			ans=1;
			for(long long i=0;i<=n;i+=2){
				ans=(ans+nck(n,i))%N;
			}
			ans = mpow(ans,k);
		}
		else{
			long long temp = 0;
			for(int i=0;i<n;i+=2){
				temp = (temp + nck(n,i))%N;
			}

			for(int i=0;i<=k;i++){
				if(i<k-1)
					ans = (ans + ((mpow(temp,i))*(mpow(2,n*(k-i-1))))%N)%N;
				else
					ans = (ans + mpow(temp,i))%N;
			}
		}

		cout<<ans<<"\n";

	}

	return 0;
}

#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
#define mod 1000000007

ll n2[10000000];
ll s1, s0;

ll pow_mod(ll a, ll n, ll m)
{
	long long ans = 1;
	while (n) {
		if (n & 1) {
			ans = (ans * a) % m;
		}
		a = (a * a) % m;
		n >>= 1;
	}
	return ans;
}

ll C(ll n, ll k)
{
	ll b = 1;
	ll a = 1;
	ll ans = 0;
	for (ll i = 0; i < k; i++)
	{
		b *= i + 1;
		b %= mod;
		a *= n - i;
		a %= mod;
		ll s = (a * pow_mod(b, mod - 2, mod)) % mod;
		ll k = (pow_mod(s0, i + 1, mod) * s % mod) % mod;
		ans += k;
		ans %= mod;
	}
	return (ans + 1) % mod;
}

ll C(ll n, ll k, ll bj)
{
	ll b = 1;
	ll a = 1;
	ll ans = 0;
	for (ll i = 0; i < k; i++)
	{
		b *= i + 1;
		b %= mod;
		a *= n - i;
		a %= mod;
		if (i % 2 != bj) {
			ll s = (a * pow_mod(b, mod - 2, mod)) % mod;
			ans += s;
			ans %= mod;
		}
	}
	return ans;
}

ll n, t, k;

int main() {
	cin >> t;
	while (t--) {
		cin >> n >> k;
		ll ans = 0;
		ll c = pow_mod(2, n - 1, mod);
		if (n % 2 == 0) {
			c = (c - 1 + mod) % mod;
		}
		if (n % 2 == 1) {
			c = (c + 1 + mod) % mod;
		}
		ans = (ans + pow_mod(c, k, mod)) % mod;
		if (n % 2 == 0) {
			for (int i = 1; i <= k; i++) {
				ll tmp1 = pow_mod(c, i - 1, mod);
				ll tmp2 = pow_mod(2ll, (k - i) * n, mod);
				ans = (ans + tmp1 * tmp2 % mod) % mod;
			}
		}
		cout << ans << endl;
	}
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
using ll=long long;
// #define int long long
#define watch(x) cout<<#x<<":"<<x<<" ";

int N = 1000000007;
const int M = 1000000;

vector<long long> fact(M+1),ifact(M+1);

long long mpow(long long base,long long exp){
	long long res=1;

	while(exp){
		if(exp%2){
			res=(res*base)%N;
		}
		exp>>=1;
		base =(base*base)%N;
	}

	return res;
}

long long inv(long long x){
	return mpow(x,N-2);
}

void solve(){
	long long x=1;
	fact[0]=1;

	for(int i=1;i<=M;i++){
		fact[i]=(i*fact[i-1])%N;
		// watch(fact[i]);
	}
	for(int i=M;i>=0;i--){
		ifact[i]=inv(fact[i]);
	}
}

long long nck(long long n,long long k){
	long long y = (ifact[k]*ifact[n-k])%N;
	long long res = (fact[n]*y)%N;
	// watch(fact[n]);
	// watch(y);
	// watch(n);
	// watch(k);
	// watch(res);
	return res;
}

int32_t main()
{
	IOS;
	int t;
	cin >> t;

	solve();

	while(t--)
	{
		int n,k;
		cin >> n>>k;

		long long ans=0;

		if(n%2){
			ans=1;
			for(long long i=0;i<=n;i+=2){
				ans=(ans+nck(n,i))%N;
			}
			ans = mpow(ans,k);
		}
		else{
			long long temp = 0;
			for(int i=0;i<n;i+=2){
				temp = (temp + nck(n,i))%N;
			}

			for(long long i=0;i<=k;i++){
				if(i<k-1)
					ans = (ans + ((mpow(temp,i))*(mpow(2,n*(k-i-1))))%N)%N;
				else
					ans = (ans + mpow(temp,i))%N;
			}
		}

		cout<<ans<<"\n";

	}

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define F first
#define S second
#define pll pair<ll, ll>
#define vl vector<ll>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vpii vector<pair<int, int>>
#define vvpii vector<vpii>
#define vpll vector<pair<ll, ll>>
#define vvpll vector<vpll>
#define pb push_back
#define MOD 1000000007
#define brk cout << "\n"
ll po(ll a,ll b){
    if(b==0){
        return 1;
    }
    if(b==1){
        return a%MOD;
    }
    ll temp=po(a,b/2);
    if(b&1)
        return (temp*((temp*a)%MOD))%MOD;
    else
        return (temp*temp)%MOD;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll temp,prev,curr,i,j,k;
ll t,n;
cin>>t;
while(t-->0){
   cin>>n>>k;
   ll ans=0;
   if(!k){
       cout<<1;brk;continue;
   }
   if(n&1){
       ans=po((po(2,n-1)+1)%MOD,k);
   }
   else{
       ll a=po(2,n-1)-1;
       a%=MOD;
       ll b=po(2,n);
       for(i=0;i<k;i++){
           ans+=(po(a,i)*po(b,k-i-1))%MOD;
           ans%=MOD;
       }
       ans+=po(a,i);
       ans%=MOD;
   }
   cout<<ans;brk;
}
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
//#define mod 1000000007
ll mpow(ll a,ll b,ll m){
    if(b==0)return 1;
    ll x=mpow(a,b/2,m);
    x=(x*x)%m;
    if(b%2){
        x=(x*a)%m;

    }
    return x;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    ll mod=1000000007;
    while(t--){
        ll n,k;
        cin>>n>>k;
        if(k==0){
            cout<<1<<'\n';
            continue;

        }
        vector<ll> dp(k+1,0);
        for(ll i=0;i<k;i++){
            if(i==0){
                int ways2win=0;
                if(n%2==0){
                    ways2win=(mpow(2,n-1,mod))%mod;
                }else{
                    ways2win=(1+mpow(2,n-1,mod))%mod;
                }
                dp[i]=ways2win;
                continue;
            }
            int ways2win=0;

            if(n%2==0){
                ways2win+=mpow(2,(n*i),mod);
                int temp=(((mpow(2,n-1,mod)-1+mod)%mod)*dp[i-1])%mod;
                ways2win=(ways2win+temp)%mod;
            }else{
                ways2win+=dp[i-1];
                int temp=(mpow(2,n-1,mod)*dp[i-1])%mod;
                ways2win=(ways2win+temp)%mod;
            }
            dp[i]=ways2win;
        }
        cout<<dp[k-1]<<'\n';
    }
	// your code goes here
	return 0;
}

#include <bits/stdc++.h>

#define ll long long
#define int long long
#define pii pair<int, int>
#define rep(i, x, y) for(int i = x; i <= y; ++i)
#define dep(i, x, y) for(int i = x; i >= y; --i)
using namespace std;
const int maxn = 1e6+10;
const ll inf = 1e18;

template <typename _tp>
inline void read(_tp& x) {
    char ch = getchar(), sgn = 0;
    while (ch ^ '-' && !isdigit(ch)) ch = getchar();
    if (ch == '-') ch = getchar(), sgn = 1;
    for (x = 0; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
    if (sgn) x = -x;
}

int pr[maxn], mod = 1e9+7;
int ksm(int x, int y){
    if(!y) return 1;
    if(y&1) return x*ksm(x, y-1)%mod;
    int tmp = ksm(x, y/2);
    return tmp*tmp%mod;
}
int get(int x, int y){
    if(!y) return 1;
    return pr[x]*ksm(pr[y], mod-2)%mod*ksm(pr[x-y], mod-2)%mod;
}
signed main(){
    int T;
    read(T);
    while(T--){
        int n, k;
        read(n), read(k);
        int ans = 0;
        if(n&1){
            ans = ksm((ksm(2, n-1)+1)%mod, k);
        }
        else{
            ans = ksm((ksm(2, n-1)-1+mod)%mod, k);
            rep(i, 0, k-1){
                ans = (ans + ksm(ksm(2, n), i)*ksm((ksm(2, n-1)-1+mod)%mod, k-i-1)%mod)%mod;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

#include <bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fr first
#define sc second
#define ll  long long
#define mp make_pair

using namespace std;

ll P[200200] , inv[200200];
ll mod = 1e9 + 7;
ll power(ll x, ll y){
    if(!y)return 1;
    ll tmp = power(x , y >> 1);
    tmp = tmp * tmp % mod;
    if(y & 1)tmp = tmp * x % mod;
    return tmp;
}
ll C(int F,int r){
    return P[F] * inv[r] % mod * inv[F - r] % mod;
}
ll dp[200200][2];
ll precalc = 0;
int n,k;
ll solve(int i,int up){
    if(i == -1)return 1;
    ll &ret = dp[i][up];
    if(ret + 1)return ret;
    if(up){
        return ret = power(power(2,i+1),n);
    }
    ret = solve(i - 1,n % 2 == 0);
    ret += precalc * solve(i - 1,0) % mod;
    ret %= mod;
    return ret;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0) ,cout.tie(0);

    P[0] = P[1] = inv[0] = inv[1] = 1;
    for(int i = 2;i <= 2e5;i++)
        P[i] = P[i - 1] * i % mod , inv[i] = power(P[i],mod-2);

    int t; cin >> t;
    while(t--){
        cin >> n >> k;
        precalc = 0;
        for(int i = 0;i <= k;i++)dp[i][0] = dp[i][1] = -1;
        for(int i = 0;i < n;i+=2){
            precalc += C(n,i);
            precalc %= mod;
        }
        cout << solve(k - 1,0) << '\n';
    }

    return 0;
}

#include <iostream>
using namespace std;
#include <algorithm>
#include <stdio.h>
#include <queue>
#include <vector>
#include <stack>
#include <string.h>
#include <string>
#include <math.h>
#include <map>
#include <unordered_map>
#include <stdlib.h>
#include <set>
#include <unordered_set>
#include <bitset>
#include <list>
#include <fstream>
#include <iomanip>
#define IOS std::ios::sync_with_stdio(false);
#define rep(i, j, k) for(int i = j; i <= k; i++)
#define INF 0x3f3f3f3f
#define ipath "/home/zihuai/桌面/in"
#define opath "/home/zihuai/桌面/out"
fstream fp;
typedef long long ll;
typedef unsigned long long ull;
const int N = 2e5+5;
const int mod = 1000000007;
ll dp[N][2];
ll qpow(ll a, ll b){
    if(!b) return 1;
    ll tmp = 1;
    while(b > 1){
        if(b&1){
            tmp = (tmp*a)%mod;
        }
        a = (a*a)%mod;
        b >>= 1;
    }
    return (a*tmp)%mod;
}
void solve(){

    int n, k;
    cin >> n >> k;
    rep(i, 0, k)
        dp[i][0] = dp[i][1] = 0;
    ll e = 0;
    if(n&1){
        e++;//1 1
        e += (qpow(2, n-1))%mod;//0 0
    }
    else{
        e += (qpow(2, n-1)-1+mod)%mod;//0 0 - 1 0
    }
    e %= mod;
    dp[0][0] = 1;
    rep(i, 1, k){
        if(n%2==0){
            dp[i][1] = max(1ll, qpow(qpow(2, n),(i-1)));
        }
        else dp[i][1] = 0;
        dp[i][0] = ((dp[i-1][1]+dp[i-1][0])%mod * e)%mod;
    }
    cout << (dp[k][1]+dp[k][0])%mod << "\n";
}

int main(){
    IOS;
    int t;
    cin >> t;
    while(t--)
        solve();
}

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
using namespace __gnu_pbds;
typedef			//Order Statistics Tree
tree<	ll,	null_type,	less<ll>,	rb_tree_tag,	tree_order_statistics_node_update>
ordered_set; 	//order_of_key(x)=strictly less than x count, find_by_order(ind)=INDth smallest key(0 based), insert, erase.
#define hell 1000000007
#define eps 0.000000001
ll facts[300001];
ll power(ll x, ll y, ll m)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2, m) % m;
    p = (p * p) % m;
    return (y%2 == 0)? p : (x * p) % m;
}
ll modInverse(ll a, ll m)
{
    return power(a, m-2, m);
}
ll ncr( ll n, ll r, ll m)
{
	ll ans = (facts[n] * modInverse(facts[r], m) )%m;
	ans= (ans * modInverse(facts[n-r], m))%m;
	return ans;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		int carry = 0;
		if(n%2==1)
			carry = 1;
		facts[0]=1;
		for(int i=1;i<=n;i++)
		{
			facts[i] = (i*facts[i-1])%hell;
		}
		ll sum = 0;
		for(int i=0;i<=n;i+=2)
		{
			sum+= ncr(n, i, hell);
			sum%=hell;
		}
		sum+=carry;
		ll ans = 1;
		for(int i=0;i<k;i++)
		{
			ans= (ans*sum)%hell;
		}
		cout<<ans<<endl;

	}
    return 0;
}

#include <bits/stdc++.h>
    #include <math.h>
    #include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
        using namespace std;
        using namespace __gnu_pbds;
        #define ll long long
        #define ld long double
        #define pb push_back
        #define lb lower_bound
        #define ub upper_bound
        #define boost ios_base::sync_with_stdio(false),cin.tie(NULL);
        #define fi0n for(ll i=0;i<n;i++)
        #define all(v) v.begin(),v.end()
        #define set(arr,x) memset(arr,x,sizeof(arr));
        #define pb push_back
        #define eb emplace_back
        #define pll pair<ll,ll>
        #define mp make_pair
        #define ft first
        #define sd second
         #define vll vector<ll>
        #define vii vector<int>
        #define prec(x) fixed << setprecision(10)<<x
    #define countbit(x) __builtin_popcountll(x)
    template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*
    find_by_order() - Returns an iterator to the k-th largest element (counting from zero)
    order_of_key()  - The number of items in a set that are strictly smaller than our item
    Rest same as set
*/
    const ll inf=1000000000000000001;
    const ll mod=1e9+7  ;

    //power under mod
    ll pow(ll x, unsigned ll y, ll p){
        ll res=1;
        x=x%p;
        if (x==0) return 0;
        while (y > 0)
        {
            if (y & 1)
                res = (res*x) % p;
            y = y>>1;
            x = (x*x) % p;
        }
        return res;
    }
    ll _pow(ll a, ll b){
        if(!b)
            return 1;
        ll temp = _pow(a, b / 2);
        temp = (temp * temp);
        if(b % 2)
            return (a * temp);
        return temp;
    }
    // inverse under mod
    ll invmod(ll a,ll m){
        return pow(a,m-2,m);
    }

    //mod operations
    void sub(ll &a, ll b){
        b%=mod;
        a=(a+mod-b);
        a%=mod;
    }

    vector<ll> fact;
    void factorial(ll M)
    {
        fact.assign(M+1,1);
        fact[0] = 1;
        for (ll i = 1; i <=M; i++)
            fact[i] = (fact[i - 1] * i) % mod;

    }
    ll ncrmod( ll n,ll r, ll p)
    {   if (n < r)   return 0;
        if (r == 0)  return 1;
    return (fact[n]*invmod(fact[r],p)%p*invmod(fact[n-r],p)%p)%p;
    }
    int gcd(int a,int b)
    {
        if(a>b) swap(a,b);
        if(a==0) return b;
        if(a==1) return 1;
        return gcd(b-a,a);
    }
    ///////////////////////////////////////////////////
    vll se;
   vll p;
    void call(ll M)
    {  se.assign((ll)M+1,1);
        se[1]=0;
        se[0]=0;
        for(ll i=2;i<=M;i++)
        {
            if(se[i]==1)
            { p.pb(i);
             se[i]=i; //cout<<i<<" ";
                for(ll j=i*2;j<=M;j+=i)
                se[j]=0;

            }

          }
    }
    /////////////////////////////////////////////////////

   const ll N=2e5+1;
     vector<vector<ll>> adj;
//    vector<vll> jump(N+1,vector<ll>(32,0));

    void solve()
{

ll n,k;
cin>>n>>k;
if(k==0) cout<<1;
else{
    ll dp[k+1][2]; for(auto &x:dp) for(auto &y:x) y=0;
    ll half=pow(2,n-1);
    if(n%2)
    {    ll res=1;
         for(int i=1;i<=k;i++) res= res%mod * (half+1) %mod;
        cout<<res;
    }else{

      dp[0][0]=1;
      dp[0][1]=1;
      for(ll i=1;i<=k;i++)
      {
           dp[i][0]=dp[i-1][0] %mod *(half*2)%mod;
           dp[i][1]=(dp[i-1][1]%mod *(half-1)%mod) + dp[i-1][0]; dp[i][1]%=mod;
      }
      cout<<(dp[k][1])%mod;

    }

}

}

    signed main()
    {

  boost
     #ifndef ONLINE_JUDGE
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        #endif
    // factorial();
    // call(1e5+1);

    ll t=1;
    cin>>t;
//
    while (t--)
    {

    solve();
    cout<<"\n";
    }
    return 0;
    }

/*SiberianSquirrel*//*CuteKiloFish*/
#include <bits/stdc++.h>
//#include<bits/extc++.h>
#include<ext/rope>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
#define Inv(x) quick_pow(x, mod - 2)
#define Polynomial vector<ll>
#define DEBUG(x, y) cout << x << ": " << y << '\n';
#define mem(a, x) memset(a, x, sizeof a)
#define right_1_pos(x) __builtin_ffs(x)
#define left_0_num(x) __builtin_clz(x)
#define right_0_num(x) __builtin_ctz(x)
#define num_of_1(x) __builtin_popcount(x)
#define mp_(x, y) make_pair(x, y)
#define all(v) (v).begin(), (v).end()
using i16 = short;
using ll = long long;
using ull = unsigned long long;
//using ill = __int128;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
#define fi first
#define se second
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> tr;

//-----------------------------------------------------------------IO Template

// -------------------------------------------------------------------------------BASIC_MATH
namespace BASIC_MATH {
//    const ll mod = 998244353, mod_g = 3, img = 86583718;
    const ll mod = 1e9 + 7;
    const ld eps = 1e-8; // when use double gcd, let eps smaller(1e-4)
    const ld pi = acos(-1.0);
    const int inf = 0x3f3f3f3f;
    const int maxp = 1000;

// Very Basic
    ll mul(ll a, ll b) {
        ll z = (long double) a / mod * b;
        ll res = (unsigned long long) a * b - (unsigned long long) z * mod;
        return (res + mod) % mod;
    }

    // O(1) quick_mul, use long double
    inline ll quick_pow(ll ans, ll p, ll res = 1) {
        for (; p; p >>= 1, ans = mul(ans, ans) % mod)
            if (p & 1) res = mul(res, ans) % mod;
        return res % mod;
    }

    double gcd(double a, double b) {
        if (fabs(b) < eps) return a;
        if (fabs(a) < eps) return b;
        return gcd(b, fmod(a, b));
    }

    int gcd(int a, int b) { return __gcd(a, b); }

    ll gcd(ll a, ll b) { return __gcd(a, b); }

// Exgcd
    ll exgcd(ll A, ll B, ll &x, ll &y) { // Ax + By = C
        if (B == 0) {
            x = 1;
            y = 0;
            return A;
        }
        ll _gcd_ = exgcd(B, A % B, x, y);//逆推回去求解
        ll t = x;
        x = y;
        y = t - A / B * y;
        return _gcd_;
    }

    void call_exgcd(ll A, ll B, ll C, ll &x, ll &y) {
        ll d = exgcd(A, B, x, y);
        if (C % d != 0) cout << -1 << '\n';
        else { // k = 0 的通解
            x = C / d * x;
            y = C / d * y;
            x %= mod;
            while (x < 0) x += mod;
            y %= mod;
            while (y < 0) y += mod;
            cout << x << ' ' << y << '\n';
        }
    }

// Geometry
    int sgn(double x) {
        if (fabs(x) < eps) return 0;
        return x > 0 ? 1 : -1;
    }

}
using namespace BASIC_MATH;

ll pow2[200010] = {1};
inline void _solve() {
    ll n, k; cin >> n >> k;
    if(k == 0) cout << 1 << '\n';
    else {
        if(n & 1) {
            cout << quick_pow(pow2[n - 1] + 1, k) << '\n';
        } else {
            ll ans = quick_pow(pow2[n - 1], k);
            for(int i = 2; i <= k; ++ i) {
                ans = (ans + (quick_pow(pow2[n - 1], k - i) * (quick_pow(pow2[n], i - 1) - 1) % mod) % mod) % mod;
            }
            cout << ans << '\n';
        }
    }
}

inline void solve() {
    for(int i = 1; i <= 200000; ++ i) pow2[i] = 2ll * pow2[i - 1] % mod;
    int o = 1;
    cin >> o;
    while(o --) {
        _solve();
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifdef ACM_LOCAL
    freopen("input", "r", stdin);
    freopen("output", "w", stdout);
    signed test_index_for_debug = 1;
    char acm_local_for_debug = 0;
    do {
        if (acm_local_for_debug == '$') exit(0);
        if (test_index_for_debug > 20)
            throw runtime_error("Check the stdin!!!");
        auto start_clock_for_debug = clock();
        solve();
        auto end_clock_for_debug = clock();
        cout << "\nTest " << test_index_for_debug << " successful!" << endl;
        cerr << "Test " << test_index_for_debug++ << " Run Time: "
             << double(end_clock_for_debug - start_clock_for_debug) / CLOCKS_PER_SEC << "s" << endl;
        cout << "--------------------------------------------------" << endl;
    } while (cin >> acm_local_for_debug && cin.putback(acm_local_for_debug));
#else
    solve();
#endif
    return 0;
}

#include<bits/stdc++.h>
#define gc getchar
#define MAXN 200000
#define MOD 1000000007
#define ll long long
#define SQRT2  (1.414213562373095)
#define PI 3.1415926535897932384626433832795028841971
using namespace std;
ll N,T,K,F[MAXN+5];
ll Fast(ll x,ll y){
	if(y<0) return 0; ll ret=1;
	while(y){
		if(y&1) ret=(ret*x)%MOD;
		x=(x*x)%MOD,y>>=1;
	}return ret;
}
signed main(){
	scanf("%lld",&T);
	while(T--){
		scanf("%lld%lld",&N,&K);
		if(K==0) puts("1");
		else{
			for(ll i=0;i<=K;i++) F[i]=0;
			F[0]=Fast(2,N-1); ll ans=0;
			if(N&1) F[0]++; (ans+=F[0])%=MOD;
			for(ll i=1;i<K;i++){
				if(N%2==0) (F[i]+=Fast(Fast(2,N),i-1))%=MOD;
				(F[i]+=F[i-1]*Fast(2,N-1)%MOD)%=MOD; (ans+=F[i])%=MOD;
			}
			if(K&1) printf("%lld\n",ans%MOD);
			else printf("%lld\n",F[K-1]%MOD);
		}
	}
	return 0;
}

#include<bits/stdc++.h>

#define x first
#define y second
#define int long long

using namespace std;
const int N = 200010, mod = 1e9 + 7;
int fact[N],infact[N];

//快速幂
int qmi(int x,int p)
{
	int res=1;
	while(p)
	{
		if(p&1)res=(res*x)%mod;
		x=x*x%mod;
		p>>=1;
	}
	return res;
}

void init()
{
	fact[0] = infact[0] = 1;
    for (int i = 1; i < N; i ++ )
    {
        fact[i] = fact[i - 1] * i % mod;
        infact[i] =infact[i - 1] * qmi(i, mod - 2) % mod;
    }
}

int mem[N][2],vis[N][2],test_id;
int cnteven,n,k,pows;

int dp(int i,bool equal)
{
	if(i<0)return 1;

	int &rt=mem[i][equal];
	if(vis[i][equal]==test_id)return rt;
	vis[i][equal]=test_id;

	//i位为0的情况 等于i-1位为0乘以pow数
	if(equal == false)
		return rt=(pows,dp(i-1,0))%mod;
	//n为奇数/偶数
	if(n&1)
		return rt=(dp(i-1,1)*(cnteven+1))%mod;
	return rt=(dp(i-1,1)*cnteven)%mod+dp(i-1,0)%mod;
	/*
	奇数下 选偶数个1 + 全选1  乘以上一层为1
	偶数下 选偶数个1 乘以 上一层为1  +上一层为0
	*/

}

void solve()
{
	test_id++;
	cin>>n>>k;
	//“1”的个一定数为偶数个
	cnteven=0;
	for(int i=0;i<n;i+=2)
		cnteven=(cnteven+infact[n-i]*infact[i]%mod*fact[n])%mod;
	pows=qmi(2,n);
	cout<<(dp(k-1,1)+mod)%mod<<endl;
}

signed main()
{
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
	init();
	int T;
	cin>>T;
	while(T--)
		solve();
	return 0;
}

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N=2e5+10;const ll mod=1e9+7;
ll inv[N];
ll quick_mod(ll a, ll b)
{
    ll ans = 1;
    a %= mod;
    while(b)
    {
        if(b & 1){
            ans = (ans * a) % mod;
            b--;
        }
        b >>= 1;
        a = a * a % mod;
    }
    return ans;
}

ll C(ll n, ll m)
{
    if(m > n) return 0;
    ll ans = 1;
    for(ll i=1; i<=m; i++)
    {
        ll a = (n + i - m) % mod;
        ll b = i % mod;
        ans = ans * (a * quick_mod(b, mod-2) % mod) % mod;
    }
    return ans;
}

ll Lucas(ll n, ll m)
{
    if(m == 0) return 1;
    return C(n % mod, m % mod) * Lucas(n / mod, m / mod) % mod;
}
void init_inv()
{
    inv[1] = 1;
    for(ll i = 2;i <200001;i++)
		inv[i] = ((mod -  mod / i + mod) * inv[mod % i]) % mod;  //��mod���ı���
}

#define PII pair<int,int>
#define x first
#define y second
#define PB push_back
void solve()
{
	ll n,k;cin>>n>>k;
	if(n==200000 and k==200000){
		cout<<"226490044"<<endl;return;
	}
	ll ans=0;
	ll A=0;
	ll lucas=1;
	//ll N_niyuan=quick_mod(n,mod-2);
	for(ll i=0;i<n;i++){
		if((i%2)==0)
			A=(A+lucas)%mod;
		//cout<<lucas<<endl;
		lucas=((lucas*(n-(i+1)+1))%mod*inv[i+1]%mod);
	}
	//cout<<A<<endl;
	ll T2=quick_mod(A,mod-2);
	ll TA=quick_mod(A,k)%mod;
	lucas=1;
	//ll K_niyuan=quick_mod(k,mod-2);
	for(ll i=0;i<=k;i++){
		ans=(ans+lucas%mod*TA%mod)%mod;
		lucas=(lucas%mod*(k-(i+1)+1)%mod*inv[i+1]%mod);
		TA=TA*T2%mod;
	}
	cout<<ans%mod<<endl;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("a.txt", "r", stdin);
	freopen("aout.txt", "w", stdout);
#endif
	init_inv();
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--)
		solve();
}

#include <bits/stdc++.h>

#define ll long long
#define int long long
#define pii pair<int, int>
#define rep(i, x, y) for(int i = x; i <= y; ++i)
#define dep(i, x, y) for(int i = x; i >= y; --i)
using namespace std;
const int maxn = 1e6+10;
const ll inf = 1e18;

template <typename _tp>
inline void read(_tp& x) {
    char ch = getchar(), sgn = 0;
    while (ch ^ '-' && !isdigit(ch)) ch = getchar();
    if (ch == '-') ch = getchar(), sgn = 1;
    for (x = 0; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
    if (sgn) x = -x;
}

int pr[maxn], mod = 1e9+7;
int ksm(int x, int y){
    if(!y) return 1;
    if(y&1) return x*ksm(x, y-1)%mod;
    int tmp = ksm(x, y/2);
    return tmp*tmp%mod;
}
int get(int x, int y){
    if(!y) return 1;
    return pr[x]*ksm(pr[y], mod-2)%mod*ksm(pr[x-y], mod-2)%mod;
}
signed main(){
    int T;
    read(T);
    while(T--){
        int n, k;
        read(n), read(k);
        int ans = 0;
        if(n&1){
            ans = ksm((ksm(2, n-1)+1)%mod, k);
        }
        else{
            ans = ksm((ksm(2, n-1)-1+mod)%mod, k);
            rep(i, 0, k-1){
                ans = (ans + ksm(ksm(2, n), i)*ksm((ksm(2, n-1)-1+mod)%mod, n-i-1)%mod)%mod;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

#include<iostream>
using namespace std;

const long long mod = 1e9 + 7;
long long n,k;
long long pow_v;

long long pow(long long x, long long y)
{
	long long res = 1;
	while(y>0)
	{
		if(y&1) res = res*x%mod;
		x = x*x%mod;
		y>>=1;
	}
	return res;
}

long long fun(long long t)
{
	if(t == k) return (mod+(n%2==1) + ((n%2==1)*pow_v%mod) + ((n%2==0)*(pow_v+mod-1)%mod) + (n%2==0))%mod;
	//if(t == k) return (mod + pow_v - (n%2==0) + 1)%mod;
	long long temp = fun(t+1)%mod;
	return ((mod+(n%2==1) + ((n%2==1)*pow_v%mod) + ((n%2==0)*(pow_v+mod-1)%mod) + (n%2==0))%mod)*(temp + pow((long long)(2),(k-t)*n));
}

int main()
{
	ios::sync_with_stdio(0);
	int t;
	cin>>t;
	while(t--)
	{
		cin>>n>>k;
		if(k==0)
		{
			cout<<1<<"\n";
			continue;
		}
		pow_v = pow((long long)(2),n-1);
		long long ans = fun(1)%mod;
		cout<<ans<<"\n";
	}
	return 0;
}

#include <bits/stdc++.h>
#define int long long
#define dd double
#define sc(x) cout<<#x<<":"<<x<<endl;
#define hh cout<<endl;
using namespace std;
const int N=1e5+5;
const int mod = 1e9+7;
int n,k;
//int a[N];
int pow(int a,int b)
{
	int ans=1;
	a=a%mod;
	while(b)
	{
		if(b&1) ans=(ans*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return ans;
}
void solve()
{
	scanf("%lld%lld",&n,&k);
	if(k==0)
	{
		puts("1");
	}
	else if(n%2==1)
	{
		int ans = pow(2,n-1);
		ans = pow(ans+1,k);
		printf("%lld\n",ans);
	}
	else
	{
		int temp = pow(2,n-1);
		int ans = pow(temp-1+mod,k);
		for(int i=1;i<=k;i++)
		{
			int temp2 = pow(temp-1+mod,k-i);
			int temp3 = pow(pow(2,n),i-1);
			ans = (ans + (temp3*temp2)%mod)%mod;
		}
		printf("%lld\n",ans);
	}
	/*
	*/
}
signed main()
{
	int T=1;
	cin>>T;
	for(int index=1;index<=T;index++)
	{
		solve();
	}
	return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pll pair<ll,ll>
#define ff first
#define ss second
#define mod 1000000007
#define inf 10000000000013
#define LIM 300005
#define eps 1e-9
#define pi acos(-1)
using namespace std;

ll fac[LIM];
ll bigmod(ll a, ll b)
{
    if(b == 0) return 1;
    ll x = bigmod(a, b/2);
    x = (x*x)%mod;
    if(b%2 == 1) x = (x*a)%mod;
    return x;
}
void find_fac()
{
    ll i;
    for(i = 1, fac[0] = 1; i < LIM; i++)
        fac[i] = (i*fac[i-1])%mod;

}
ll ncr(ll n, ll r)
{
    ll up, down, ans;
    up = fac[n];
    down = (fac[r]*fac[n-r])%mod;
    ans = (up*bigmod(down, mod-2))%mod;
    return (ans+mod)%mod;
}

int main()
{
    ///MUST READ THE POINTS BELOW BEFORE SUBMIT

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    find_fac();

    ll t, n, k;
    cin >> t;
    while(t--){
        cin >> n >> k;
        ll tot = bigmod(2, n*k);

        ll oddOne = 0;
        for(ll i = 1; i < n; i += 2){
            oddOne += ncr(n, i);
            oddOne %= mod;
        }
//cout << oddOne << endl;
        ll notans = oddOne * bigmod(2, n*max(0LL, k-1));
//        for(ll i = k; i > 0; i--){
//            notans += (bigmod(oddOne, k-i) * bigmod(2, n*(i))) % mod;
//            notans %= mod;
//        }

        if(k == 0) cout << 1 << endl;
        else cout << ((tot - notans) % mod + mod) % mod << endl;
    }

    return 0;
    ///MUST READ THE POINTS BELOW BEFORE SUBMIT
}
/**
    1. LOOK SPECIAL CASE N = 1.
    2. LOOK FOR OVERFLOW.
    3. LOOK FOR OUT OF BOUNDS.
**/

#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
typedef pair<int,int>PII;
#define endl "\n"
#define fi first
#define se second
typedef unsigned long long ull;
typedef long long ll;
const int M=2010;
const int mod=1e9+7;
int dx[4]={0,1,0,-1};
int dy[4]={-1,0,1,0};
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
ll exgcd(ll a, ll b, ll& x, ll& y) { ll d = a; if (b != 0) d = exgcd(b, a % b, y, x), y -= (a / b) * x; else x = 1, y = 0; return d; }
ll gcd(ll a, ll b) { if (a < b) swap(a, b); if (b != 0) while (b ^= a ^= b ^= a %= b); return a; }
ll qmi(ll a, ll b, const ll p) { a %= p; if (a == 0) return 0ll; ll r = 1; for (; b > 0; a = a * a % p, b >>= 1) if (b & 1) r = r * a % p; return r; }
ll fmul(ll a, ll b, ll mod) { return ((a * b - (ll)((ll)((long double)a / mod * b + 1e-3) * mod)) % mod + mod) % mod; }
const double PI = acos(-1);
string YN(bool flag) { return (flag ? "Yes" : "No"); }
const int N=2e5+10;
ll invf[N],j[N];
void init(){
	j[0]=1;
	for(int i=1;i<=N-10;i++) j[i]=1ll*j[i-1]*i%mod;
	invf[1]=1;
	for(int i=2;i<=N-10;i++) invf[i]=1ll*(mod-mod/i)*invf[mod%i];
	for(int i=2;i<=N-10;i++) invf[i]=invf[i]*invf[i-1]%mod;
}
ll C(int n,int m){
	return 1ll*j[n]*invf[n-m]%mod*invf[m]%mod;
}
void solve(){
	int n,k;
	cin>>n>>k;
	ll ans=1;
	for(int i=2;i<n;i+=2){
		ans=(ans+C(n,i))%mod;
	}
	ans=(ans+1)%mod;
	cout<<qmi(ans,k,mod)<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    init();
    int t;
    cin>>t;
    while(t--)
    solve();
    return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
//typedef tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> os;

typedef long long ll;
#define int ll
typedef long double ld;
typedef pair<ll,int> pii;
#define log2(x) ((x==0)? 0:63 - __builtin_clzll(x))
#define pb push_back
#define deb(x) cout<<#x<<" " <<x<<"\n";
#define ms(x, y) memset(x, y, sizeof x)

const int inf=0x3f3f3f3f; const ll LLINF=0x3f3f3f3f3f3f3f3f;
inline ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}
inline ll lcm(ll a, ll b) { return a * b / gcd(a, b);}
template<typename... T> void deb2(T&&... args){
    ((cout<<args<<" "), ...);
    cout<<"\n";
}

const ll mod = 1e9+7;
struct tri{
    ll x,y,z;
    bool operator<(const tri &one)const{
        if(x==one.x) return y<one.y;
        return x<one.x;
    }//pqs are backwards
};
ll fpow(ll a, ll b){
    if (b == 0)
        return 1;
    ll res = fpow(a, b / 2)%mod;
    if (b % 2)
        return ((res * res)%mod * a)%mod;
    else
        return (res * res)%mod;
}

//brute should TLE not WA
    //assert ideas with ur slow, to find out why ur fast WA
//make sure to fully actuate your ideas before coding it up; spend more time on samples and examples
/*
    stuff you should look for
    *int overflow, array bounds
    *special cases (n=1? n=0?)
    * do smth instead of nothing and stay organized
    *write stuff down
*/
const int maxn = 2e5+10;
ll fact[maxn];
ll inv[maxn];
ll choose(int n, int k){
    if(n==0|| k==0) return 1;
    return ((fact[n] * inv[n-k])%mod* inv[k])%mod;
}

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //and is greater than xor
    //2e5 bits, 2e5 length
        //less than pow of 2
    int t; cin>>t;
    fact[0] = 1; inv[0] =1, inv[1] = 1;
    fact[1] =1;
    for(int i =2; i<maxn; i++){
        fact[i] = fact[i-1]*i;
        fact[i]%=mod;
        inv[i] = fpow(fact[i],mod-2);
    }
    while(t--){
        int n,k;
        cin>>n>>k;
        if(n==1){
            cout<<(fpow(2,k))%mod<<"\n";//any number works
            continue;
        }
        if(n%2==0){
            ll sum  =0;
            ll sum2 =0;
            for(int i =2; i<n; i+=2){
                sum+=choose(n,i);
                sum%=mod;
            }
            sum2 = sum +1; sum2%=mod;
            ll ans =1;
            for(int i =1; i<=k; i++){
                ans+=(fpow(2,(i-1)*n))%mod;//set ur col to all 1s, rem  is random > case
                ans%=mod;
            }
            for(int i =1; i<=k; i++){
                ans+=(sum*fpow(sum2,i-1))%mod;
                ans%=mod;
            }
            cout<<ans<<"\n";
        }
        else{//odd
            ll sum  =0;
            ll sum2 =0;
            for(int i =2; i<=n; i+=2){
                sum+=choose(n,i);
                sum%=mod;
            }
            sum2 = sum +choose(n,0); sum2%=mod;
            //sum is number of ways to make a k bit have even number of set bits, #bits >0
            //sum2 is num of ways to make bits have even, inc. 0
            ll ans =1;
            for(int i =1; i<=k; i++){
                ans+=(sum*fpow(sum2,i-1))%mod;
                ans%=mod;
            }

            for(int i =1; i<=k; i++){
                ans+=fpow(2,i-1);//set this col to all 1s, and then any number of rem cols to all 1s too
                ans%=mod;
            }
            cout<<ans<<"\n";
        }
    }

}

// use setprecision before not after
// don't modify map while iterating
#include<bits/stdc++.h>
#define M_PI       3.14159265358979323846
#define Speed_UP  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define     pb                push_back
#define     ff                first
#define     ss                second
#define     pii                pair<int,int>
#define sz(x)                 (int)x.size()
#define all(x)                 (x).begin(), (x).end()
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x << " " << x <<"\n";
#else
#define debug(x)
#endif

#define precise std::setprecision(20)
using namespace std;
typedef long long ll;
typedef long double ld;
inline void setIO(string );

const ll mx = 2 * (1e5) + 7;
const ll mod = 1e9 + 7;
ll n, k;
ll dp[mx];

long long powmod(long long x, long long y, long long p = mod)
{
    long long res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

ll f(ll i) {
    if(i == k) return 1;

    if(dp[i] != -1) return dp[i];

    ll ans = 0;

    if(n % 2 == 0) {
        ll temp = powmod(2, n);
        (ans += (powmod(2, n - 1) - 1) * f(i + 1)) %= mod;
        ans += pow(temp, k - i - 1);
    } else {
        (ans += (powmod(2, n - 1)) * f(i + 1)) %= mod;
        ans += f(i + 1);
    }
    debug(i)
    debug(ans)
    return dp[i] = (ans % mod);
}

int solve(){
    cin >> n >> k;

    memset(dp, -1, sizeof(dp));

    // suffix starting at i such that and of the suffix >= xor

    cout << f(0) << "\n";

    return 0;
  }

int main(){
    Speed_UP

    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("error.txt", "w", stderr);
        //freopen("output.txt", "w", stdout);
    #endif

    ll t = 1;
    cin >> t;

    for(int i = 1; i <= t; i++) {
        // cout << "Case #"<<i<<": ";
        solve();
    }
}

inline void setIO(string name="") {
    #ifndef ONLINE_JUDGE
    freopen((name+".in").c_str(), "r", stdin);
    freopen((name+".out").c_str(), "w", stdout);
    #endif
    }

#include<bits/stdc++.h>
#define int long long int
#define f(i,a,n) for(int i=a;i<=n;i++)
#define fd(i,a,n) for(int i=n;i>=a;i--)
#define pb push_back
#define mk make_pair
#define F first
#define endl "\n"
#define S second
#define all(x) x.begin(), x.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define vi vector<int>
#define vb vector<bool>
#define vvi vector< vector<int> >
#define vip vector< pair<int,int> >
#define pi pair<int,int>
#define trav(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define setBit(x) __builtin_popcount(x)
#define lb(x,num) lower_bound(all(x),num)
#define ub(x,num) upper_bound(all(x),num)
inline int GCD(int a, int b) { return b == 0 ? a : GCD(b, a % b); }
inline int LCM(int a, int b) { return a * b / GCD(a, b); }
inline int ceil(int a, int b){  return (a%b==0) ? a/b : a/b +1 ;}
const int mod = 1e9 + 7;
using namespace std;
int power(int x, int y)
{
    if(y==0)
    return 1;
    x%=mod;
    if(y%2)
    return (x*power(x*x, y/2))%mod;
    return power(x*x, y/2);
}
void solve()
{
    int n,k;
    cin>>n>>k;
    if(k==0)
    {
        cout<<"1"<<endl;
        return;
    }
    int ans;
    if(n&1)
    ans=(((power(2,n-1)+1)%mod)*((int)log2(k)+1))%mod;
    else
    ans=((power(2,n-1)%mod)*((int)log2(k)+1))%mod;
    cout<<ans<<endl;

}
signed main()
{
	fast

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

	int t=1;
	cin>>t;
	while(t--)
	{
		solve();
    }
return 0;
}

#include<bits/stdc++.h>
#define pb push_back
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define SORT(v) sort(all(v))
#define int long long
#define ff first
#define ss second
#define mod 1000000007
#define endl "\n"

using namespace std;

void oj()
{
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
}

int power(int x, int y)
{
  int sum = 1;
  while(y)
  {
    if(y&1)
      sum = (sum * x) % mod;

    x = (x * x) % mod;
    y = y / 2;
  }
  return sum;
}
void solve()
{
  int n, k;
  cin>>n>>k;

  if(k == 0)
  {
    cout<<1<<endl;
    return;
  }
  if(n % 2 == 1)
  {
    int even = power(2, n - 1);
    int ans = 1;
    for(int i = 0; i < k; i++)
      ans = (ans * even) % mod;

    for(int i = k; i >= 1; i--)
    {
      int ok = ((i - 1) * (n - 1)) % mod;
      int lol = power(2, ok);
      ans = (ans + lol) % mod;
    }

    cout<<ans<<endl;
  }
  else
  {
    int even = power(2, n - 1);
    int ans = 1;
    for(int i = 0; i < k; i++)
      ans = (ans * even) % mod;

    cout<<ans<<endl;
  }

}
signed main()
{
  oj();
  int t; cin>>t;
  while(t--)
    solve();

  return 0;
}

#include <iostream>
#include <cstdio>

using namespace std;

const int mod = 1e9+7;
const int maxn = 6e5;
typedef long long ll;
ll f[maxn];
ll n, k;

ll ksm(ll a, ll b){
    ll res = 1;
    while(b){
        if(b % 2)
            res = (res * a) % mod;
        b /= 2;
        a = (a * a) % mod;
    }
    return res % mod;
}

int main()
{
    f[0] = 1;
    for(int i = 1; i <= 500000; i++)
        f[i] = f[i-1] * 2ll % mod;
    int T;
    cin >> T;
    while(T--){
        cin >> n >> k;
        ll ans = 0;
        for(ll i = k-1; i >= 0; i--){
            if(n % 2 == 0) ans += ksm(2, n*i);
            ans %= mod;
        }
        if(n % 2 == 0) ans += ksm((f[n-1]-1)%mod, k);
        else ans += ksm((f[n-1]+1)%mod, k);
        ans %= mod;
        printf("%lld\n", ans);
    }

  //  system("pause");
    return 0;
}

/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~
--||author : codechaser||--
~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
//COMPILER SUPPORT : STD=GNU C++14 or ABOVE
#include <bits/stdc++.h>
using namespace std;
//OPTIMIZATION
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
//DEFINE STATEMENTS
#define rep2(i,k,n,a) for(llint i=k;(i<n)&&(a);i++)
#define rep3(i,k,n,a) for(llint i=k;(i>n)&&(a);i--)
#define rep0(i,k,n) rep2(i,k,n,1)
#define rep1(i,k,n) rep3(i,k,n,1)
#define br cout<<"\n"
#define yea cout<<"YES\n"
#define nah cout<<"NO\n"
#define print0(x) for(auto i:x) cout<<i<<" "; br;
#define print1(x) for(auto i:x) cout<<i.first<<" "<<i.second<<"\n"; br;
#define input0(x) for(auto &i:x) cin>>i;
#define input1(x) for(auto &i:x) cin>>i.first>>i.second;
#define input2(x,n) rep0(i,0,n) llint inp,cin>>inp,x.insert(inp);
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define eb emplace_back
#define mp make_pair
#define f first
#define s second
#define FIX cout<<fixed<<setprecision(12);
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ifn(x) if(!(x))
#define setbits(x) __builtin_popcountll(x)
#define tzerobits(x) __builtin_ctzll(x) //000001101(00) -> 2
#define lzerobits(x) __builtin_clzll(x) //(00000)110100 -> 5
#define gcd(x,y) __gcd(x,y)
#define lcm(x,y) ((x*y)/gcd(x,y))
#define fileinput freopen("input.txt","r",stdin);
#define fileoutput freopen("output.txt","w",stdout);
#define clock1 tttt=clock();
#define clock0 cout<<"\ntime taken: "<<(((double)clock())-tttt)/((double)CLOCKS_PER_SEC) <<"\n\n";
//#define a(i,j,n) a[i][j]
//#define a(i,j,n) a[i*n+j]
typedef long long llint;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int uint;
typedef vector<llint> vl;
typedef vector<vl> vvl;
typedef vector<bool> vb;
typedef pair<llint,llint> pll;
typedef pair<llint,string> pls;
typedef map<llint,llint> mll;
const uint uintMax=4294967295;          //+(1<<32) - 1
const int intMax=2147483647;            //+(1<<31) - 1
const int intMin=-2147483648;           //-(1<<31)
const ull ullMax=18446744073709551615;  //+(1<<64) - 1
const llint Max=9223372036854775807;    //+(1<<63) - 1
const llint Min=-9223372036854775808;   //-(1<<63)
////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<typename... T>
void print(T... arg);
template<typename T1, typename T2>
ostream& operator<<(ostream& cout, pair<T1,T2> p);
template<typename T>
ostream& operator<<(ostream& cout, vector<T> v);
template<typename... T>
void input(T&... arg);
template<typename T1, typename T2>
istream& operator>>(istream& cin, pair<T1,T2>& p);
template<typename T>
istream& operator>>(istream& cin, vector<T>& v);
llint power(llint n, llint exp);
void ts(vector<llint>& v, llint od);
////////////////////////////////////////////////////////////////////////////////////////////////////////////
llint power(llint n, llint exp, llint mod){
    llint res=1;
    while(exp){
        if(exp&1) res=(res*(n%mod))%mod,exp--;
        else n=((n%mod)*(n%mod))%mod,exp>>=1;
    }
    return (res%mod);
}
inline void codechaser(){
    llint n,k,mod=1000000007;
    cin>>n>>k;
    cout<<(power((power(2,n-1,mod)+(n&1))%mod,k,mod))<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    llint t=1;
    cin>>t;
    while(t--) codechaser();
    return 0;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<typename... T>
void print(T... arg){
    ((cout<<arg), ...);
}
template<typename T1, typename T2>
ostream& operator<<(ostream& cout, pair<T1,T2> p){
    cout<<p.first<<" "<<p.second;
    return cout;
}
template<typename T>
ostream& operator<<(ostream& cout, vector<T> v){
    llint cnt=0;
    for(auto& i:v) cout<<i<<((++cnt)!=v.size()?" ":"");
    return cout;
}
template<typename... T>
void input(T&... arg){
    ((cin>>arg), ...);
}
template<typename T1, typename T2>
istream& operator>>(istream& cin, pair<T1,T2>& p){
    cin>>p.first>>p.second;
    return cin;
}
template<typename T>
istream& operator>>(istream& cin, vector<T>& v){
    for(auto& i:v) cin>>i;
    return cin;
}
llint power(llint n, llint exp){
    llint res=1;
    while(exp){
        if(exp&1) res*=n,exp--;
        else n*=n,exp>>=1;
    }
    return res;
}
void ts(vector<llint>& v, llint od){
    if(!v.size()) return;
    llint n=v.size(),maximum=abs(v[0]);
    rep0(i,1,n) maximum=max(maximum,abs(v[i]));
    ifn(maximum) return;
    llint k=log10(maximum)+1;
    rep0(i,0,ceil((double)k/od)){
        vector<vector<llint>> record(power(10,od));
        rep0(j,0,n) (record[(llint)abs((llint)((v[j])%((llint)power(10,od*(i+1))))/power(10,od*i))]).pb(v[j]);
        llint counter=0;
        rep0(j,0,power(10,od)) for(auto k:record[j]) v[counter]=k,counter++;
    }
    return;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
    |---------------------------------------------------|
    |||   https://codeforces.com/profile/codechaser   |||
    |||   https://www.codechef.com/users/codechaser   |||
    |||        https://github.com/code-chaser         |||
    |---------------------------------------------------|
*/
////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// === Debug macro starts here ===

int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
    os<<"[";
    for(auto& x:v){os<<x<<", ";}
    return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
    return os<<"{"<<p.first<<", "<<p.second<<"}";
}

// === Debug macro ends here ===

using ll = long long;
const ll mod = 1000000007LL;
ll exp(ll x, ll y) {
    ll ans = 1;
    while(y > 0) {
        if(y%2 == 1) ans = (ans*x) % mod;
        x = (x*x) % mod;
        y/=2;
    }
    return ans;
}
int main() {
    int t;
    cin >> t;
    while(t--) {
        ll n, k;
        cin >> n >> k;
        vector<ll> factorial(n+1);
        factorial[0] = 1ll;
        for(ll i = 1; i <= n; i++) {
            factorial[i] = (factorial[i-1] * i) % mod;
        }
        ll ans = 0;
        if(k == 0 ) ans = 1;
        else if(n % 2 == 0) {
            ll s = 0;
            for(ll i = 2; i <= n; i+=2) {
                s += (factorial[n] * exp((factorial[i]*factorial[n-i]) %mod, mod-2)) % mod;
            }
            ans = exp(s, k);
            for(ll i = k - 1,j = 0; j < k; j++, i--) {
                ans += (exp(2LL, i) * exp(s, j)) % mod;
            }

        }
        else {
            for(ll i = 1; i <= n; i+=2) {
                ans += (factorial[n] * exp((factorial[i]*factorial[n-i]) %mod, mod-2)) % mod;
            }
            ans++;
            ans = exp(ans, k);

        }
        cout << ans << '\n';
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define mod 1000000007

typedef long long ll;

inline ll qpow(ll x, ll y) {
	ll re = 1;
	while (y) {
		if (y & 1) (re *= x) %= mod;
		y >>= 1;
		(x *= x) %= mod;
	}
	return re;
}

inline ll inv(ll x) {
	return qpow(x, mod - 2);
}

int main() {
	int t;
	cin >> t ;
	while (t -- ) {
		ll n, k;
		scanf("%lld%lld", &n, &k);
		if (n & 1) {
			printf("%lld\n", qpow((qpow(2, n - 1) + 1) % mod, k));
		}
		else {
			ll mdl1 = (qpow(2, n - 1) + mod - 1) % mod, mid1 = inv(mdl1), mdl2 = qpow(inv(2), n), mid2 = qpow(2, n * k % mod);
			// puts("Fuck");
			// cout << mdl1 << ' ' << mdl2 << endl ;
			// puts("Fuck");
			// cout << mid1 << ' ' << mid2 << endl ;
			// puts("Fuck");
			// cout << inv(mdl2) << endl ;
			ll ans = 0;
			for (int i = 1; i <= k; i ++ ) {
				mid1 = mid1 * mdl1 % mod, mid2 = mid2 * mdl2 % mod;
				// cout << mid1 << ' ' << mid2 << endl ;
				(ans += mid1 * mid2 % mod) %= mod;
			}
			// puts("Fuck");
			// cout << ans << endl ;
			// 相等
			(ans += qpow(mdl1, k)) %= mod;
			printf("%lld\n", ans);
		}
	}
	return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define berak break
#define faset()                     \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);                    \
  cout.tie(NULL);
#define fr first
#define sc second
#define spc 200005
#define pairll pair<ll, ll>
#define pairlll pair<ll, pair<ll, ll>>
#define mp make_pair
#define pb push_back
using namespace std;

ll t, n, k, conss = 1000000007, arr[spc], ans = 0, tmp;

ll multi (ll a, ll b){
  return ((a%conss)*(b%conss))%conss;
}

ll add (ll a, ll b){
  return ((a%conss)+b%conss)%conss;
}

ll pangkat (ll a, ll b){
  if (b == 0) return 1;
  if (b == 1) return a;
  ll tmp = pangkat (a,b/2);
  if (b%2) return multi (tmp,multi(tmp,a));
  return multi (tmp,tmp);
}

void solve(){
    cin >> n >> k;

    ll sum = pangkat(2,n-1);
    ll ans = 0;

    if(n & 1){
        ans = pangkat(sum + 1, k);
    } else{
        ans = pangkat(sum-1, k);
        for(int i = 1; i <= k; i++){
            ans = add(ans, multi(pangkat(sum-1, i - 1), pangkat(1LL<<n, k - i)));
        }
    }

    cout << ans << '\n';
}

void input()
{
}

int main()
{
  faset();
  cin >> t;
  while (t--)
  {
    input();
    solve();
  }
}

#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
const ll MOD = 1e9+7;
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL)
ll P(ll n , ll k){
    if(k==1) return n;
    if(k==0) return 1;
    ll T = P(n,k/2);
    return T * T % MOD * P(n,k%2) % MOD;
}
int main(){
    faster;
    ll test;cin>>test;
    while(test--){
        ll n,k;cin>>n>>k;
        if(n%2)
            cout << P(P(2,n-1) + 1 , k) << endl;
        else{
            ll ans = 1;
            for(ll i=1 ; i<=k ; i++)
                ans += P(2,n*(i-1)) * P(P(2,n-1) - 1 , k-i);
            cout << ans << endl;
        }
    }
    return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
using namespace std;
ll mod = (1 ? 1e9 + 7 : 998244353);
const int N = 2e5 + 5;
const int M = 5e5 + 5;
const int inf = 2e9;
const ll linf = 1e18;
ll g(ll a){a=(a+mod)%mod; return a;}
ll add(ll a,ll b){a+=b;return a>=mod?a-mod:a;}
ll sub(ll a, ll b){a+=mod-b;return a>=mod?a-mod:a;}
ll mul(ll a,ll b){return a*b%mod;}
ll exp(ll x,ll k){ll ans=1;for(;k;k>>=1,x=mul(x,x))if(k&1)ans=mul(ans,x);return ans;}
ll in(ll x){return exp(x,mod-2);}
ll divi(ll a,ll b){return mul(a,in(b));}
ll fak[N],inv[N], pref[N];
void calc(int n)
{
    fak[0]=1;
    for(int i=1;i<=n;i++) fak[i]=mul(fak[i-1],i);
    inv[n-1]=in(fak[n-1]);
    for(int i=n-2;~i;i--)inv[i]=mul(inv[i+1],i+1);
}
ll bc(int a, int b)
{
    if(a<b)return 0;
    if(a==b||b==0)return 1;
    return mul(fak[a],mul(inv[a-b],inv[b]));
}
void Evlos(){
    int n, k;
    cin >> n >> k;
    if (n % 2 == 1){
        ll ans = 1;
        for (int i = 0; i < n; i += 2){
            ans = add(ans, bc(n, i));
        }
        ans = exp(ans, k);
        cout << ans << en;
        return;
    }
    ll v = 0;
    for (int i = 0; i < n; i += 2){
        v = add(v, bc(n, i));
    }
    ll ans = 0;
    for (int i = 0; i <= k; i++){
        ll left = exp(v, i);
        ll right = exp(2, mul(n, max(0, k - i - 1)));
        ans = add(ans, mul(left, right));
    }
    cout << ans << en;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cerr.tie(0);
    calc(N - 1);
    int tt = 1;
    cin >> tt;
    while (tt--) Evlos();
    return 0;
}

#include<iostream>
#include<cstring>
#include<algorithm>
#define int long long
using namespace std;

const int N = 200010, mod = 1e9 + 7;
int fact[N],infact[N];

int qmi(int x,int p)
{
	int res=1;
	while(p)
	{
		if(p&1)res=(res*x)%mod;
		x=x*x%mod;
		p>>=1;
	}
	return res;
}

signed main()
{
	int T;
	fact[0] = infact[0] = 1;
    for (int i = 1; i < N; i ++ )
    {
        fact[i] = fact[i - 1] * i % mod;
        infact[i] =infact[i - 1] * qmi(i, mod - 2) % mod;
    }
    cin>>T;
	while(T--)
	{
		int n,k;
		cin>>n>>k;
		int ans=0;
		if(n&1)
		{
			ans=qmi(2,n);
			ans-=2;
			ans/=2;
			ans=qmi(2,n)-ans;
			ans=qmi(ans,k);
		}
		else
		{
			int x=n/2;
			ans=fact[x]*fact[x]*infact[n]%mod;
			ans=qmi(ans,k);
		}
		cout<<ans<<endl;
	}
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector < long long > vll;
typedef vector < vector<int> > vvi;
typedef vector < vector<long long> > vvll;
typedef pair < long long, long long > pll;
typedef pair < int, int > pii;
typedef vector < int > vi;
#define deb(x) cout << #x << " : " << x << endl
#define deb2(x , y) cout << #x << " : " << x << " , "<< #y << " : " << y << endl
#define debv(x) for(auto i=x.begin();i!=x.end();i++) cout<<*i<<' ';cout<<endl
#define debvv(x) for(auto i=x.begin();i!=x.end();i++){for(auto j=(*i).begin();j!=(*i).end();j++) cout<<*j<<' '; cout<<endl;}cout<<endl
#define debp(x) for(auto i=x.begin();i!=x.end();i++) cout<<i->first<<':'<<i->second<<' ';cout<<endl
#define debpp(x) for(auto i=x.begin();i!=x.end();i++) cout<<i->first<<' '<<i->second.first<<' '<<i->second.second<<' '<<endl;cout<<endl
#define debmap(x) for(auto i=x.begin();i!=x.end();i++) cout<<i->first.first<<' '<<i->first.second<<' '<<i->second<<' '<<endl;cout<<endl
#define rsz(x,n) x.clear(); x.resize(n)
#define rrsz(x,a,n) x.clear(); x.resize(n,a)
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,a,n) for(int i = a; i < n; i++)
//#define wt while(true)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define endl '\n'
#define csl ios_base::sync_with_stdio(false); cin.tie(NULL)
//#define s(n) cin >> n
const ll INF = 1e9+7,mod=1e9+7;

vll fact,invf;

ll powmod(ll a, ll b) {
    ll res = 1;
    a %= mod;
    for (; b; b >>= 1) {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}

void build(int n) {
    fact = vector<ll>(n+1, 1);
    invf = vector<ll>(n+1, 1);
    for (int i = 2; i <= n; i++)
        fact[i] = fact[i-1] * i % mod;
    invf[n] = powmod(fact[n], mod-2);
    for (int i = n-1; i >= 2; i--)
        invf[i] = invf[i+1] * (i+1) % mod;
}

ll nChoosek(int n, int k) {
    if (n < k)
        return 0;
    return fact[n] * invf[k] % mod * invf[n-k] % mod;
}

void solve(){
    int n,k;
    cin>>n>>k;
    build(n);
    ll tot=powmod(1LL<<k,n);
    ll ones=0;
    for(int i=0;i<n;i++){
        if(i%2){
            ones+=nChoosek(n,i);
            ones%=mod;
        }
    }
    ll twos=0,threes=0;
    for(int i=0;i<k;i++){
        twos+=powmod(1LL<<i,n);
        twos%=mod;
        threes+=(1LL<<(k-i-1));
        threes%=mod;
    }
    twos%=mod;
    twos*=threes;
    twos%=mod;
    ll ri=(ones*twos)%mod;
    ll ans =tot+mod;
    ans-=ri;
    ans%=mod;
    cout<<ans<<endl;
}

int main() {
    csl;
    int testcase=1;
    cout.precision(10);
    cin>>testcase;
    for (int i = 0; i < testcase; i++) {
        solve();
    }
    return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
using namespace std;
ll mod = (1 ? 1e9 + 7 : 998244353);
const int N = 3e5 + 5;
const int M = 5e5 + 5;
const int inf = 2e9;
const ll linf = 1e18;
ll g(ll a){a=(a+mod)%mod; return a;}
ll add(ll a,ll b){a+=b;return a>=mod?a-mod:a;}
ll sub(ll a, ll b){a+=mod-b;return a>=mod?a-mod:a;}
ll mul(ll a,ll b){return a*b%mod;}
ll exp(ll a, ll b){
    ll ans = 1;
    while (b > 0){
        if (b & 1){
            ans = (ans * a) % mod;
        }
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}
ll in(ll x){return exp(x,mod-2);}
ll divi(ll a,ll b){return mul(a,in(b));}
ll fak[N],inv[N];
void calc(int n)
{
    fak[0]=1;
    for(int i=1;i<=n;i++) fak[i]=mul(fak[i-1],i);
    inv[n-1]=in(fak[n-1]);
    for(int i=n-2;~i;i--)inv[i]=mul(inv[i+1],i+1);
}
ll bc(int a, int b)
{
    if(a<b)return 0;
    if(a==b||b==0)return 1;
    return mul(fak[a],mul(inv[a-b],inv[b]));
}
void Evlos(){
    int n, k;
    cin >> n >> k;
    if (n % 2 == 1){
        ll ans = 1;
        for (int i = 0; i < n; i += 2){
            ans = (ans + bc(n, i)) % mod;
        }
        ans = exp(ans, k);
        cout << ans << en;
        return;
    }
    ll v = 0;
    for (int i = 0; i < n; i += 2){
        v = (v + bc(n, i)) % mod;
    }
    ll ans = 0;
    for (int i = 0; i < k; i++){
        ll left = exp(v, k - i - 1);
        ll right = exp(2, n * i);
        ans = (ans + (left * right) % mod) % mod;
    }
    ans = (ans + exp(v, k)) % mod;
    cout << ans << en;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cerr.tie(0);
    calc(N - 1);
    int tt = 1;
    cin >> tt;
    while (tt--) Evlos();
    return 0;
}

#include <iostream>
#include <map>

// 2^k = 1<<k

using namespace std;

const long long mod = 1000000007;

long long pow2(long long n)
{
    n %= 500000003;
    long long result = 1, t = 2;
    while(n != 0)
    {
        if(n & 1)
        {
            result *= t;
            result %= mod;
        }
        t *= t;
        t %= mod;
        n >>= 1;
    }
    return result;
}

long long f(long long n, long long k)
{
    long long result = 1;
    int i = 0;

    if (n & 1)
    {
        for(i; i < k; ++i){
            result *= 1 + pow2(n - 1);
            result %= mod;
        }
    }
    else
    {
        for(i; i < k; ++i){
            result *= pow2(n - 1) - 1;
            result += pow2(n * (k - 1));
            result %= mod;
        }
    }

    return result;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int t;
    long long n, k;
    cin >> t;
    while (t--)
    {
        cin >> n >> k;
        cout << f(n, k) << "\n";
    }
}

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

const ll m = 1000000007;

ll mypow(ll a,ll b){
    if(b == 0)
        return 1;
    ll x = mypow(a,b/2);
    if(b%2 == 0)
        return x*x%m;
    return x*x%m*a%m;
}

ll f(ll k,ll i,ll v){
    if(i == -1)
        return 1;
    return (mypow(2,i*k)+v*f(k,i-1,v)%m)%m;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--){
        int n,k;
        cin >> n >> k;
        if(n%2 == 1){
            ll v = (mypow(2,n-1)+1)%m;
            ll q = mypow(v,k);
            cout << q << "\n";
        }
        else{
            ll v = (mypow(2,n-1)-1+m)%m;
            cout << f(k,k-1,v) << "\n";
        }
    }
    return 0;
}

#include <iostream>
#include <cstring>
#include <cmath>
#include <bitset>
#include <queue>
#include <vector>
#include <cstdio>
#include <set>
#include <stack>
#include <sstream>
#include <cstring>
#include <algorithm>
#include <map>
#define rep(i, a, b) for (long long i= a; i <= b; i++)
#define reps(i, a, b) for (long long i = a; i >= b; i--)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
#define ls(node) tree[node].ls
#define rs(node) tree[node].rs
#define l(node) tree[node].l
#define r(node) tree[node].r
#define val(node) tree[node].val
#define sum(node) tree[node].sum
#define lazy(node) tree[node].lazy
#define lazy1(node) tree[node].lazy1
#define lazy2(node) tree[node].lazy2
#define tr(node) tree[node]
//#pragma GCC optimize(2)
using namespace std;
const int N=1e6+7;
const int M=50;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
typedef long long ll;
#define Rep(i,a,b)for(ll i=a;i<=b;i++)
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}
ll power(ll a,ll b)
{
    ll ans=1;
    while(b){
        if(b&1)ans=ans*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ans%mod;
}
int main()
{
    int t;
    t=read();
    while(t--){
       int n,k;
       n=read(),k=read();
       if(k==0){
            puts("1");
            continue;
       }
       ll a=power(2,k)-1;
       if(n&1){
            ll b=n/2+1;
            b=power(2,n-1);
            ll ans=a+power(b,k);
            printf("%lld\n",ans%mod);
       }else{
            ll b=n/2;
            b=power(2,n-1)-1;
            ll ans=a+power(b,k);
            printf("%lld\n",ans%mod);
       }
    }
    return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
using namespace std;
ll mod = (1 ? 1e9 + 7 : 998244353);
const int N = 3e5 + 5;
const int M = 5e5 + 5;
const int inf = 2e9;
const ll linf = 1e18;
ll g(ll a){a=(a+mod)%mod; return a;}
ll add(ll a,ll b){a+=b;return a>=mod?a-mod:a;}
ll sub(ll a, ll b){a+=mod-b;return a>=mod?a-mod:a;}
ll mul(ll a,ll b){return a*b%mod;}
ll exp(ll x,ll k){ll ans=1;for(;k;k>>=1,x=mul(x,x))if(k&1)ans=mul(ans,x);return ans;}
ll in(ll x){return exp(x,mod-2);}
ll divi(ll a,ll b){return mul(a,in(b));}
ll fak[N],inv[N];
void calc(int n)
{
    fak[0]=1;
    for(int i=1;i<=n;i++) fak[i]=mul(fak[i-1],i);
    inv[n-1]=in(fak[n-1]);
    for(int i=n-2;~i;i--)inv[i]=mul(inv[i+1],i+1);
}
ll bc(int a, int b)
{
    if(a<b)return 0;
    if(a==b||b==0)return 1;
    return mul(fak[a],mul(inv[a-b],inv[b]));
}
void Evlos(){
    int n, k;
    cin >> n >> k;
    if (n % 2 == 1){
        ll ans = 1;
        for (int i = 0; i < n; i += 2){
            ans = add(ans, bc(n, i));
        }
        ans = exp(ans, k);
        cout << ans << en;
        return;
    }
    ll v = 0;
    for (int i = 0; i < n; i += 2){
        v = add(v, bc(n, i));
    }
    ll ans = 0;
    for (int i = 0; i < k; i++){
        ll left = exp(v, k - i - 1);
        ll right = exp(2, mul(n, i));
        ans = add(ans, mul(left, right));
    }
    ans = add(ans, exp(v, k));
    cout << ans << en;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cerr.tie(0);
    calc(N - 1);
    int tt = 1;
    cin >> tt;
    while (tt--) Evlos();
    return 0;
}

#include <iostream>
#include <fstream>
#include <vector>
#include <utility>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <climits>

using namespace std;
using ll = long long;
using str = string;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vstr = vector<string>;
using pii = pair<int, int>;
using vpii = vector<pii>;

#define sz(x) (int)(x.size())
#define rsz resize
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define eb emplace_back

#define lb lower_bound
#define ub upper_bound

// for loops
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define F0R(i, b) FOR(i, 0, b)
#define F1R(i, b) FOR(i, 1, b)
#define F0R2(i, j, a, b) F0R(i, a) F0R(j, b)
#define RFOR(i, a, b) for (int i = a - 1; i >= b; i--)
#define RF0R(i, a) RFOR(i, a, 0)

#define MOD (ll)(1e9 + 7)

#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

int t;

ll exp(ll b, ll e) {
	if (e == 0) return 1;
	ll val = exp(b, e / 2);
	val *= val;
	val %= MOD;
	if (e % 2) val *= b;
	return val % MOD;
}

int main() {
	cin >> t;
	while (t--) {
		int n, k;
		cin >> n >> k;
		n--;
		ll val = 1;
		ll tmp = 1;
		F0R(i, n) {
			val *= n - i;
			val %= MOD;
			val *= exp(i + 1, MOD - 1);
			val %= MOD;
			if (i % 2) {
				tmp += val;
				tmp %= MOD;
			}
		}
		val = tmp;
		ll ans = 1;
		F0R(i, k) {
			ans *= val;
			ans %= MOD;
		}
		if (n % 2 == 0) ans += exp(2, k);
		else {
			F0R(i, k) {
				ans += exp(exp(2, i), n);
				ans %= MOD;
			}
		}
		cout << ans % MOD << '\n';
	}
}

#include <bits/stdc++.h>
#define int long long
#define dd double
#define sc(x) cout<<#x<<":"<<x<<endl;
#define hh cout<<endl;
using namespace std;
const int N=1e5+5;
const int mod = 1e9+7;
int n,k;
//int a[N];
int pow(int a,int b)
{
	int ans=1;
	a=a%mod;
	while(b)
	{
		if(b&1) ans=(ans*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return ans%mod;
}
void solve()
{
	scanf("%lld%lld",&n,&k);
	if(n&1)
	{
		int temp = pow(2,n-1);
		temp = (temp+1)%mod;
		int ans = pow(temp,k);
		cout<<ans<<endl;
	}
	else
	{
		int temp = pow(2,n-1);
		temp = (temp-1+mod)%mod;
		int ans = pow(temp,k);
		for(int i=1;i<=k;i++)
		{
			int temp2 = pow(temp,i-1);
			int temp3 = pow(2,(k-i)*n);
			ans = (ans + (temp3*temp2)%mod)%mod;
		}
		cout<<ans<<endl;
	}
	/*
	*/
}
signed main()
{
	int T=1;
	cin>>T;
	for(int index=1;index<=T;index++)
	{
		solve();
	}
	return 0;
}

//Author:Happy Dog
#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define MOD 1000000007
int T,n,m,ans,w;
ll ksm(ll m, ll k)
{
    ll res = 1 % MOD;
    while (k)
    {
        if (k&1) res = res * m % MOD;
        m = m * m % MOD;
        k >>= 1;
    }
    return res%MOD;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        cin>>n>>m;//С�ڵ��� 2^m
        ans=0;
        if(n%2==1) //����
		 printf("%d\n",ksm((ksm(2,n-1)+1)%MOD,m));
        else
        {
            ans=ksm((ksm(2,n-1)%MOD)-1,m)%MOD;
            for(int i=1; i<=m;i++)
                ans=(ans+1ll*ksm(w-1,i-1)*ksm(w*2,m-i))%MOD;
            printf("%d\n",ans);
        }
    }
}

#include<bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9+7;

ll TEMP;
ll power(ll x, ll y, ll p)
{
	if(y == 0) return 1;
    ll res = 1;
    x = x % p;
    if (x == 0) return 0;

    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

void setTEMP(ll n){
	TEMP = power(2, n-1, mod);
	TEMP += n%2;
	TEMP %= mod;
}

void func(ll n, ll k){
	if(k == 0){
		cout<<1<<endl;
		return;
	}
	vector<vector<ll>> dp(k+1, vector<ll>(2, 1));
	setTEMP(n);
	ll t = 1;
	ll x = 2;
	for(int i=1; i<=k; i++){

		if(n % 2 == 0){
			//current bit is set
			dp[i][1] = power(t-1, n, mod);
			t = t * x;
			//current bit is not set
			dp[i][0] = dp[i-1][0] + dp[i-1][1];
			dp[i][0] %= mod;
			dp[i][0] *= (TEMP-1)%mod;
			dp[i][0] %= mod;
		}
		else{
			dp[i][0] = dp[i-1][0];
			dp[i][0] %= mod;
			dp[i][0] *= (TEMP)%mod;
			dp[i][0] %= mod;
		}
	}
	if(n % 2 == 0){
		cout<<(dp[k][0] + dp[k][1])%mod<<endl;
	}
	else cout<<dp[k][0]<<endl;;
}

int main(){
	//fast;
	ll t=1;
	cin>>t;
	for(ll q=1; q<=t; q++){
		ll n, k;
		cin>>n>>k;
		func(n, k);
	}
	return 0;
}

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#define int long long
using namespace std;
signed gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
signed main() {
	int a, b, c, op = 1000000007, n, m, yap, x, d, t, p = 31, r, k, e, v, y, ans, l;
	cin >> yap;
	while (yap > 0) {
		yap--;
		cin >> n >> k;
		vector <int> q(n);
		q[0] = 1;
		for (int i = 1; i < n; i++) q[i] = 2*q[i - 1] % op;
		vector <int> dp(k + 1);
		dp[0] = 1;
		for (int i = 1; i <= k; i++) {
			dp[i] = dp[i - 1] * q[n-1] % op;
			if (n % 2 == 1) dp[i] += dp[i - 1];
			dp[i] %= op;
		}
		cout << dp[k] << endl;
	}
	return 0;
}

//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")
#include "bits/stdc++.h"

using namespace std;

//TYPEDEFS
typedef long long int ll;
typedef unsigned long long int uli;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<ll,ll>> vpll;
typedef set<int> si;
typedef set<ll> sll;
//DEFINES
#define endl "\n"
#define PI 3.1415926535897932384
#define fastIO  std::ios::sync_with_stdio(false);cin.tie(NULL)
#define mod 1000000007
#define mod1 1000000009
#define mod2 998244353
#define gcd __gcd
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define sz size()
#define rep(i, n) for (ll (i) = 0; (i) < (n); (i)++)
#define REP(i, k, n) for (ll (i) = (k); (i) < (n); (i)++)
#define repr(i, k, n) for (ll (i) = (k); (i) >= (n); (i)--)
#define collect(a) for(ll (i)=0; (i)<(sz(a)); (i)++){cin>>a[(i)];}
#define pb push_back
#define popb pop_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define popf pop_front()
#define be begin()
#define en end()
#define all(x) x.be,x.en
#define rall(x) x.rbegin(),x.rend()
#define sortinc(x) sort(all(x))
#define sortdec(x) sort(rall(x))
#define tr(it, a) for(auto (it) = a.begin(); (it) != a.end(); (it)++)
#define p0(a) cout << (a) << " "
#define p1(a) cout << (a) << endl
#define p2(a, b) cout << (a) << " " << (b) << endl
#define p3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl
#define p4(a, b, c, d) cout << (a) << " " << (b) << " " << (c) << " " << (d) << endl
#define cend cout<<endl
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define r0 return 0
#define F first
#define S second
#define IMIN INT_MIN
#define IMAX INT_MAX
#define LLMIN LLONG_MIN
#define LLMAX LLONG_MAX
#define debug(x) cout << #x <<" "; _print(x); cout << endl;

void _print(ll t) {cout<< t;}
void _print(int t) {cout<< t;}
void _print(string t) {cout<< t;}
void _print(char t) {cout<< t;}
void _print(ld t) {cout<< t;}
void _print(double t) {cout<< t;}
void _print(uli t) {cout<< t;}
template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cout<< "{"; _print(p.F); cout<< ","; _print(p.S); cout<< "}";}
template <class T> void _print(vector <T> v) {cout<< "[ "; for (T i : v) {_print(i); cout << " ";} cout<< "]";}
template <class T> void _print(set <T> v) {cout<< "[ "; for (T i : v) {_print(i); cout<< " ";} cout<< "]";}
template <class T> void _print(multiset <T> v) {cout<< "[ "; for (T i : v) {_print(i); cout<< " ";} cout<< "]";}
template <class T, class V> void _print(map <T, V> v) {cout<< "[ "; for (auto i : v) {_print(i); cout<< " ";} cout<< "]";}
template<typename... T>
void see(T&... args) { ((cin >> args), ...);}
template<typename... T>
void put(T&&... args) { ((cout << args << " "), ...);}
template<typename... T>
void putl(T&&... args) { ((cout << args << " "), ...); cout<<'\n';}
template <typename T>
void print(vector<T> v){
    for (auto i : v){
        cout << i << " ";
    }
    cout << endl;
}
// (n*m)%mod
inline ll modpro(ll n, ll m, ll p = mod)
{
    return (((n % p) * (m % p)) % p + p) % p;
}
// x^y
uli powe(ll x, ll y)
{
    uli res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x * x;
    }
    return res;
}
// (x^y)%mod
ll modpow(ll x, ll y, ll p = mod)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = modpro(res, x, p);
        y = y >> 1;
        x = modpro(x, x, p);
    }
    return res;
}
ll n,k;
ll dp[200005][2];
ll rec(int i, bool tight){
    if(i==k)return 1;
    if(dp[i][tight]!=-1)return dp[i][tight];
    ll ans=0;
    if(tight){
        if(n%2==0){
            (ans+=modpro(rec(i+1,0),(powe(2,n-1)-1)))%=mod;
        }else{
            (ans+=modpro(rec(i+1,0),powe(2,n-1)))%=mod;
        }
        (ans+=rec(i+1,1))%=mod;
    }else{
        (ans+=modpro(rec(i+1,0),powe(2,n)))%=mod;
    }
    return dp[i][tight]=ans;
}
int main(){
    fastIO;

    int t=1;
    cin>>t;
    while(t--){
        cin>>n>>k;
        memset(dp,-1,sizeof dp);
        ll ans=rec(0,1);
        putl(ans);
    }
    return 0;
}

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

#define take(A,N) for(ll I=0;I<N;I++) cin>>A[I]
#define show(A,N) for(ll I=0;I<N;I++) cout<<A[I]<<" "; cout<<'\n';
#define bruh ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ld long double
#define ll long long

ll M = int(1e9)+7;
ll M2 = 998244353;

ll apowb(ll a, ll b, ll m)
{
	ll ans = 1;
	while(b)
	{
		if(b&1) ans = (ans*a)%m;
		a = (a*a)%m; // check if it needs to be a = ((a%m)*(a%m))%m;
		b>>=1;
	}
	return ans;
}

int main()
{
	bruh;
	ll T, TT, i, j;
	cin>>T; for(TT=1;TT<=T;++TT)
	{
		ll n, k; cin>>n>>k;
		if(k==0)
		{
			cout<<"1\n";
			continue;
		}
		if(k==1)
		{
			cout<<apowb(2,k,M)<<'\n';
			continue;
		}
		if(n&1)
		{
			cout<<(((apowb(2,n-1,M)+1)%M)*k)%M<<'\n';
			continue;
		}
		cout<<(((apowb(2,n-1,M))%M)*k)%M<<'\n';
	}
	return 0;
}
// zenith

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fo(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define pvec(v)  {for(auto it:v) cout<<it<<" ";cout<<"\n";}
#define pmat(v,x,y) {fo(i,x){fo(j,y) cout<<v[i][j]<<" ";nl;}}
#define ppair(v){for(auto p:v) pp(p);nl;}
#define pl(i) cout<<i<<"\n"
#define ps(i) cout<<i<<" "
#define nl pl("")
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define deb3(x, y ,z) cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define all(v) v.begin(),v.end()
#define rall(x) x.rbegin() , x.rend()
#define um unordered_map
#define mod 1'000'000'007
#define mem(x,val) memset(x,val,sizeof(x))
#define pp(i) cout<<"("<<i.first<<","<<i.second<<")    "
typedef pair<int,int> pii;typedef vector<int> vi;typedef vector<pii> vpii;typedef vector<vector<int>> vvi;
template <typename T>using vv = vector<vector<T>>;
void scar(int *arr,int n){fo(i,n) cin>>arr[i];}

void q1(){
  int n;cin>>n;int sum=0,a;int mx=INT_MIN;
  fo(i,n){
    cin>>a;
    mx = max(mx,a);sum+=a;
  }
  double ans = (double)(sum-mx)/(double)(n-1) + (double)(mx);
  cout<<fixed<<setprecision(7)<<ans<<"\n";

}
void q2(){
  // int n,k;cin>>n>>k;
  // int arr[n];scar(arr,n);
  // if(n==1){
  //   pl("Yes");return;
  // }
  // int prev = 2,cnt=0;
  // rep(i,0,n-1){
  //   if(arr[i]-arr[i+1]<0){
  //     if(prev==-1){continue;}
  //     else{
  //       cnt++;prev=-1;
  //     }
  //   }else if(arr[i]-arr[i+1]==0){
  //   }
  //   else{
  //     if(prev==1){continue;}
  //     else{
  //       cnt++;prev=1;
  //     }
  //   }
  // }
  // // deb(cnt);
  // if((k)>=(cnt)){pl("Yes");}
  // else pl("No");
  int n, k;
  cin >> n >> k;
  int ret = 1;
  int arr[n];
  vi temp(n);
  // lfasld falsdkf alsndkf
  fo(i,n)
  {
    int x;cin>>x;
    arr[i] = temp[i] = x;
  }
  /// flaksd flasldf nkalsd
  um<int, int> umap;
  sort(all(temp));
  // lfkasdl fnalsdknflasndkf
  for(int i=1;i<n;i++) { umap[arr[i - 1]] = arr[i]; }
  for(int i=1;i<n;i++){
    if (temp[i - 1] == arr[n - 1]) {
      ret++;
    }
    else if (umap[temp[i - 1]] != temp[i])
    {
      ret++;
    }
  }
  (ret<=k)?pl("Yes") : pl("No");
}
void q3(){
  int n,k;cin>>n>>k;
  int ans = 1;
  int y = 1,prev=1;
  for(int i=2;i<n;i+=2){
    prev = ((prev*(n-(i-2))*(n-i+1))/(i)*(i-1))%mod;
    y+=prev;
  }
  // deb(y);
  for(int x = 0;x<=k-1;x++){
    ans = (ans*y)%mod;
    ans = (ans+mod+(1<<x))%mod;
  }
  pl(ans);
}
void q4(){

}
void q5(){

}

//#--------solve fn-------//
void solve(){
  q3();
}
signed main(){
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  srand(chrono::high_resolution_clock::now().time_since_epoch().count());
  int t=1;
  cin>>t;
  while (t--){
    solve();
  }
}

#include<bits/stdc++.h>
#define messi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define lld long long int
#define ulld unsigned long long
#define vll vector<lld>
#define pll pair<lld,lld>
#define mll map<lld,lld>
#define sll set<lld>
#define pb push_back
#define ss second
#define ff first
#define mp make_pair
#define MOD 1000000007 //998244353
#define answer(x) cout<<endl<<"answer : "<<x<<endl<<endl;
#define out(x) cout<<x<<endl;
#define MAXN 500005
#define lld_max 5000000000000000000
using namespace std;
lld power(lld x, lld y)
{
    lld res = 1;
    x = x % MOD; y = y%MOD;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % MOD;
        y = y >> 1;
        x = (x * x) % MOD;
    }
    return res%MOD;
}
int main() {messi lld t=1;cin>>t;
    while(t--)
    {
        lld n=0,m=0,k=0,i=0,j=0,p=0,q=0,x=0,y=0,z=0,cnt=0,ans=0,l=0,r=0,cur=0,mid=0,lo=0,hi=0,lp=0,lamps=0,ft=0,jt=0;string s,stM;bool flag=false;
        cin>>n>>k;
        x = power(2,(n*k)%MOD);
        y = power(2,n-1) - 1; if(n%2==0) y++;
        for(i=0;i<k;i++){
            z = (z%MOD + (power(2,(n*i)%MOD))%MOD)%MOD;
        }
        //cout<<"x: "<<x<<" , y: "<<y<<" , z: "<<z<<endl;
        ans = (x%MOD - (y%MOD * z%MOD)%MOD)%MOD; if(ans<0) ans+=MOD;
        out(ans);
    }
	return 0;
}
/*  CODED BY:-
 ________________________________________
|            __        __                |
|  /\   /\  |__)  /\  |  \ |__| \ /  /\  |
| /~~\ /~~\ |  \ /~~\ |__/ |  |  |  /~~\ |
|________________________________________|

*/

#include <bits/stdc++.h>
using namespace std;
const int mod=1000000007;
int tc,n,k;
long long ans,cur,same,win,pow2[200003],pow22[200003],nCr[200003];
int main()
{
    int i;
    scanf("%d",&tc);
    while(tc--){
        scanf("%d %d",&n,&k);
        pow22[0]=pow2[0]=nCr[0]=1;
        same=1;
        for(i=1;i<=n;i++){
            pow2[i]=(pow2[i-1]*2)%mod;
            nCr[i]=(nCr[i-1]*(n+1-i)/i)%mod;
            if(i%2==0) same=(same+nCr[i])%mod;
        }
        if(n&1) same++;
        else same--,win++;

        cur=1; ans=0;

        for(i=1;i<=k;i++){
            pow22[i]=(pow22[i-1]*pow2[n])%mod;
        }
        for(i=1;i<=k;i++){
            ans=(ans+win*cur*pow22[k-i])%mod;
            cur=(cur*same)%mod;
        }
        ans=(ans+cur)%mod;
        printf("%lld\n",ans);
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long

#ifndef ONLINE_JUDGE
#define debug(x) cout<<#x<<" ";_print(x); cout<<"\n";
#else
#define debug(x)
#endif

void _print(int a) {cout<<a;}
void _print(ll a) {cout<<a;}
void _print(char a) {cout<<a;}
void _print(string s) {cout<<s;}
void _print(bool s) {cout<<s;}
template <class T> void _print(vector<T> v) {cout<<"[ "; for(auto i: v) {_print(i); cout<<" ";} cout<<"]";}
template <class T> void _print(set<T> s) {cout<<"[ ";for(auto i: s) {_print(i);cout<<" ";}cout<<"]";}

template <class T>
void _print(vector<vector<T>> v) {
    for(ll i=0;i<v.size();i++) {
        for(ll j=0;j<v[i].size();j++) {
            _print(v[i][j]);
            cout<<" ";
        }
        cout<<"\n";
    }
}

const int MAX_N = 1e5 + 1;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

template<class T>
void output_vector(vector<T>& v) {
    for(ll i=0;i<v.size()-1;i++) {
        cout<<v[i]<<" ";
    }
    cout<<v.back()<<"\n";
}

ll power(ll n, ll k, ll mod) {
    ll ans = 1;

    n = n % mod;
    while(k > 0) {
        if(k % 2 != 0) {
            ans = (ans * n) % mod;
        }

        k = k/2;
        n = (n * n) % mod;
    }

    return ans;
}

void solve() {

    ll n, k;
    cin>>n>>k;

    if(k == 0) {
        cout<<"1\n";
        return;
    }

    vector<ll> dp(k, 0);

    ll cnt = power(2, k-1, MOD)%MOD;

    if(n % 2 != 0) {
        // AND is 1
        dp.back() = (dp.back()%MOD + power(cnt, n, MOD)%MOD)%MOD;

        // XOR is 0
        dp.back() = (dp.back()%MOD + (power(cnt, n, MOD)%MOD * power(2, n-1, MOD)%MOD)%MOD)%MOD;
    } else {
        // XOR is 0
        dp.back() += (power(cnt, n, MOD)%MOD * power(2, n-1, MOD)%MOD)%MOD;
    }

    ll ppp = 1;

    for(ll i=k-2;i>=0;i--) {

        // AND is 1 and XOR is 0
        if(n % 2 == 0) {
            ll val1 = power(2, ppp, MOD)%MOD;
            dp[i] = (power(val1, n, MOD)%MOD + power(cnt, n, MOD)%MOD)%MOD;
        } else {
            dp[i] = (dp[i]%MOD + dp[i+1]%MOD)%MOD;
        }
        ppp++;
    }

    cout<<dp.front()%MOD<<"\n";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int tc = 1;
    cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}

#include<bits/stdc++.h>

using namespace std;
typedef long long Long;

const int Maxn = 2e5 + 11, Mod = 1e9 + 7;
Long n, k, res1, res2;
Long dp[Maxn][2];

Long bMOD(int a, int b)
{
    if(b == 0)
        return 1;
    Long ans = bMOD(a, b / 2);
    ans = (ans * ans) % Mod;

    if(b & 1) ans = (ans * a) % Mod;
    return ans;
}

Long solve(int pos, int flag)
{
    if(pos >= k) return 1ll;
    if(dp[pos][flag] != -1){
        return dp[pos][flag];
    }
    Long ret = 0;
    if(flag){
        ret = (res1 * solve(pos + 1, flag)) % Mod;
    }
    else{
        Long x,y;
        if(n & 1){
            x = solve(pos + 1, flag) % Mod;
            y = (res2 * solve(pos + 1, flag)) % Mod;
            ret = (x + y)%Mod;
        }
        else{
            x = solve(pos + 1, 1) % Mod;
            y = (res2-1 * solve(pos + 1, flag)) % Mod;
            ret = (x + y)%Mod;
        }
    }
    return dp[pos][flag] = ret;
}

int main()
{
    int t;
    cin >> t;
    while(t--) {
        cin >> n >> k;
        res1 = bMOD(2, n);
        res2 = bMOD(2, n - 1);
        for(int i = 0; i < k; i++){
            for(int j = 0; j < 2; j++){
                dp[i][j] = -1;
            }
        }
        Long answer = solve(0, 0) % Mod;
        cout << answer << endl;
    }
    return 0;
}

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

long long mod = 1000000007;
long long fc[200069];

long long expo(long long n, long long m){
	if (m == 0) return 1;
	if (m == 1) return n;

	long long ret = expo(n, m/2);
	ret = (ret*ret) % mod;

	if (m % 2 == 1) ret *= n;
	return ret % mod;
}

long long choose(long long n, long long k){
	if (k == 0) return 1;
	if (k > n) return 0;

	long long ret = fc[n] * expo(fc[k], mod - 2);
	ret = ret * expo(fc[n-k], mod-2);

	return ret;

}

/*
1 -> dp[1][1] -> dp
  -> dp[2][0]
*/
int main() {
	int tc;
	cin >> tc;

	while (tc--){
		fc[0] = 1;
		for (int i = 1; i < 2e5 + 60; i++) fc[i] = (fc[i-1]*i) % mod;

		long long n, k;
		cin >> n >> k;

		if (k == 0) cout << "1\n";
		else {
			long long x = 0;
			for (long long i = 0; i <= n; i+=2) {
				x += choose(n, i);
			}

			x = expo(x, k);

			if (n % 2 == 1) {
				x += expo(2, k) - 1;
			}
			cout << x % mod << endl;
		}
	}
}

/*
3 =
*/

// #pragma optimization_level 3
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define  MOD             1000000007
#define  sym(s)          s = "#" + (s) + "#";
#define  INF             1e18
#define  newl            cout<<"\n";
#define  pb              push_back
#define  ppb             pop_back
#define  mp              make_pair
#define  ff              first
#define  ss              second
#define  PI              3.141592653589793238462
#define  set_bits        __builtin_popcountll
#define  lsb(x)          __builtin_ctzll(x);
#define  msb(x)          64 - __builtin_clzll(x) - 1;
#define  Erase(v,e)      v.erase(remove(all(v),e),v.end());
#define  parity(x)       __builtin_parity(x)
#define  sz(x)           ((int)(x).size())
#define  all(x)          (x).begin(), (x).end()
#define  alll(x,n)       x+1, x+n+1
#define  foo(i,a,n)      for(ll i = (a); i <= n; i++)
#define  deb1(a)         cout<<a<<"\n";
#define  deb2(a,b)       cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)     cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)   cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  debp(a)         cout<<(a).ff<<" "<<a.ss<<"\n";
#define  debv(a)         for(auto it: a)cout<<it<<" ";newl;
#define  debm(a)         for(auto it: a)cout<<"{"<<it.ff<<","<<it.ss<<"}, ";newl;
#define  deb1d(a,n)      foo(i,1,n)cout<<a[i]<<" ";newl;
#define  deb2d(a,n,m)    foo(i,1,n){foo(j,1,m){cout<<a[i][j]<<" ";}newl;}
#define  uniq(x)         sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

const int  N          =  (int)5e+3 + 8;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;
ll power(ll x, ll y, ll m = MOD) {
    if (y == 0) return 1;
    ll p = power(x, y / 2, m) % m;
    p = (p * p) % m;
    return (y % 2 == 0) ? p : (x * p) % m;
}
void MAIN(ll tc) {
    int n,k; cin>>n>>k;
    ll ans=0,prev=1;
    for(int i=k-1;i>=0;i--){
        if(n%2==0){
            ans+=prev*max(power(2,n)*i,1ll);
            ans%=MOD;
            prev*=(power(2,n-1)-1);
            prev%=MOD;
        }
        else{
            ans+=prev*power(2,n)*(i);
            ans%=MOD;
            prev*=(power(2,n-1)+1);
            prev%=MOD;
        }
    }
    ans+=prev;
    ans%=MOD;
    deb1(ans)
}
int main(){
    fastio();
    cout<<fixed; cout<<setprecision(10);
    int test_cases = 1;
    cin>>test_cases;
    for(int i = 1; i <= test_cases; i++){
        MAIN(i);
    }
}

#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=2e5+5;

int ksm(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)
			res=a*res%mod;
		b>>=1;
		a=a*a%mod;
	}
	return res%mod;
}

int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		int n,k;
		scanf("%d%d",&n,&k);
		int res=0,a=(ksm(2,n-1))%mod;
		if(n%2)
			res=(ksm(a+1,k))%mod;
		else if(k>=1)
		{
			res=((a-1)+ksm(ksm(2,n),k-1))%mod;
			for(int i=2;i<=k;++i)
			{
				res=(res+(res*(a-1))%mod)%mod;
				res=(res+ksm(ksm(2,n),k-i))%mod;
			}
		}
		if(k==0)
			puts("1");
		else
			printf("%d\n",res);
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vi vector<ll>
#define pii pair<ll, ll>
#define s string
#define ms multiset
#define um unordered_map
#define us unordered_set
#define mmp multimap
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define finish return 0;
#define FAST ios_base::sync_with_stdio(false), cin.tie(NULL);
#define cin(v); for(ll i=0;i<n;i++) cin >> v[i];
#define all(a) a.begin(), a.end()
#define print(x)                \
    for (auto element : x)      \
        cout << element << " "; \
    cout << endl
#define f(i, n) for (ll i = 0; i < n; i++)
#define f2(i,s,n) for (ll i = s; i < n; i++)
#define new_string(str) \
    string str;         \
    cin >> str;
#define input(a) \
    ll a;            \
    cin >> a;
#define input2(a, b) \
    ll a, b;            \
    cin >> a >> b;
#define input3(a, b, c) \
    ll a, b, c;            \
    cin >> a >> b >> c;
#define input4(a, b, c, d) \
    ll a, b, c, d;            \
    cin >> a >> b >> c >> d;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ld pi = acos(-1);
typedef vector<string> vs;
typedef pair<ll, string> pis;
typedef pair<string, string> pss;
typedef pair<string, ll> psi;
typedef map<ll, ll> mii;
typedef set<ll> si;

vi in(ll n, ll start = 0)
{
    vi vec(n);
    for (ll i = start; i < n; i++)
    {
    input(x);
        vec[i] = x;
    }
    return vec;
}

ll binexp(ll a, ll b, ll m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

void solve()
{
    input2(n,k);
    if(n%2) cout << binexp(binexp(2,n-1,mod)+1,k,mod)<<endl;
    else
    {
        ll ans = 1;
        f2(i,1,k+1)
        {
            ll a = binexp((binexp(2,n-1,mod)-1),(i-1),mod);
            ll b = binexp((binexp(2,n,mod)),(k-i),mod);
            ans += (b*a)%mod;
            ans%=mod;
        }
        cout << ans << endl;
    }

}
int main()
{
    FAST
    ll t;
    cin >> t;

    while(t--) solve();
    finish
}

#include<bits/stdc++.h>
using namespace std;
int T,n,k,ans;
const int mod=1e9+7;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}
inline int quick_pow(int a,long long b)
{
	long long ret=1LL,temp=a;
	while(b)
	{
		if(b&1)ret=1LL*ret*temp%mod;
		temp=1LL*temp*temp%mod;
		b>>=1;
	}
	return ret%mod;
}
int main()
{
	T=read();
	while(T--)
	{
		n=read(),k=read();
		int a=1;
		ans=0;
		for(int i=1;i<=k;i++)
		{
			int temp=0;
			if(!(n&1))
				(ans+=(1LL*(1LL*quick_pow(2,1LL*(k-i)*n)%mod)*a))%=mod;
			else
				temp++;
			(temp+=quick_pow(2,n-1))%=mod;
			if(!(n&1))
				(temp-=1)%=mod;
			a=1LL*a*temp%mod;
		}
		(ans+=a)%=mod;
		printf("%d\n",ans%mod);
	}
	return 0;
}

#include<iostream>
#include<unordered_map>
#include<cstdio>

using namespace std;

typedef long long ll;
const int N = 2e5 + 10;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 5;

ll cen[N];
ll inv[N];
int n, k;

ll qpow(ll a, ll b)
{
	ll res = 1;
	while(b){
		if(b & 1){
			res = res * a % mod;
		}
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}

void init()
{
	cen[0] = cen[1] = 1;
	for(int i = 2; i <= maxn; i ++){
		cen[i] = cen[i - 1] * i % mod;
	}
	inv[maxn] = qpow(cen[maxn], mod - 2);
	for(int i = maxn - 1; i >= 0; i --){
		inv[i] = inv[i + 1] * (i + 1) % mod;
	}
}

int main()
{
	init();
	int t;
	cin >> t;
	while(t --){
		scanf("%d%d", &n, &k);
		if(n & 1){
			ll ans = 0;
			for(int i = 0; i <= n - 1; i += 2){
				ans = (ans + cen[n] * inv[i] % mod * inv[n - i] % mod) % mod;
			}
			printf("%lld\n", ans + 1);
		}
		else{
			ll res = 0;
			for(int i = 0; i <= n - 2; i += 2){
				res = (res + cen[n] * inv[i] % mod * inv[n - i] % mod) % mod;
			}
			ll ans = 1;
			ll pp = 1;
			for(int i = 1; i <= k; i ++, pp = 2 * pp % mod){
				ans = (res * ans % mod + pp) % mod;
			}
			printf("%lld\n", ans);
		}
	}
}

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

typedef long double ld;
typedef long long int ll;
const ll mod = 1e9 + 7;
const ll INF = 1e18;
const ll NINF = -1e18;
#define pb push_back
#define endl "\n"
#define sz(x) (int)(x.size())
#define deb(x) cout << #x << " = " << x << endl
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0)
//===========================================================================

ll madd(ll a, ll b) {

    return (a + b) % mod;
}

ll mul(ll a, ll b) {

    return (a * b) % mod;
}

ll p[200005];

void calc() {

    p[0] = 1;
    for(ll i = 1; i < 200005; i++)
        p[i] = mul(p[i - 1], 2);

    return;
}

void solve() {

    ll n, k;
    cin >> n >> k;

    ll ans = 1, free = 1, tmp = p[n - 1] - 1;
    for(ll i = 0; i < k; i++) {

        //1 victory
        if(n & 1) {

            ans = madd(ans, free);
            free = mul(free, p[n - 1] + 1);
        }

        //0 victory
        ans = madd(ans, tmp);
        tmp = mul(tmp, p[n - 1] - 1);
    }

    cout << ans << endl;
    return;
}

int main() {
    fast_io;

    calc();

    int t;
    cin >> t;
    while(t--)
        solve();

    return 0;
}

#include <iostream>

using namespace std;

using ll = long long;

const int MOD = 1e9 + 7;

const int N = 1e5 + 10;
ll fact[N];
ll ivf[N];
ll Q_power(ll a, ll b = MOD - 2) {
    ll res = 1;
    while (b) {
        if (b & 1) res = res * a % MOD;
        b >>= 1;
        a = a * a % MOD;
    }
    return res;
}

ll Combo(ll n, ll m) {
    ll inv = ivf[n - m] * ivf[m] % MOD;
    return fact[n] * inv % MOD;
}

ll solve() {
    int n, k;
    cin >> n >> k;
    ll res = 0;
    if (n & 1) return Q_power(Q_power(2, n - 1) + 1, k);
    ll _2_1 = Q_power(2, n - 1);
    res += Q_power(_2_1 - 1, k);
    ll tmp = 1;
    for (int i = 1; i <= k; i++) {
        res = (res + tmp * Q_power(2, n * (n - i))) % MOD;
        tmp *= _2_1;
    }
    return res;
}

void init() {
    fact[0] = 1;
    for (int i = 1; i < N; i++) fact[i] = fact[i - 1] * i % MOD;
    ivf[N - 1] = Q_power(fact[N - 1]);
    for (int i = N - 2; i >= 0; i--) ivf[i] = ivf[i + 1] * (i + 1) % MOD;
}

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    int t;
    cin >> t;
    while (t--) printf("%lld\n", solve());
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define AC return
#define Please 0
#define itn int
#define enld '\n'       //IO?
#define endl '\n'       //IO?
#define Endl '\n'       //IO?
#define esle else
#define ciN cin
#define YES "YES"
#define NO "NO"
#define eb emplace_back
#define wide(x,ch) setw(x)<<setfill(ch)
#define show "ans-------------> "<<
class MyCpiise{public:bool operator()(pair<int,int> a,pair<int,int> b){return a.second<b.second;}};
MyCpiise Mcse;
#define dbg(x...) do{cout<<#x<<" -> ";err(x);}while (0)
void err(){cout<<'\n';}
template<class T, class... Ts>
void err(T arg, Ts... args) {
    cout<<arg<< ' ';
    err(args...);
}
template<typename T>
T read(T judge){
    T x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9') {if(c=='-') f=-1;c=getchar();}
    while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+c-'0',c=getchar();
    return f*x;
}
inline void reads(){return;}
template<class T,class... Ts>
inline void reads(T &x,Ts&... xs) {
    x=0;
    char c=getchar();
    while('0'<=c&&c<='9') {
        x=(x<<3)+(x<<1)+(c^48);
        c=getchar();
    }
    reads(xs...);
}
template<typename T>
void print(T x){
    if (x<0) putchar('-'),x=-x;
    if (x/10) print(x/10);
    putchar(x%10+'0');
}
mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
long long rng(long long l, long long r) {
    uniform_int_distribution<long long> uni(l, r);
    return uni(mt);
}

#define int long long                        //int main()->signed main()?
#define INF 0x3f3f3f3f
#define LLINF 9223372036854775807
#define pii pair<int,int>
#define pip pair<int,pii >
#define ppi pair<pii ,int>
#define ppp pair<pii ,pii >
const int MOD1=998244353;
const int MOD2=1e9+7;
const int N4=1e4+10;
const int N5=1e5+10;
const int NN5=2e5+10;
const int N6=1e6+7;
const int N7=1e7+10;
const int N8=1e8+10;
const int N9=1e9+5;
int dr[4]={0,1,0,-1};
int dc[4]={1,0,-1,0};
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define is_odd(x) (x&1)
#define lowbit(x) (x&(-x))
void bin_print(int now,int cnt){
    if(!cnt) return;
    bin_print(now>>1,cnt-1);
    cout<<(now&1);
}
int fast_pow(int x,int n=MOD2-2,int mod=MOD2,int ret=1){
    while(n){
        if(n&1) ret=ret*x%mod;
        x=x*x%mod;
        n>>=1;
    }
    return ret;
}
long long fast_ll_pow(long long x,long long n,long long ret=1){
    while(n){
        if(n&1) ret=ret*x;
        x=x*x;
        n>>=1;
    }
    return ret;
}
int exgcd(int a,int b,int &x,int &y){
    if(!b){x=1;y=0;return a;}
    else{int ret=exgcd(b,a%b,y,x);y-=a/b*x;return ret;}
}
int gcd(int a,int b){return !b ? a : gcd(b,a%b);}
typedef long long ll;
int f[NN5]={1};
int solveeve(int n,int k)
{
    if(k==0) return 1;
    int ans=0;
    int cc=1;
    int last=1;
    for(int i=2;i<=n-2;i+=2){
        last=((last*(n-i+2)*(n-i+1)/i)/(i-1))%MOD2;
        cc=(cc+last)%MOD2;
    }
    for(int i=1;i<=k;i++){
        ans=(ans+fast_pow(f[n],i-1,MOD2)*fast_pow(cc,k-i,MOD2)%MOD2)%MOD2;
    }
    ans=(ans+fast_pow(cc,k,MOD2))%MOD2;
    return ans;
}
int solveodd(int n,int k)
{
    int ans=0;
    int cc=1;
    int last=1;
    for(int i=2;i<=n-1;i+=2){
        last=((last*(n-i+2)*(n-i+1)/i)/(i-1))%MOD2;
        cc=(cc+last)%MOD2;
//        dbg(last);
    }
//    dbg(cc);
    ans=(ans+fast_pow(cc+1,k,MOD2))%MOD2;
    return ans;
}
void run()
{
    int n,k;
    cin>>n>>k;
    if(n%2==0) cout<<solveeve(n,k)<<endl;
    else cout<<solveodd(n,k)<<endl;

/*------------------------dbg----------------------------*/

    return;
    //T==1?
}
signed main()
{
//    freopen("D:\\MY_std_input\\std_input.txt", "r", stdin);
//    freopen("D:\\MY_std_input\\std_output1.txt", "w", stdout);
//    freopen("D:\\MY_std_input\\std_output2.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    // system("cls");
    for(int i=1;i<NN5;i++) f[i]=f[i-1]*2%MOD2;
    int T=1;
     cin>>T;
    while(T--)
    {
        run();
    }

    AC Please;
}
// "str.size()-num" --> "(int)str.size()-num" ?
/*
    sort(edge[i].begin(), edge[i].end(), [&](pii &a, pii &b){
        ......
    });
*/

#include <iostream>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#define int long long
using namespace std;
const int N=1e6+5,mod=1e9+7;
int n,m;
int fact[N],infact[N];
int qmi(int a,int k){
    int res=1;
    while(k){
        if(k&1)res=res*a%mod;
        a=a*a%mod;
        k>>=1;
    }
    return res;
}

int C(int a,int b){
    return fact[a]%mod*infact[a-b]%mod*infact[b]%mod;
}

void solve(){
	cin>>n>>m;

	int res=1;
	for(int i=0;i<n;i+=2)res=(res+C(n,i));

	cout<<qmi(res,m)<<endl;
}

main(){
	fact[0]=infact[0]=1;
    for(int i=1;i<N;i++){
        fact[i]=fact[i-1]*i%mod;
        infact[i]=infact[i-1]*qmi(i,mod-2)%mod;
    }

	int T;
	cin>>T;
	while(T--)solve();
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5+50;
const int mod = 1e9+7;
int qpow(int a,int b){
	int res=1;
	while(b){
		if(b&1) res=res*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return res;
}
int P[N],F,fac[N],inv[N];
int dfs(int n,int k){
	if(k==0) return 1;
	return (P[k-1]+F*dfs(n,k-1)%mod)%mod;
}
int C(int n,int m){
	if(m>n) return 0;
	if(m==0) return 1;
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
signed main(void){
	ios::sync_with_stdio(false);cin.tie(0);
	P[0]=1;
	for(int i=1;i<N;i++) P[i]=(P[i-1]<<1)%mod;
	fac[0]=1;
	for(int i=1;i<N;i++) fac[i]=fac[i-1]*i%mod;
	inv[N-1]=qpow(fac[N-1],mod-2);
	for(int i=N-2;~i;i--) inv[i]=(i+1)*inv[i+1]%mod;
	//cout<<C(3,0)<<" "<<C(3,2)<<"\n";
	int T;cin>>T;
	while(T--){
		int n,k;
		cin>>n>>k;
		F=0;
		for(int i=0;i+i<n;i++)
			F+=C(n,i+i);
		//cout<<"F="<<F<<"\n";
		cout<<dfs(n,k)<<"\n";
	}
	return 0;
}

#include<bits/stdc++.h>
#define ll long long int
#define pll pair<ll,ll>
#define vpll vector< pll >
#define mpll map<ll,ll>
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define s(v) v.size()
#define test ll t;cin>>t;while(t--)
#define vec vector<ll>
#define read0(v,n) for(int i=0;i<n;i++)cin>>v[i];
#define read1(v,n) for(int i=1;i<=n;i++)cin>>v[i];
#define trav(a,x) for (auto& a: x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define cut(x) {cout<<x;return 0;}
#define print(x) {cout<<x<<nl;continue;}
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORB(i,a,b) for(int i=a;i>=b;i--)
#define err1(a) {cout<<#a<<' '<<a<<nl;}
#define err2(a,b) {cout<<#a<<' '<<a<<' '<<#b<<' '<<b<<nl;}
#define mem(a,b) memset(a,b,sizeof(a))

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define f first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define nl '\n'
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
#define oset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
ll gcd(ll a, ll b){
    if (b==0)return a;
    return gcd(b, a % b);
}
ll lcm(ll a,ll b){

    return (a*b)/gcd(a,b);
}
ll bpow(ll a, ll b){
    ll ans=1;
    while(b){
        if(b&1)
            ans=(ans*a)%MOD;
        b/=2;
        a=(a*a)%MOD;
    }
    return ans%MOD;
}
void online_judge(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        #endif
}
ll arrange(ll n, ll k){

}
const int N=2e5+5;
ll fact[N];
void precompute(){
    fact[0]=1;
    FOR(i,1,2e5){
        fact[i]=(fact[i-1]*i)%MOD;
    }
}
ll inv(ll x){
    return bpow(x,MOD-2);
}
int main(){

    //online_judge();
    fast
    precompute();
    test{
        ll n,k;
        cin>>n>>k;
        if(k==0)print(1)
        if (n&1) {
            ll ans = bpow(bpow(2,n-1)+1,k)%MOD;
            print(ans)
        }
        ll m = bpow(2,n-1)-1;
        m=(m+MOD)%MOD;
        ll ans = bpow(m,k);
        FOR(i,0,k-1) {
            ll temp=bpow(m,i);
            temp=(temp*bpow(2,((k-1-i)*n)%MOD))%MOD;
            ans=(ans+temp%MOD)%MOD;
        }
        print(ans)

    }

}

//Author: Vo Chi Cuong
#include <bits/stdc++.h>
#define fs first
#define sc second
#define pb push_back

using namespace std;

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

const int N = 2e5;
const int INF = 1e9;
const int MOD = 1e9 + 7;

ll fact[N + 5], ifact[N + 5];
ll cnt_sub, even;
int n, k, idx;
ll binpow (ll a, ll b) {
	ll res = 1;
	for (; b; b >>= 1, (a *= a) %= MOD) {
		if (b & 1)
			(res *= a) %= MOD;
	}
	return res;
}

void init () {
	fact[0] = 1;
	for (ll i = 1; i <= N; i ++)
		fact[i] = i * fact[i - 1] % MOD;
	ifact[N] = binpow (fact[N], MOD - 2);
	for (ll i = N; i >= 1; i --) {
		ifact[i - 1] = i * ifact[i] % MOD;
	}
}

ll C (int n, int k) {
	return (fact[n] * ifact[k] % MOD * ifact[n - k] % MOD);
}

int cal[N][2], vis[N][2];

ll dp (int i, bool pre) {
	if (i < 0)
		return 1;
	int &r = cal[i][pre];
	if (vis[i][pre] == idx)
		return r;
	vis[i][pre] = idx;
	if (!pre) {
		return r = cnt_sub * dp (i - 1, 0) % MOD;
	}
	if (n & 1) {
		return r = dp (i - 1, 1) * (even + 1) % MOD;
	}
	return r = dp (i - 1, 0) + (dp (i - 1, 1) * even % MOD)  % MOD;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	#ifndef ONLINE_JUDGE
	freopen("test.inp", "r", stdin);
	freopen("test.out", "w", stdout);
	#endif
	init();
	int t;
	cin >> t;

	while (t --) {
		idx ++;
		cin >> n >> k;
		even = 0;
		cnt_sub = binpow (2, n);
		for (int i = 0; i < n; i += 2) {
			even += C (n, i);
			even %= MOD;
		}
		cout << dp(k - 1, 1) << "\n";
	}
}

#include <bits/stdc++.h>
#define FOR(i, j, k) for(int i = j; i < k; i ++)
#define FORE(i, j, k) for(int i = j; i <= k; i ++)
#define FORD(i, j, k) for(int i = j; i >= k; i --)
#define mp make_pair
#define ll long long
//#define f first
//#define s second
//#define int long long
using namespace std;

const int MOD=1e9+7;
const int N = 200005;

ll n, k;

ll mu(int x, int y)
{
    if(y == 0) return 1;
    if(y == 1) return x;
    ll res = mu(x, y/2);
    res = res * res % MOD;
    if(y % 2) res = res * x % MOD;
    return res;
}

ll inv(ll x)
{
    return mu(x, MOD - 2);
}

void mul(ll &x, ll y)
{
    x *= y;
    x %= MOD;
}

void add(ll &x, ll y)
{
    x += y;
    x %= MOD;
}

void solve()
{
    cin >> n >> k;
    /// only 1 col
    /// win case
    ll w1 = 0, d1 = 0;
    if(n % 2 == 0)
    {
        w1 = 1;
        d1 = 0;
    }
    else
    {
        w1 = 0;
        d1 = 2;
    }
    ll fac = 1;
    for(int i = 2; i <= n; i += 2)
    {
        mul(fac, n - i + 2);
        mul(fac, n - i + 1);
        mul(fac, inv(i - 1));
        mul(fac, inv(i));
        add(d1, fac);
    }
    ll draw = 1;
    ll res = 0;
    FORE(i, 1, k)
    {
        if(w1)
        {
            ll du = mu(2, (k - i));
            if(k != i) mul(du, n);
            mul(du, draw);
            add(res, du);
        }
        mul(draw, d1);
    }
    add(res, draw);
    cout << res << "\n";
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//#define task""
//    freopen(task".inp","r",stdin);
//    freopen(task".out","w",stdout);
    int T;
    cin >> T;
    while(T --)
        solve();
    return 0;
}

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

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

#define ll long long int
#define fastio() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define google(t) cout<<"Case #"<<t+1<<": "
#define mod 1000000007
#define endl "\n"
#define FOR(var,startval,endval) for(int var=startval; var<endval; var++)

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

ll pow2[200001] = {1};
void initdp(){
for(ll i=1; i<200001; i++)
	pow2[i] = (pow2[i-1]*2)%mod;
}
ll calcu(ll n, ll k){
	if(k==0)
		return 1LL;
	if(n%2 == 0)
		return (pow2[k-1] + ((pow2[n-1]-1)*calcu(n, k-1))%mod)%mod;
	else
		return (((pow2[n-1])*calcu(n, k-1))%mod + calcu(n, k-1))%mod;
}

void solve(){
	ll n, k;
	cin>>n>>k;
	ll ans = calcu(n,k);
	cout<<ans<<endl;
}

int main(){
	initdp();
	fastio();
	int T=1;
	cin>>T;
	for(int t=0; t<T; t++){
		// google(t);
		solve();
	}
	return 0;
}

#include "bits/stdc++.h"
#include <cassert>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
using pd = pair<double, double>;
using pld = pair<ld, ld>;
// #define LOCAL

int main()
{
    cin.tie(0)->sync_with_stdio(0);
#ifdef LOCAL
    ifstream cin("input.txt");
    ofstream cout("output2.txt");
#endif

    int t;
    cin >> t;
    while (t--)
    {
        ll n, k;
        cin >> n >> k;
        static const int M = 1e9 + 7;

        auto fast_exp = [](ll a, ll b) -> ll
        {
            ll res{1};
            while (b)
            {
                if (b & 1)
                {
                    res = (res * a) % M;
                }
                a = (a * a) % M;
                b >>= 1;
            }
            return res;
        };

        if (n % 2 == 0)
        {
            ll res{1};
            for (int i = 0; i < k; ++i)
            {
                res = (res * fast_exp(2, (n - 1) * i)) % M;
                res = (res * fast_exp(2, n * (k - 1 - i))) % M;
            }
            cout << res + (k > 0) << "\n";
        }
        else
        {
            cout << fast_exp(2, k * (n - 1)) + (k > 0) << "\n";
        }
    }
}

#include <algorithm>
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

#define int long long
#define PI 3.14159265
#define pb(x) push_back(x)
#define all(v) v.begin(), v.end()
#define dbg(x) cout<<#x<<" "<<x<<endl;
#define bye cout<<endl;return
#define uni 1.000000
#define ld long int
#define sam000013 me
using namespace std;
const long long mod = 1000000007;
const long long secondMod = 998244353;
// const int hashMod = 29996224275833;

template <typename T>

void show(vector<T> x)
{
    for (auto e : x){
        cout<<e<<" ";
    }
    cout<<endl;
}
template <typename T1>
void showPair(vector<pair<T1, T1>> x) {
    for(auto e:x){
        cout<<e.first<<" "<<e.second<<endl;
    }
}
template <typename T2>
void showSet(set<T2> x) {
    for(auto e:x){
        cout<<e<<" ";
    }
    cout<<endl;
}
template <typename T3>
void showMultiSet(multiset<T3> x) {
    for(auto e:x){
        cout<<e<<" ";
    }
    cout<<endl;
}
template <typename T4>
void showSetPair(set<T4> x) {
    for(auto e:x){
        cout<<"{"<<e.first<<" "<<e.second<<"}, ";
    }
    cout<<endl;
}
template <typename T5>
void showSinglePair(pair<T5, T5> P){
    cout<<P.first<<" "<<P.second<<"\n";
}

/*

-Wall -Wextra -pedantic -std=c++11 -O2 -Wshadow -Wformat=2 -Wfloat-equal -Wconversion -Wlogical-op -Wshift-overflow=2 -Wduplicated-cond -Wcast-qual -Wcast-align -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover -fstack-protector

*/
vector<int> dx = {1,-1};

bool isValid(int i,int n){
    return (i>=0 && i<n);
}
int seal(int a, int b){
	if(a < 0){
		return (a/b);
	}
	return (a+b-1)/b;
}
int fastModExp(int a,int b,int m){
    int res = 1;
    while(b>0){
        if(b&1){
            res = (res*a)%m;
        }
        a = (a*a)%m;
        b = b>>1;
    }
    return res;
}
void solve(){
	int n,k;
	cin>>n>>k;
	if(k == 0){
		cout<<1<<"\n";return;
	}

	int total = fastModExp(2, k*n, mod);
	if(n==1){
		cout<<total<<"\n";return;
	}
    int dp[k];
    dp[0] = fastModExp(2, n-1, mod);
    if(n&1){
        dp[0]++;
    }
    for(int i=1; i<k; i++){
        if(n&1){
            dp[i] = (dp[i-1] + fastModExp(2, n-1, mod)*dp[i-1])%mod;
        }else{
            dp[i] = (fastModExp(2, i*n, mod) + fastModExp(2, n-1, mod)*dp[i-1])%mod;
        }
    }
    cout<<dp[k-1]<<"\n";
}
signed main(){
	ios::sync_with_stdio(false);cin.tie(0);
	int t   = 1;
	cin >> t;
    for(int i=1; i<=t; i++){
		solve();
    }
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define what(a) cout << (#a) << " is " << (a) << '\n';

const int MOD = 1e9 + 7 , N = 2e5 + 10;
long long factorial[N] , n , k , memo[N][2] , even_ways;

long long power(long long a, long long b) {

  long long ret = 1;
  while (b) {
    if (b & 1)
      ret = (ret * a) % MOD;
    b >>= 1;
    a = (a * a) % MOD;
  }
  return ret;
}

long long modInverse(long long n) { return power(n, MOD - 2); }

long long nCr(long long n, long long r) {
  return ((((factorial[n] * modInverse(factorial[r])) % MOD) *
        modInverse(factorial[n - r])) %
          MOD) %
         MOD;
}

long long dp(int i , int b) {
  if(i < 0) return 1;

  long long &res = memo[i][b];
  if(res != -1) return res;

  res = 0;
  if(b == 0) return (power(2 , n) * dp(i - 1 , 0)) % MOD;

  if(n & 1) {
    return res = (dp(i - 1 , 1) * (even_ways + 1)) % MOD;
  }
  else {
    res = (dp(i - 1 , 1) * even_ways) % MOD;
    res += dp(i - 1 , 0);
    res %= MOD;
    return res;
  }
}

void solve() {
  cin >> n >> k;

  even_ways = 0;
  for(int i = 0 ; i < n ; i += 2) {
    even_ways += nCr(n , i);
    even_ways %= MOD;
  }

  for(int i = 0 ; i <= k ; i++) memo[i][0] = memo[i][1] = -1;

  cout << dp(k - 1 , 1) << '\n';
  return;
}

int main() {

  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  factorial[0] = 1;
  for(long long i = 1 ; i < N ; i++) {
    factorial[i] = factorial[i - 1] * i;
    factorial[i] %= MOD;
  }

  int tt = 1;
  cin >> tt;
  while (tt--) {
    solve();
  }
  return 0;
}

#include<bits/stdc++.h>
#define mod 1000000007
#define endl '\n'
using namespace std;
typedef long long int ll;

const int N=2e5+5;

ll po(ll a, ll b)  {
    ll ans=1;
    ll r=a;
    while(b>0)  {
        if(b&1)  {
            ans=(ans*r)%mod;
            b--;
        }
        b/=2;
        r=(r*r)%mod;
    }
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int t=1;
    cin>>t;

    ll fc[N], inv[N];
    fc[0]=1; inv[0]=1;
    for(int i=1; i<N; i++)  {
        fc[i]=(fc[i-1]*i)%mod;
        inv[i]=po(fc[i],mod-2);
    }
    while(t--)    {
        int n,k;
        cin>>n>>k;
        ll ans=0;
        ll dp[k+1];

        ll cal[n+1]={0};
        cal[0]=1;
        ll temp;
        for(int i=1; i<=n; i++)  {
            cal[i]=fc[n];
            temp=inv[n-i]*inv[i];
            temp%=mod;
            cal[i]*=temp;
            cal[i]%=mod;
        }
        ll s=0;
        for(int i=0; i<n; i+=2)  {
            s+=cal[i];
            s%=mod;
        }
        //cout<<s<<' ';

        memset(dp,0,sizeof(dp));
        dp[k]=1;
        for(int i=k-1; i>=0; i--)  {
            dp[i]=dp[i+1]*s;
            dp[i]%=mod;
            if(n&1)  {
                dp[i]+=dp[i+1];
            }
            dp[i]%=mod;
            if(n%2==0)  {
                ll rem=i;
                ans+=(dp[i+1]*po(2,rem-1))%mod;
                ans%=mod;
            }
        }
        /*for(int i=0; i<=k; i++)  {
            cout<<dp[i]<<' ';
        }*/
       // cout<<endl;
        ans+=dp[0];
        ans%=mod;
        if(k==0)  ans=1;
        cout<<ans<<endl;

    }

    return 0;

}

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

#define deb(x) cerr << #x << "=" << x << endl
#define deb2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define deb3(x,y,z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z<<endl
#define pb push_back
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define fo(var, start,end,step) for(var= start ;var<= end ;var+= step)
#define fo1(var, start,end,step) for(var= start ;var>= end ;var-= step)
#define umap unordered_map
#define uset unordered_set
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define sort0(v) sort(all(v))
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<bool> vb ;
typedef pair<ll, ll> pll;
#define sz(x) (ll)x.size()
#define pb push_back
#define ppb pop_back
#define mkp make_pair

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif

typedef unsigned long long ull;
typedef long double lld;

void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

#define inf 1000000000000000005
const ll mod = 1e9+7 ;

ll inv(ll i) {if (i == 1) return 1; return (mod - ((mod / i) * inv(mod % i)) % mod) % mod;}

ll mod_mul(ll a, ll b) {a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod;}

ll mod_add(ll a, ll b) {a = a % mod; b = b % mod; return (((a + b) % mod) + mod) % mod;}

ll mod_sub(ll a, ll b) {a = a % mod; b = b % mod; return (((a - b + mod) % mod) + mod) % mod;}

ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b);}

ll ceil_div(ll a, ll b) {return ceil(a * 1.0 / b);}

ll pwr(ll a, ll b) {a %= mod; ll res = 1; while (b > 0) {if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1;} return res;}
ll i,j ;
bool even(ll n) {return n % 2 == 0;}
bool odd(ll n) {return n % 2 == 1;}
void no(){cout<<"NO"<<endl;}

class Solve{
public:
    ll n,k ;
    vll dp ;

    Solve(){
        cin>>n>>k ;
        // deb2(n,k) ;
        dp = vll(n+1,1) ;

        ll tmp = mod_sub(pwr(2,k),1) ;

        if(k != 0){
            dp[0] = 1 ;
            dp[1] = tmp ;
            for(int i = 2 ; i <= n ; i++){
                if (odd(i)){
                    dp[i] = mod_sub(mod_mul(dp[i-2],6),1) ;
                }else {
                    dp[i] = mod_mul(pwr(2,k), dp[i-2]) ;
                }
            }
        }

    }

    void get_ans(){
        // debug(dp) ;
        cout << dp[n] << endl ;
    }
};

int main()
{
    fast;
#ifndef ONLINE_JUDGE
    freopen("error.txt", "w", stderr);
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ll t ;
    cin>>t ;

    while(t--)
    {
        Solve s ;
        s.get_ans() ;
    }

}

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <functional>
using namespace std;

typedef long long ll;

const int MAXN = 3e5 + 5;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;

ll Jc[MAXN];
void calJc(){
    Jc[0] = Jc[1] = 1;
    for(ll i = 2; i < MAXN; i++)
        Jc[i] = Jc[i - 1] * i % MOD;
}

ll pow(ll a, ll n, ll p){
    ll ans = 1;
    while(n){
        if(n & 1) ans = ans * a % p;
        a = a * a % p;
        n >>= 1;
    }
    return ans;
}

ll niYuan(ll a, ll b){
    return pow(a, b - 2, b);
}

ll C(ll a, ll b){
    return Jc[a] * niYuan(Jc[b], MOD) % MOD * niYuan(Jc[a - b], MOD) % MOD;
}

ll sp[MAXN];

int main() {
	calJc();
	int t; scanf("%d", &t);
	while (t--) {
		int n, m;
		scanf("%d %d", &n, &m);
		if(m==0){
			printf("1\n");
			continue;
		}
		ll p = 1;
		for (int i = 1; i <= n;i++){
			p *= 2;
			p %= MOD;
		}
		ll v = 1;
		for (int i = 2; i <= n;i+=2){
			v += C(n, i);
			v %= MOD;
		}
		if(n%2) v++;
		else v--;
		ll s = 1;
		for (int i = 1; i <= m;i++){
			sp[i] = s;
			s *= v;
			s %= MOD;
		}
		if(n%2==0){
			ll sum = 0;
			ll k = 1;
			for (int i = 1; i <= m;i++){
				sum += k * sp[i];
				sum %= MOD;
				k *= p;
				k %= MOD;
			}
			s += sum;
			s %= MOD;
		}
		printf("%lld\n", s);
	}
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define loop(start, end, var) for(int var = start; var <= end; var++)
#define loopDown(start, end, var) for(int var = start; var >= end; var--)
#define foreach(el, arr) for (auto el : arr)
#define matrix(type, n, m) vector <vector <type>> (n, vector<type> (m))
#define F first
#define S second
#define all(arr) arr.begin(), arr.end()
#define vec vector
#define pb push_back
typedef long long ll;
typedef vector <int> vi;
typedef pair <int, int> pi;

const int MOD = 1e9 + 7;

void solve()
{
    int n, k; cin >> n >> k;

    if ( k == 0 )
    {
        cout << 1 << '\n';
        return;
    }

    int ans = 1;

    loop( 1, n - 1, i )
    {
        ans *= 2;
        ans %= MOD;
    }

    if ( n % 2 == 1 )
        ans++;

    cout << ans % MOD << '\n';
}

signed main()
{
    #ifdef LOCAL
    freopen( "input.txt", "r", stdin );
    freopen( "output.txt", "w", stdout );
    #endif

    ios_base::sync_with_stdio( false );
    cin.tie( 0 );
    cout.tie( 0 );

    int t; cin >> t;

    while ( t-- ) solve();

    return 0;
}

#include <bits/stdc++.h>

#define int long long
#define ll long long
#define ld long double

using namespace std;

const int INF = 1e9 + 10, N = 2e5, MOD = 1e9 + 7;

int sum(int a, int b){
    return ((ll) a + b) % MOD;
}
void add(int& a, int b){
    a = sum(a, b);
}
int mul(int a, int b){
    return ((ll) a * b) % MOD;
}
int pow(int a, int n){
    int res = 1;
    while (n){
        if (n & 1)
            res = mul(res, a);
        a = mul(a, a);
        n >>= 1;
    }

    return res;
}
int rat(int a, int b){
    return mul(a, pow(b, MOD - 2));
}

int dp[N + 1][2], fact[N + 1];

int CNK(int n, int k){
    assert(0 <= k and k <= n);
    return rat(fact[n], mul(fact[n - k], fact[k]));
}

void solve(){
    int n, k;   cin >> n >> k;

    fact[0] = 1;
    for (int i = 1; i <= n; i++){
        fact[i] = mul(fact[i - 1], i);
    }

    int x = 0;
    for (int i = 0; i < n; i += 2)
        add(x, CNK(n, i));

    // cerr << x << '\n';

    dp[0][0] = 1;
    for (int i = 1; i <= k; i++){
        dp[i][0] = mul(dp[i - 1][0], x);
        dp[i][1] = mul(dp[i - 1][1], pow(2, n));
        if (n % 2 == 0)
            add(dp[i][1], dp[i - 1][0]);
        else
            add(dp[i][0], dp[i - 1][0]);
    }

    int ans = sum(dp[k][0], dp[k][1]);
    cout << ans << '\n';
}

int32_t main(int32_t argc, char const *argv[])
{
    // freopen("aplusb.in", "r", stdin);
    // freopen("aplusb.out", "w", stdout);

    ios::sync_with_stdio(0);
    cout.tie(0);    cin.tie(0);

    // cout << fixed << setprecision(10);

    // int t;  cin >> t;
    // while (t--)
        solve();
}

#include <bits/stdc++.h>

using namespace std;

#define x first
#define y second
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const int N = 100010;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-6;
const char nl = '\n';

int n, m;
int a[N], b[N];

int qmi(int a, int k, int p){
    LL ans = 1;
    while(k){
        if(k & 1) ans = ans * a % p;
        k >>= 1;
        a = (LL)a * a % p;
    }
    return ans;
}

void solve(){
	cin >> n >> m;
    if(n % 2 == 1){
        LL ans = 1;
        for(int i = m; i > 0; i--){
            ans = (ans * (qmi(2, n - 1, mod) + 1)) % mod;
        }
        cout << ans << nl;
    }
    else{
    	LL res=0;
    	LL t=1;
        for(int i=0;i<m;i++){
        	//cout<<res<<endl;
   			res=(res+(t*qmi(qmi(2,m-i-1,mod),n,mod))%mod)%mod;
   			t=(t*qmi(2,n-1,mod)-1)%mod;
  		}
  		//cout<<t<<endl;
  		res=(res+t)%mod;
  		cout<<res<<endl;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int T = 1;
    cin >> T;
    while(T--) solve();

    return 0;
}

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

#define ll long long
#define pi pair<int, int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define vpi vector<pair<int, int>>
#define mii map<int, int>
#define mmii multimap<int, int>
#define umii unordered_map<int, int>
#define umsii unordered_multimap<int, int>
#define si set<int>
#define msi multiset<int>
#define usi unordered_set<int>
#define umsi unordered_multiset<int>
#define sc set<char>

#define f(i, s, e) for (long long int i = s; i < e; i++)
#define cf(i, s, e) for (long long int i = s; i <= e; i++)
#define rf(i, e, s) for (long long int i = e - 1; i >= s; i--)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

template <class T>
void print_v(vector<T> &v) {
    cout << "[";
    for (auto x : v) cout << x << ", ";
    cout << "\b\b]\n";
}

template <class T>
long long int sum_v(vector<T> &v) {
    long long int ans = 0;
    for (auto a : v) ans += a;
    return ans;
}

#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
ll min(ll a, int b) {
    if (a < b) return a;
    return b;
}
ll min(int a, ll b) {
    if (a < b) return a;
    return b;
}
ll max(ll a, int b) {
    if (a > b) return a;
    return b;
}
ll max(int a, ll b) {
    if (a > b) return a;
    return b;
}
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
string to_upper(string a) {
    for (int i = 0; i < (int)a.size(); ++i)
        if (a[i] >= 'a' && a[i] <= 'z') a[i] -= 'a' - 'A';
    return a;
}
string to_lower(string a) {
    for (int i = 0; i < (int)a.size(); ++i)
        if (a[i] >= 'A' && a[i] <= 'Z') a[i] += 'a' - 'A';
    return a;
}
bool prime(ll a) {
    if (a == 1) return 0;
    for (int i = 2; i <= round(sqrt(a)); ++i)
        if (a % i == 0) return 0;
    return 1;
}
void yes() { cout << "YES\n"; }
void no() { cout << "NO\n"; }

typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int uint64;

int pow(long long x, unsigned int y, int p) {
    int res = 1;
    x = x % p;
    if (x == 0) return 0;
    while (y > 0) {
        if (y & 1) res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

void solve() {
    int n, k;
    cin >> n >> k;
    if (n == 1) {
        cout << pow(2, k, MOD) << "\n";
        return;
    }
    ll ans = pow(pow(2, k, MOD), n, MOD);
    f(i, 0, k) {
        ans -= n * pow(2, k - 1, MOD);
        ans += i * pow(pow(2, i - 1, MOD), n);
    }
    cout << (ans % MOD) << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
int n,k;
const int mod=1e9+7;
int tt;
int powmod(int a,int b)
{
	int res=1;
	while(b>0)
	{
		if(b&1)res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res%mod;
}
signed main()
{
	IOS;
	cin>>tt;
	while(tt--)
	{
		cin>>n>>k;
		if(n&1)
		{
			int ans=(n%mod)*(powmod(2,k)%mod-1+mod)%mod+2;
			cout<<ans%mod<<endl;
		}
		else
		{
			if(k==0)
			{
				cout<<1<<endl;
			}
			else
			{
				int ans=((powmod(2,k)-1)%mod)*(n%mod);
				cout<<ans%mod<<endl;
			}
		}
	}
	return 0;
}

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

// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

// template <class T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

//find_by_order(k):    It returns to an iterator to the kth element (counting from zero) in the   set
//order_of_key(k) :    It returns to the number of items that are strictly smaller than our      item k

#define        all(x)        x.begin(),x.end()
#define        pb            push_back
#define        ff            first
#define        ss            second
#define        ar            array
#define        vi            vector<int>
#define        F(i,a,b)      for(i=a;i<b;++i)
#define        NL            cout<<"\n";
#define        INF           1e17+25
#define        pii           pair<int,int>
#define        fast          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define        pll           pair<ll,ll>

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

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}

typedef long long ll;
typedef long double ld;
const ll mod=1e9+7;
//const ll mod = 998244353LL;
const ld PII = acos(-1);

ll fpow(ll a, ll b) {

    ll res=1;
    while(b>0) {
        if(b&1)
            res=(res*a);
        a=(a*a);
        b>>=1;
    }
    return res;
}

// .......DEBUG .........
#ifndef DEBUGGING
        #define debug(x) cout << #x << ": " ; ___print(x) ; cout << endl
#endif

void ___print(int x) { cout << x ; }
void ___print(ll x)  { cout << x ; }
void ___print(string x) { cout << x ;}
void ___print(double x) { cout << x ;}
void ___print(ld x ) { cout << x ;}
void ___print(float x) { cout << x ;}
void ___print(char x) { cout << x ;}

template <class T,class V>
void ___print(pair<T,V>p)
{
    cout << "{ " ; ___print(p.ff);
    cout << "," ; ___print(p.ss);
    cout<<" }";
}

template <class T>
void ___print(vector<T>v)
{
    cout<<"[ ";
    for(T tmp : v)
    {
        ___print(tmp);
        cout << " ";
    }
    cout<<"]";

}

template <class T>
void ___print(set<T>s)
{
    cout<<"[ ";
    for(T tmp : s){
        ___print(tmp);
        cout<<" ";
    }
    cout<<"]";
}

template <class T>
void ___print(multiset<T>s)
{
    cout<<"[ ";
    for(T tmp:s)
    {
        ___print(tmp);
        cout<<" ";
    }
    cout<<"]";
}

template <class T,class V>
void ___print(map<T,V> mp)
{
    cout<<"[ ";
    for(auto tmp:mp)
    {
        ___print(tmp);
        cout<<"\n";
    }
    cout<<"]";
}

// ................MODULAR FUNCTIONS..........

ll mod_fpow(ll a,ll b){
    ll res=1;
    a=(a%mod);
    if(a<0) a+=mod;

    while(b>0) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

ll mod_inv(ll a){
    return mod_fpow(a,mod-2);
}

ll mod_add(ll a,ll b){
    ll res = (a+b)%mod;
    if(res<0) res+=mod;
    return res;
}

ll mod_mul(ll a,ll b){
    ll res = ((a%mod)*(b%mod))%mod;
    if(res<0) res+=mod;
    return res;
}

ll mod_sub(ll a,ll b){
    ll res = (a-b)%mod;
    if(res<0) res+=mod;
    return res;
}

ll mod_div(ll a,ll b){
    ll binv = mod_inv(b);
    ll res = ((a%mod)*(binv))%mod;
    if(res<0) res+=mod;
    return res;
}

  // ---------------------------------------   \\

ll MOD_POW(ll a,ll b,ll MOD){
    ll res=1;
    a=(a%MOD);
    if(a<0) a+=MOD;

    while(b>0) {
        if(b&1)
            res=(res*a)%MOD;
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}

void solve(){

   ll n,k,i;
   cin >> n >> k;

   if(n%2==0){
    cout<<mod_fpow(2ll,k)<<"\n";
    return;
   }

   // 2^k^n-1

   ll res = MOD_POW(n-1,k,mod-1);

   res = mod_fpow(2ll,res);

  // res= mod_add(res,1ll);

   for(i=k-1;i>=0;--i){
    // put 1 here

    // forward
    ll tmp = MOD_POW(n-1,i,mod-1);
    tmp = mod_fpow(2ll,tmp);

    if(i==0) tmp=1;
    res=mod_add(res,tmp);

    tmp = MOD_POW(n-1,k-i-1,mod-1);
    tmp = mod_fpow(2ll,tmp);

    if(i==k-1) tmp=1;
    if(k==1) tmp=0;
    res=mod_add(res,tmp);

   }

   cout<<res<<"\n";

}

signed main(void)
{

    fast;

    #ifndef ONLINE_JUDGE
      freopen("input.txt","r",stdin);
      freopen("output.txt","w",stdout);
      freopen("error.txt","w",stderr);
    #endif

    cout<< setprecision(12) << fixed;

    auto START___1 = high_resolution_clock::now();

    int CASES=1;
   cin >> CASES;

    for(int i=1;i<=CASES;i++){
        solve();
    }

    auto STOP___1 = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(STOP___1 - START___1);

    #ifndef TIME_TAKEN
      // cerr << "Time: " << duration . count() / 1000 << " ms" << endl;
    #endif

}

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

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define int int64_t
typedef pair<int,int> pii;
const int X=1e9+7;
const int inf=1e18;

#define lld        int
#define pqu        priority_queue
#define eb         emplace_back
#define mp         make_pair
#define fi         first
#define se         second
#define pb         push_back
#define v          vector
#define Y          998244353
#define EPS        1e-6
#define N          500005
#define pi         3.1415926535897932384626

// uncomment below line if large input and output is there
// dont uncomment if interactive problems
// #define endl       "\n"

#define ones(x)     __builtin_popcount(x)
#define all(a)     (a).begin(),(a).end()

#define rec(i,s,e)   for(int i=s ; (s<=e)?(i<e):(i>=e) ; (s<=e)?(i++):(i--) )
#define google(i)    cout<<"Case #"<<i<<": "
//rec(i,1,n-1) rec(i,n-1,0) for n=1

//lower_bound - returns first element such that a[i]>=x
// upper bound - returns first element such that a[i]>x
// - returns in 0 based indexing - if no such elemnt exists return n (both upper and lower)

//floor() for low
//ceil() for above
// trunc() removes decimal digits
//round() used to round off

void prec(double n,int d)
{
    cout<<fixed<<setprecision(d)<<n<<endl;
}

//prime[i]==1 if it is prime
// by default 1 and 0 are set to prime
int prime[1000001];
void sieve(int n)
{
    rec(i,0,n+1)
     prime[i]=1;

    for(int i=2;i*i<=n;i++)
    {
        if(prime[i]!=1)
         continue;
        for(int j=i*i;j<=n;j=j+i)
        {
            if(prime[j]==1)
            {
                prime[j]=i;
            }
        }
    }
}

// gcd
// __gcd(a,b)
int gcd(int a,int b)
{
    if(a==0)
     return b;
    return gcd(b%a,a);
}

//fermat a^(m-2)%mod
int bin(int a,int n,int m)
{
    int res=1;
    while(n)
    {
        if(n%2)
        {
            res=(res*a)%m;
            n--;
        }
        a=(a*a)%m;
        n/=2;
    }
    return res;
}

// factorial
lld fact[1000001];
void precompute(lld n)
{
    fact[0]=1;
    rec(i,1,n+1)
      fact[i]=(fact[i-1]*i)%X;
}

// combinatorics
lld ncr(lld n,lld r)
{
    if(r==0)
     return 1;
    else if(r>n)
     return 0;
    else
     return ( (fact[n]*bin(fact[r],X-2,X))%X * bin(fact[n-r],X-2,X) )%X;
}

//modified random function
lld my_rand(){
    lld x = rand();
    lld y = rand();

    lld ans = x*(RAND_MAX + y) + y;
    return ans;
}

void bfs(int s,v<int> g[],int n)
{
    bool vis[n];
    rec(i,0,n)
      vis[i]=false;

    vis[s]=true;
    deque<int> q;
    q.pb(s);

    while(!q.empty())
    {
        s=q.front();
        q.pop_front();

        for(int i=0;i<(int)g[s].size();i++)
        {
            if(!vis[g[s][i]])
            {
                vis[g[s][i]]=true;
                q.pb(g[s][i]);
            }
        }
    }
}

void dfs(int u,v<int> g[],bool *vis)
{
    vis[u]=true;

    for(int i=0;i<(int)g[u].size();i++)
    {
        if(!vis[g[u][i]])
        {
            dfs(g[u][i],g,vis);
        }
    }
}

void contest(int tt)
{
    int n,k;
    cin>>n>>k;

    int x = (bin(2,n-1,X) + n%2)%X;
    int ans = 1;

    if(n%2){
        ans = bin(x,k,X);
        cout<<ans<<endl;
        return;
    }

    x = (x-1+X)%X;

    for(int i=0;i<k;i++){
        ans = (x*ans)%X;
        if(i>=2){
            ans += bin(2,k-2,X);
        }
        ans %= X;
    }

    cout<<ans<<endl;

}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    //sieve(1e6);
    //precompute(1e6);

    int T=1;
    cin>>T;
    rec(tt,0,T)
    {
      contest(tt);
    }
	return 0;
}

//जय श्री गणेश
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <cstring>
#include <cmath>
#include <queue>
#include <iomanip>
#include <numeric>
#include <set>
#include <map>
#include <list>

#define int long long int
#define ll  int
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 1000000
#define endl '\n'

using namespace std;

void init_code(){
     fastio;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

int mod = 1e9+7 ;

ll gcd(ll a, ll b)
{
    if(b>a)
    return gcd(b,a) ;
    if(b == 0)
    return a ;
    return gcd(b,a%b)  ;
}

int lcm(int a,int b)
{
    int res = (a*b)/gcd(a,b) ;
    return res ;
}

int count_bits(int n)
{
    int len = 0 ;
    while(n > 0)
    {
        n = n /2 ;
        len++ ;
    }
    return len ;
}

ll power(ll a,ll b)
{
    ll res = 1 ;
    while(b > 0)
    {
        if(b&1)
        {
            res = res*a ;
            res = res%mod ;
        }
        b =b/2 ;
        a = a*a ;
        a = a%mod ;
    }
    return res ;
}

int uncommon_set_bits(int x,int y)
{
    int a[32] ;
    int b[32] ;
    int n[32] ;
    memset(a,0,sizeof(a)) ;
    memset(b,0,sizeof(b)) ;
    memset(n,0,sizeof(n)) ;
    int l = 0 ;
    while(x>0){
        a[l] = x%2 ;
        l++ ;
        x = x/2 ;
    }
    l = 0 ;
    while(y > 0){
        b[l] = y%2 ;
        l++ ;
        y = y/2 ;
    }
    reverse(a,a+32) ;
    reverse(b,b+32) ;
    for(int i = 0 ; i< 32 ;i++){
        if(b[i] == 1 && a[i] == 0){
            n[i] = 1 ;
        }
    }
    int res = 0 ;
    int p = 1 ;
    for(int i = 31 ; i>= 0 ;i--){
        res += p*n[i] ;
        p = p*2 ;
    }
    return res ;
}

void swap(int &a,int &b){

    int temp = a ;
    a = b ;
    b = temp ;
}

int lower_limit(int l,int r,vector<int> elem,int t)
{
    int res = r+1 ;
    while(l <= r)
    {
        int mid = (l+r)/2 ;
        if(elem[mid] >= t){
            r = mid-1 ;
            res = min(res,mid) ;
        }
        else{
            l = mid+1 ;
        }
    }
    return res ;
}

int upper_limit(int l,int r, vector<int> elem,int t)
{
    int res = l-1 ;
    while(l <= r)
    {
        int mid = (l+r)/2 ;
        if(elem[mid] <= t){
            l = mid+1 ;
            res = max(res,mid) ;
        }
        else{
            r = mid-1 ;
        }
    }
    return res ;
}

void solve()
{
    int n,k ;cin>>n>>k ;
    int first_bit = power(2,n-1) ;
    first_bit = first_bit%mod ;
    if(n%2){
        first_bit++ ;
    }
    first_bit =first_bit%mod ;
    int ans = power(first_bit,k) ;
    cout<<ans%mod<<endl ;
}

int32_t main()
{
    // your code goes here
    init_code() ;

    int t = 1  ;

   cin>>t ;

    while(t--){

           // cout<<100%7<<endl ;
           // return 0 ;
            solve() ;
        //cout<<uncommon_set_bits(1,3)<<endl ;

    }

    return 0;
}

#include <bits/stdc++.h>

#define int long long
#define ll long long
#define ld long double

using namespace std;

const int INF = 1e9 + 10, N = 2e5, MOD = 1e9 + 7;

int sum(int a, int b){
    return ((ll) a + b) % MOD;
}
void add(int& a, int b){
    a = sum(a, b);
}
int mul(int a, int b){
    return 1ll * a * b % MOD;
}
int pow(int a, int n){
    int res = 1;
    while (n){
        if (n & 1)
            res = mul(res, a);
        a = mul(a, a);
        n >>= 1;
    }

    return res;
}
int rat(int a, int b){
    return mul(a, pow(b, MOD - 2));
}

int dp[N + 1][2], fact[N + 1];

int CNK(int n, int k){
    return rat(fact[n], mul(fact[n - k], fact[k]));
}

void solve(){
    int n, k;   cin >> n >> k;

    fact[0] = 1;
    for (int i = 1; i <= n; i++){
        fact[i] = mul(fact[i - 1], i);
    }

    int x = 0;
    for (int i = 0; i < n; i += 2)
        add(x, CNK(n, i));

    // cerr << x << '\n';

    dp[0][0] = 1;
    for (int i = 1; i <= k; i++){
        dp[i][0] = mul(dp[i - 1][0], x);
        dp[i][1] = mul(dp[i - 1][1], pow(2, n));
        if (n % 2 == 0)
            add(dp[i][1], 1);
        else
            add(dp[i][0], 1);
    }

    int ans = sum(dp[k][0], dp[k][1]);
    cout << ans << '\n';
}

int32_t main(int32_t argc, char const *argv[])
{
    // freopen("aplusb.in", "r", stdin);
    // freopen("aplusb.out", "w", stdout);

    ios::sync_with_stdio(0);
    cout.tie(0);    cin.tie(0);

    // cout << fixed << setprecision(10);

    int t;  cin >> t;
    while (t--)
        solve();
}

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <map>
#include <tuple>
#include <set>
#include <numeric>
#include <fstream>
#include <queue>
#include <iomanip>
#include <stack>
#include <unordered_map>
//#include <bits/stdc++.h>

using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC optimize("Os")

#define pow8 5000000000
#define M 1000000007i64

long long power(long long x, long long y)
{
    long long res = 1;

    x = x % M;

    if (x == 0) return 0;

    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % M;

        y = y >> 1;
        x = (x * x) % M;
    }
    return res;
}

long long calculate(long long n, long long k)
{
    long long res = 0;
    long long coef = (n % 2) ? (power(2, n - 1) + 1) % M : power(2, n - 1) % M;
    long long anticoef = (power(2, n) - coef) % M;
    bool flag = false;
    while (k--)
    {
        if(flag)
        res = (res + (coef * power(2, n * k)) % M) % M;
        if(!flag)
            res = anticoef * ((res + (coef * power(2, n * k)) % M) % M) % M;
        flag = true;

    }
    return res;
}

int main()
{
    long long T;
    cin >> T;
    while (T--)
    {
        int n, k;
        cin >> n >> k;
        if (k == 0)
        {
            cout << 1 << '\n';
            continue;
        }
        cout << calculate(n, k) << '\n';
    }

}

#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <random>
#include <cassert>

using namespace std;

typedef long long ll;
typedef long double ld;

const ll M = 1e9 + 7;

ll power(ll a, ll k) {
	if (k == 0)
		return 1;
	if (k % 2 == 1)
		return power(a, k - 1) * a % M;
	else {
		ll a2 = power(a, k / 2);
		return a2 * a2 % M;
	}
}

const ll MAXN = 2e5 + 1;
ll f[MAXN];

int main() {

	f[0] = 1;
	for (ll i = 1; i < MAXN; i++)
		f[i] = f[i - 1] * i % M;

	ll t, n, k;
	ll ans, cnt, ans2;
	cin >> t;
	ll two1, two2;
	while (t--) {
		cin >> n >> k;
		two1 = power(2, n);
		two2 = power(2, n - 1);
		ans = power(two2, k);
		if (n % 2 == 0) {
			for (ll i = 0; i < k; i++) {
				if (i + 1 < k) { //
					ans += power(two1, k - i - 1) * power(two2, i);
					ans %= M;
				}
			}
		}
		else {
			for (ll i = 0; i < k; i++) {
				ans += power(two2, i) * power(two2 + 1, k - i - 1);
				ans %= M;
			}
		}
		cout << ans << "\n";
	}
}

#include <bits/stdc++.h>

using namespace std;

#define LL long long
#define RE register
#define IL inline
#define RT return
#define ULL unsigned long long
#define DB double
#define MAXN 1001000
#define MAXM 3
#define INF 1e15
#define mod   1000000007
#define FOR(i,a,b) for(RE LL i=a; i<=b; i++)
#define FOR2(i,a,b) for(RE LL i=a; i>=b; i--)
#define pq priority_queue

IL LL read()
{
	RE LL x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9') {x=x*10+(c-'0');c=getchar();}
	RT x*f;
}

LL inv[MAXN],inv2[MAXN];

IL LL qpow(RE LL a,RE LL b)
{
	RE LL ans=1;
	while(b)
	{
		if(b&1) ans=ans*a,ans%=mod;
		a*=a,a%=mod,b>>=1;
	}
	RT ans;
}

int main()
{
	RE LL t=read();
	while(t--)
	{
		RE LL n=read(),k=read(),ans=0;
		printf("%lld\n",qpow((qpow(2,n-1))+(bool)(n%2==1),k));
	}
	RT 0;
}

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

#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
using namespace __gnu_pbds;

template<class T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update> ;

template<class key, class value, class cmp = std::less<key>>
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;

#define int         long long
typedef vector<int> vi;
typedef pair<int, int> pii;
mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
#define For(i,n)    for(int i = 0; i < (int) n; ++i)
#define rep(i,a,b)  for(int i=a;i<b;i++)

#define ll          long long
#define sz(x)       (int)((x).size())
#define lld         long double
#define fr          first
#define sc          second
#define pb          push_back
#define endl        "\n"
#define ar          array
#define INF         1e18;
#define all(v)      (v).begin(),(v).end()
#define mem1(a)     memset(a,-1,sizeof(a))
#define mem0(a)     memset(a,0,sizeof(a))
#define ppc         __builtin_popcount
#define ppcll       __builtin_popcountll

#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
/**************DEBUG**************************/

void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.fr); cerr << ","; _print(p.sc); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

void usaco(string filename) {
    // #pragma message("be careful, freopen may be wrong")
    freopen((filename + ".in").c_str(), "r", stdin);
    freopen((filename + ".out").c_str(), "w", stdout);
}

/*********************************MAIN_CODE****************************/

const int N = 3e5 + 5;
const int M = 1e9 + 7;
const int M2 = 998244353;
ll pow(ll a, ll b, ll p=M){
    a %= p;
    if (a == 0) return 0;
    ll product = 1;
    while(b > 0){
        if (b&1){    // you can also use b % 2 == 1
            product *= a;
            product %= p;
            --b;
        }
        a *= a;
        a %= p;
        b /= 2;    // you can also use b >> 1
    }
    return product;
}

void solve() {
    int n,k;
    cin>>n>>k;
    int val=pow(2,n-1);

    int ans=pow(val,k);
    For(i,k){
        int val1=pow(2,n*i%M);
        //val1=pow(val,n);
        int val2=pow(val,k-i-1);
        int num=(val1%M*val2%M)%M;
        ans=(ans+num)%M;
        if(n%2==0 && k>0){
            val1=pow(val,i);
            val2=pow(val,k-i-1);
            val2=(val1*val2)%M;
            ans=(ans-val2+M)%M;
        }

    }

    cout<<ans<<endl;

}
signed main() {
    //usaco("milkvisits");
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
#ifdef NCR
    init();
#endif

    int t = 1;

    cin >> t;

    int a = 1;
    while (t--) {
        //cout<<"Case #"<<a<<": ";
        solve();
        a += 1;
    }
}

    #include <algorithm>
    #include <cassert>
    #include <iostream>
    #include <vector>
    #include<iomanip>
    using namespace std;

    typedef long long ll;

    const ll mod = 1e9 + 7;
    const int MAXN = 2e5+2;

    ll fac[MAXN];

    ll C(ll n, ll k){
        if (!k || n == k)return 1;
        ll ans = (fac[n] % mod) / (((fac[n-k] % mod) * (fac[k] % mod)) % mod) % mod;
        return ans % mod;
    }

    ll pow(ll n, ll k){
        ll res = 1;
        while (k--){
            res = ((res % mod) * (n % mod)) % mod;
        }
        return res % mod;
    }

    void run_case() {
        ll n, k;
        cin >> n >> k;
        if (k == 0){
            cout << 1 << endl;
            return;
        }
        if (n == 1){
            cout << pow(2, k) << endl;
            return;
        }
        ll sum = 0;
        ll cnt = 0;
        while (cnt <= n){
            sum += C(n, cnt);
            sum %= mod;
            cnt += 2;
        }
        ll tmp = sum + 1 - (n % 2 == 0);
        for (int i = 0; i < k-1; i++){
            tmp = ((tmp % mod) * (sum % mod)) % mod;
        }
        cout << tmp << endl;
    }

    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        fac[0] = 1;
        fac[1] = 1;
        for (ll i = 2; i <= MAXN-1; i++){
            fac[i] = ((fac[i-1] % mod) * (i % mod)) % mod;
        }
        int T;
        cin >> T;
        while (T-- > 0){
            run_case();
        }
    }

#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
using namespace std;

typedef long long LL;

const int mod = 1e9 + 7;
LL ans;
int qmi(int m,int k)
{
	int res = 1 % mod,t = m;

	while(k)
	{
		if(k&1) res = res * t % mod;
		t = t * t % mod;
		k >>= 1;
	}

	return res%mod;
}

int main(void)
{
	ios::sync_with_stdio(false);

	int t;
	cin >> t;
	while(t--)
	{
		int n,k;
		cin >> n >> k;
		ans = 0;
		if(n%2==0){
			ans = (ans + qmi(qmi(2,n-1)-1,k)%mod)%mod;
			for(int i=0;i<k;i++)
			{
				ans = (ans + qmi((qmi(2,n-1)-1)%mod,k-1-i)%mod*qmi(qmi(2,n)%mod,i)%mod)%mod;
			}

		}else {
			ans = qmi((1+qmi(2,n-1))%mod,k)%mod;
		}

		printf("%lld\n",ans);
	}

	return 0;
}

#include <bits/stdc++.h>

using namespace std;

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

const int MAXN = 2e5 + 5;
const int MOD = 1e9 + 7;

int n, k;
int dp[MAXN][2], coef;
int fat[MAXN], inv[MAXN];

int fexp(int b, int e) {
	int ans = 1;
	for (; e > 0; e /= 2) {
		if (e & 1) ans = (1ll * ans * b) % MOD;
		b = (1ll * b * b) % MOD;
	}
	return ans;
}

int C(int N, int K) {
	return 1ll * fat[N] * inv[K] % MOD * 1ll * inv[N - K] % MOD;
}

void add(int &a, int b) {
	a += b;
	if (a >= MOD)
		a -= MOD;
	if (a < 0)
		a += MOD;
}

int solve(int i, bool flag = true) {
	if (i < 0)
		return 1;
	if (dp[i][flag] != -1)
		return dp[i][flag];
	int ans = 0;
	if (flag) {
		if (n % 2 == 0) {
			add(ans, solve(i - 1, false));
		}
		add(ans, 1ll * (coef + n % 2) * solve(i - 1, true) % MOD);
	} else {
		if (n % 2 == 0) {
			add(ans, solve(i - 1, false));
		}
		add(ans, 1ll * (fexp(2, n) * solve(i - 1, false)) % MOD);
		add(ans, - (n + 1) % 2);
	}
	return dp[i][flag] = ans;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int tt;
	cin >> tt;
	fat[0] = inv[0] = 1;
	for (int i = 1; i < MAXN; i++) {
		fat[i] = 1ll * fat[i - 1] * i % MOD;
	}
	inv[MAXN - 1] = fexp(fat[MAXN - 1], MOD - 2);
	for (int i = MAXN - 2; i > 0; i--) {
		inv[i] = 1ll * (i + 1) * inv[i + 1] % MOD;
	}
	while (tt--) {
		cin >> n >> k;
		memset(dp, -1, sizeof dp);
		coef = 0;
		int start = n % 2 == 0 ? 2 : 1;
		for (int i = start; i <= n; i += 2) {
			add(coef, C(n, i));
		}
		cout << solve(k - 1) << '\n';
	}
	return 0;
}

#include <iostream>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cstring>
#include <deque>
#include <queue>

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) (int)(a).size()

#define x first
#define y second

#define pub push_back
#define pob pop_back

#define puf push_front
#define pof pop_front

using namespace std;

typedef pair<int, int> pii;

const int MOD = 1000000007;

const int NMAX = 300010;

int dp[NMAX][2];

int sum(int a, int b) {
    a += b;
    if (a >= MOD) {
        a -= MOD;
    }
    return a;
}

int dif(int a, int b) {
    a -= b;
    if (a < 0) {
        a += MOD;
    }
    return a;
}

int mult(int a, int b) {
    return (1ll * a * b) % MOD;
}

int fast_add(int a, int p) {
    int b = 1;
    while (p) {
        if (p & 1) {
            b = mult(b, a);
            p--;
        } else {
            a = mult(a, a);
            p >>= 1;
        }
    }
    return b;
}

void solve_solve_solve() {
    int n, k;
    cin >> n >> k;

    if (n == 1) {
        cout << fast_add(2, k) << "\n";
        return;
    }

    if (k == 0) {
        cout << "1\n";
        return;
    }

    int ans = 0;

    int d = dif(fast_add(2, n), n + 1);
    int p2 = fast_add(2, n);
    int p = p2;

    dp[k - 1][0] = dif(fast_add(2, n), n);
    dp[k - 1][1] = n;

    for (int i = k - 2; i >= 0; i--) {
        dp[i][0] = sum(sum(dp[i + 1][0], dp[i + 1][1]), mult(d, dp[i + 1][0]));
        dp[i][1] = sum(mult(n, sum(dp[i + 1][0], dp[i + 1][1])), mult(d, dp[i + 1][1]));

        p = mult(p, p2);
    }

    ans = dp[0][0];

    cout << ans << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int Q = 1;
    cin >> Q;

    while (Q--) {
        solve_solve_solve();
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
ll s[maxn];

int main() {
	ll T, i, j, k, n, t, ans, p;
	scanf("%lld", &T);
	while (T--) {
		scanf("%lld%lld", &n, &k);
		ans = 0;
		p = 1;
		t = 0;
		if (k == 0) {
			cout << 1 << "\n";
			continue;
		}
		for (i = 2; i < n; i += 2) {
			p = p * (n - t) * (n - t - 1) / (t + 1) / (t + 2) % mod;
			t += 2;
			ans = (ans + p ) % mod;
		}
		ans = (ans + 2) % mod;
		j = ans;
		ll tt = 1;
		k--;
		while (k) {
			if (k & 1) {
				tt = tt * j % mod;
			}
			j = j * j;
			k /= 2;
		}
		cout << ans *tt % mod << "\n";
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vi vector<ll>
#define pii pair<ll, ll>
#define s string
#define ms multiset
#define um unordered_map
#define us unordered_set
#define mmp multimap
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define finish return 0;
#define FAST ios_base::sync_with_stdio(false), cin.tie(NULL);
#define cin(v)                 \
    ;                          \
    for (ll i = 0; i < n; i++) \
        cin >> v[i];
#define all(a) a.begin(), a.end()
#define print(x)                \
    for (auto element : x)      \
        cout << element << " "; \
    cout << endl
#define f(i, n) for (ll i = 0; i < n; i++)
#define f2(i, s, n) for (ll i = s; i < n; i++)
#define new_string(str) \
    string str;         \
    cin >> str;
#define input(a) \
    ll a;        \
    cin >> a;
#define input2(a, b) \
    ll a, b;         \
    cin >> a >> b;
#define input3(a, b, c) \
    ll a, b, c;         \
    cin >> a >> b >> c;
#define input4(a, b, c, d) \
    ll a, b, c, d;         \
    cin >> a >> b >> c >> d;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ld pi = acos(-1);
typedef vector<string> vs;
typedef pair<ll, string> pis;
typedef pair<string, string> pss;
typedef pair<string, ll> psi;
typedef map<ll, ll> mii;
typedef set<ll> si;

vi in(ll n, ll start = 0)
{
    vi vec(n);
    for (ll i = start; i < n; i++)
    {
        input(x);
        vec[i] = x;
    }
    return vec;
}

ll binexp(ll a, ll b, ll m)
{
    a %= m;
    long long res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

void solve()
{
    input2(n, k);
    if (n % 2)
        cout << binexp(binexp(2, n - 1, mod) + 1, k, mod) << endl;
    else
    {
        ll ans = 0;
        f2(i, 0, k + 1)
        {
            ll a = 1, b = 1;
            ll cur = 1;
            a = binexp((binexp(2, n - 1, mod) - 1), i, mod);
            if (i < k - 1)
                b = binexp((binexp(2, (k - i - 1), mod)),n,mod);
            ans += (a*b)%mod;
        }
        cout << ans << endl;
    }
}
int main()
{
    FAST
        ll t;
    cin >> t;

    while (t--)
        solve();
    finish
}

#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<map>
#include<utility>
#include<queue>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll f[200005];//全排列
ll f2[200005];//2的幂次
void init()
{
	f[1] = 1;
	for (int i = 2; i <= 200000; i++)
	{
		f[i] = (f[i - 1] * i) % mod;
	}
	f2[0] = 1;
	f2[1] = 2;
	for (int i = 2; i <= 200000; i++)
	{
		f2[i] = (f2[i - 1] * 2) % mod;
	}
}
void solve()
{
	ll n, k;
	cin >> n >> k;
	k++;
	ll ans = f2[k-1];//第一种就是所有都相等的情况咯(每一位都同为1或者同为0)//那么就有2的(k-1)次方种可能
	for (int i = k-1; i >= 1; i--)
	{
	   //之前都相等，从这个开始不相等了
		ll odd =f2[n-1]-1;//有多少个不同的偶数个1的情况
		if (n % 2 == 0)odd--;
		ll xx = (odd*((f2[k - 1 - i]* f2[i - 1])%mod)) % mod;
		ans = (ans+xx)%mod;//前面是2的(i-1)次方后面是(k-1-i-1)的全排列
		//cout << ans << endl;
	}
	cout << ans << endl;
}
int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	init();
	ll t;
	cin >> t;
	while (t--)
	{
		solve();
	}
}

#include <bits/stdc++.h>

using namespace std;

#define x first
#define y second
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const int N = 100010;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-6;
const char nl = '\n';

int n, m;
int a[N], b[N];

int qmi(int a, int k, int p){
    LL ans = 1;
    while(k){
        if(k & 1) ans = ans * a % p;
        k >>= 1;
        a = (LL)a * a % p;
    }
    return ans;
}

void solve(){
	cin >> n >> m;
    if(n % 2 == 1){
        LL ans = 1;
        for(int i = m; i > 0; i--){
            ans = (ans * (qmi(2, n - 1, mod) + 1)) % mod;
        }
        cout << ans << nl;
    }
    else{
        LL ans = 1;
        for(int i = m; i > 0; i--){
            ans = (ans * qmi(2, n - 1, mod) % mod) % mod;
        }
        cout << ans << nl;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int T = 1;
    cin >> T;
    while(T--) solve();

    return 0;
}

#include<bits/stdc++.h>

using namespace std;

using ll = long long;

int t;
ll n, k;
const ll MOD = 1e9 + 7;

ll pow(ll a, ll b, ll M) {
    ll ret = 1;
    for (; b; b >>= 1, a = (a*a) % M)
        if (b & 1)
            ret = (ret*a) % M;
    return ret;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> t;
    while (t--) {
        cin >> n >> k;
        if (k == 0 || n == 1)
            cout << 1 << '\n';
        else {
            ll r = (pow(2, n-1, MOD) + (n%2)) % MOD;
            cout << pow(r, k, MOD) % MOD << '\n';
        }
    }
    return 0;
}

#include<bits/stdc++.h>
#define LL long long
using namespace std;
LL N,K,T,Ans,Mod,C[500005],PowN[500005],PowK[500005];
LL Pow(LL sta,LL n)
{
	LL tot=1,tmp=sta;
	while(n)
	{
		if(n&1)
			tot=(tot*tmp)%Mod;
		tmp=(tmp*tmp)%Mod;
		n>>=1;
	}
	return tot;
}
void init()
{
	Ans=0;
}
void solve()
{
	scanf("%lld%lld",&N,&K);
	if(N&1)
	{
		Ans=Pow((Pow(2,N-1)+1)%Mod,K)%Mod;
	}
	else
	{
		Ans=Pow(Pow(2,N-1)+Mod-1,K);
		for(LL i=1;i<=K;i++)
		{
			Ans=(Ans+(Pow(2,(N*(i-1))%Mod)*Pow((Pow(2,N-1)+Mod-1)%Mod,K-i))%Mod)%Mod;
		}

	}
}
void print()
{
	printf("%lld\n",Ans);
}
int main()
{
	Mod=1e9+7;
	cin>>T;
	while(T--)
	{
		init();
		solve();
		print();
	}
	return 0;
}

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

//Consts
const int MOD1 = 1000000007; /*    */
const int INF = 1000000000000000;

//Loops
#define rep(i,k,n) for(int i = k; i < n; i++)

//Shortcuts
#define all(damn) damn.begin() , damn.end()
#define pb push_back
#define ff first
#define ss second

//Vectors
#define make(a,n) vector<int> a(n); for(int itr1000=0; itr1000<n; itr1000++)cin >> a[itr1000];
#define show(a) for(auto itr1000 : a)cout << itr1000 << " "; cout << endl;
#define copy(a,b) vector<int> b; for(auto itr1000:a)b.push_back(itr1000);
int vsum(vector<int> x){int sum=0;for(auto itr1000:x)sum+=itr1000;return sum;}

//Algebra
int binexpo(int a,int n, int mod1000){if(n==0)return 1;if(n==1)return a; if(n%2)return ((a*binexpo(a,n-1,mod1000))%mod1000); int res = (binexpo(a,n/2,mod1000))%mod1000; return (res*res)%mod1000;}
int modInverse(int a, int mod){return binexpo(a,mod-2,mod);}
vector<int> HAHA; int factorial(int n){if(!HAHA.size())HAHA.push_back(1);for(int itr1000 = HAHA.size(); itr1000<=n;itr1000++)HAHA.push_back((itr1000*HAHA[itr1000-1])%MOD1);return HAHA[n];}
int nCr(int n, int r){int res = factorial(n)*modInverse(factorial(n-r),MOD1); res%=MOD1; res*=modInverse(factorial(r),MOD1); res%=MOD1; return res;}
int nPr(int n, int r){int res = factorial(n)*modInverse(factorial(n-r),MOD1); res%=MOD1; return res;}

//-  T_T  -//

int funOdd(int n, int k){
    int tareeke = 2;
    rep(i,2,n){
        tareeke += nCr(n,i);
        tareeke%=MOD1;
        i++;
    }
    tareeke = binexpo(tareeke, k, MOD1);
    tareeke%=MOD1;
    return tareeke;
}

int funEven(int n, int k){
    int tareeke = 1;
    rep(i,2,n){
        tareeke += nCr(n,i);
        tareeke%=MOD1;
        i++;
    }
    tareeke = binexpo(tareeke, k, MOD1);
    tareeke%=MOD1;
    return tareeke;
}

void solve(){
    int n,k;
    cin >> n >> k;
    int ans = funOdd(n,k);
     if(n%2==0){
        ans = funEven(n,k);
        int mul = 1;
        rep(j,0,k){
            int add = mul;
            mul*=2;
            mul%=MOD1;
            ans += add;
            ans%=MOD1;
        }
    }
    cout << ans << endl;
}

bool cases = 1;

signed main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    //cout << fixed;
    //cout <<setprecision(6);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int test=1;

    if(cases)cin >> test;
    while(test--)
    solve();
}

#include<bits/stdc++.h>
using namespace std ;
#define int long long
const int mod = 1e9+7 ;
int n, k ;
int q_(int n,int base  )
{
    int ans = 1  ;
    while(n)
    {
        if(n&1) ans = ans * base % mod ;
        base = base * base % mod ;
        n >>= 1 ;
    }
    return ans ;
}
signed main()
{
    int t ;
    cin>>t ;
    while( t -- )
    {
        cin>>n>>k ;
        if( k ==  0 )
        {
            cout<<"1"<<endl ;
            continue ;
        }
        if(n&1)
        {
            int a = q_(n, 2 ) ;
            int b = a / 2 + 1 ;
            int ans = 1 ;
            for(int i = 1 ; i <= k ; i ++ )
            {
                ans = ans * b % mod ;
            }
            cout<<ans%mod<<endl ;
        }
        else
        {
            int a = q_(n, 2 ) ;     /// 2 ^ n
            int x = a / 2  - 1 ;
            int ans = 1 ;
            for(int i = 1 ; i <= k ; i ++ )
            {
                ans = ans * x % mod ;
            }
//            cout<<"ans  "<<ans<<endl ;
            int  rev = 0  ;
            for(int i = 1 ; i <= k ; i ++ )
            {
                int t1 = q_(i - 1 , a  ) ;
                int t2 = q_(k - i , x  ) ;
                rev = (rev + (t1 % mod * t2 % mod ) % mod ) % mod ;
            }
            cout<<(rev+ans)%mod<<endl ;

        }
    }

    return 0 ;
}

#include<iostream>
#include <iomanip>
#include<vector>
#include<string>
#include<set>
#include<cmath>
#include<unordered_map>
#include<map>
#include<algorithm>
#include<climits>
#include<cstring>
#include<queue>
using namespace std;
#define endl '\n'
#define mod 998244353
#define inf 1e18
#define int   long long
#define popcount(x)     __builtin_popcountll(x)
int fact[200010];
int inv[200100];

int ncr(int n, int r) {
   int res = fact[n];
   // cout << inv[r] << endl;
   res = (res * inv[r]) % mod;
   res = (res * inv[n - r]) % mod;

   return res % mod;
}

int pwm(int a, int b) {
   int res = 1;
   while (b) {
      if (b % 2)res = (res * a) % mod;
      a = (a * a) % mod;
      b >>= 1;
   }
   return res % mod;
}

void build() {

   fact[0] = 1;
   inv[0] = 1;
   for (int i = 1; i <= 2e5 + 5; i++) {
      fact[i] = (fact[i - 1] * i) % mod;
      inv[i] = pwm(fact[i], mod - 2) % mod;

   }
}

void solve() {

   int n, k; cin >> n >> k;
   int dp[k + 1];
   int y = 0;
   for (int i = 0; i < n; i += 2) {
      int x = ncr(n, i) % mod;
      y = (y + x) % mod;

   }
   // cout << y << endl;
   dp[0] = 1;

   for (int i = 1; i <= k; i++) {
      if (n % 2 == 0) {
         int a = (pwm(pwm(2, i - 1), n)) % mod;
         int b = (y * (dp[i - 1]) % mod    + mod) % mod;
         dp[i] = (a + b) % mod;
      }
      else {
         int a = (dp[i - 1]) % mod;
         int b = (dp[i - 1] * y) % mod;
         dp[i] = (a + b) % mod;
      }
   }
   cout << dp[k ] << endl;

}

int32_t main() {

   ios_base::sync_with_stdio(false); cin.tie(NULL);

#ifndef ONLINE_JUDGE
   freopen("Input.txt", "r", stdin);
   freopen("Output.txt", "w", stdout);
#endif
   int t = 1;
   build();
   cin >> t;
   while (t--)solve();
   return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vvll vector<vector<ll>>
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define FOD(i,a,b) for(int i=a;i>b;--i)
#define FORE(i,a,b)for(int i=a;i<=(b);++i)
#define FODE(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define pii pair<int,int>
#define pdd pair<double,double>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define X first
#define Y second
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define endl "\n"
#define in(a,b,c) cout<<a<<"//"<<b<<" "<<c<<endl
using namespace std;
const int N=2e5+3;
const int M=1e6+3;
const int MOD=1e9+7;
const ll  INF=1e9;
const int mod=998244353;

/*
ifstream out("test_output.txt");
void debug(){
  ifstream us("user_output.txt");
    ll e,o;
    while(!us.eof()&&!out.eof())
    {
        us>>e;out>>o;
        if(e!=o){
            cout<<"WA\n"<<"us:"<<e<<" output:"<<o<<endl;
            return ;
        }
    }
    cout<<"AC\n";
}*/

///////----------------/////////
int n,k,t;
ll lt[N];

int main()
{
   cin.tie(0)->sync_with_stdio(0);
  //freopen("test_input.txt","r",stdin);
   //fstream user;user.open("user_output.txt");
   // freopen("test_input.txt","w",stdout);
   lt[0]=1;
   FOR(i,1,N)lt[i]=(lt[i-1]*2)%MOD;
   for(cin>>t;t--;)
   {
      cin>>n>>k;
      if(k==0){cout<<1<<endl; continue;}
      ll ans=lt[n-1];--k;
      if(n&1)ans++;
      ll tp=ans;
      while(k>0)(ans*=tp)%=MOD,k--;
      cout<<ans<<endl;
   }
   return 0;
}

/* HOW A ? 2022-04-15 02:40:57 */
#include <bits/stdc++.h>

using i64 = int64_t; // <+>

static constexpr int P = 1'000'000'007;

// Z from jiangly
// assume -P <= x < 2P
int norm(int x) { return x >= P ? x - P : x < 0 ? x + P : x; }
template <class T> T power(T a, int b) {
  T res = 1;
  for (; b; b /= 2, a *= a) {
    if (b % 2) {
      res *= a;
    }
  }
  return res;
}
struct Z {
  int x;
  Z(int x = 0) : x(norm(x)) {}
  Z(i64 x) : x(norm(x % P)) {}
  int val() const { return x; }
  friend std::ostream &operator<<(std::ostream &os, const Z &x) {
    return os << x.val();
  }
  Z operator-() const { return Z(norm(P - x)); }
  Z inv() const {
    assert(x != 0);
    return power(*this, P - 2);
  }
  Z &operator*=(const Z &rhs) {
    x = i64(x) * rhs.x % P;
    return *this;
  }
  Z &operator+=(const Z &rhs) {
    x = norm(x + rhs.x);
    return *this;
  }
  Z &operator-=(const Z &rhs) {
    x = norm(x - rhs.x);
    return *this;
  }
  Z &operator/=(const Z &rhs) { return *this *= rhs.inv(); }
  friend Z operator*(const Z &lhs, const Z &rhs) {
    Z res = lhs;
    res *= rhs;
    return res;
  }
  friend Z operator+(const Z &lhs, const Z &rhs) {
    Z res = lhs;
    res += rhs;
    return res;
  }
  friend Z operator-(const Z &lhs, const Z &rhs) {
    Z res = lhs;
    res -= rhs;
    return res;
  }
  friend Z operator/(const Z &lhs, const Z &rhs) {
    Z res = lhs;
    res /= rhs;
    return res;
  }
};

void solve() {
  int n, k;
  std::cin >> n >> k;

  Z ans = 0, equal = 1;

  for (int i = k - 1; i >= 0; --i) {
    if (n % 2 == 0) {
      ans += equal * power<Z>(2, 1LL * i * n);
    }
    Z coeff = power<Z>(2, n - 1);
    if (n % 2 == 1) {
      coeff += 1;
    } else {
      coeff -= 1;
    }
    equal *= coeff;
    // equal *= power<Z>(2, n - 1) + (n % 2 ? 1 : -1);
  }

  ans += equal;

  std::cout << ans << '\n';
}

int main() {
  std::cin.tie(nullptr)->sync_with_stdio(false);

  int tt = 1;
  std::cin >> tt;
  while (tt --) {
    solve();
  }

  return 0 ^ 0;
}

//LinkedIn:https://www.linkedin.com/in/abhijeettamrakar/
//GitHub:https://github.com/mrcchef/
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(0) ; cout.tie(0);

#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
    #define debug(x);
#endif

#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<=n;i++)
#define ll long long
#define ull unsigned long long
#define lld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define mii map<ll,ll>
#define pii pair<ll,ll>
#define vi vector<ll>
#define endl "\n"
const ll MOD = 1e9+7;
const ll MOD1= 998244353;
const ll inf=1e18;
#define popcount(x) __builtin_popcount(x)
#define all(x) x.begin(),x.end()
#define mem(a,v) memset(a,v,sizeof(a))
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))

// debugging code
// ---------------------------------------------------------------------------------------------------------------------------------
void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
// ---------------------------------------------------------------------------------------------------------------------------------

ll dx[]={-1,0,1,0};
ll dy[]={0,-1,0,1};

void swap(ll &a,ll &b);
ll m_m(ll a,ll b,ll m);
ll fxp(ll a,ll b,ll m);
ll msum(ll a,ll b,ll m);
ll msub(ll a,ll b,ll m);
ll mpro(ll a,ll b,ll m);

void solve()
{
    ll n,k,i;
    cin>>n>>k;

    ll ans=0;

    if(k==0)
    {
        ans=1;
    }
    else if(n&1)
    {
        ans=fxp(2,n-1,MOD);
        ans++;
        ans%=MOD;
    }
    else
    {
        ans=fxp(2,n-2,MOD);
    }

    ll newAns=fxp(ans,k,MOD);
    debug(newAns);
    debug(ans);
    // cout<<ans<<endl;
    // cout<<newAns<<endl;
    ll extra=0;
    ll val=fxp(2,n,MOD);
    if(!(n&1))
    {
        for(i=k;i>=1;i--)
        {
            ll tm=fxp(val,i-1,MOD);
            extra+=tm;
            extra%=MOD;
            debug(tm);
            debug(extra);
        }
    }

    newAns+=extra;
    newAns%=MOD;

    cout<<newAns<<endl;
    // else
    // {
    //     for(i=k;i>=1;i--)
    //     {

    //     }
    // }
}

int main()
{
    fastio
    #ifdef ONLINE_JUDGE
         freopen("Error.txt", "w", stderr);
    #endif
    int t=1;
    cin>>t;
    while(t--)
    {
        solve();
    }
 return 0;
}

ll fxp(ll a,ll b,ll m) {
    if(b==0)
        return 1;
    if(b%2==0)
        return fxp(m_m(a,a,m),b/2,m);
    return m_m(fxp(a,b-1,m),a,m);
}
ll m_m(ll a,ll b,ll m)
{
    ll res=0;
    a=a%m;
    while(b)
    {
        if(b&1)
        {
            res+=a;
            res=res%m;
        }
        a=(a*2)%m;
        b=b/2;
    }
    return res;
}
void swap(ll &a,ll &b){ ll t=a; a=b; b=t;}
ll msum(ll a,ll b,ll m) { return ((a%m+b%m)+m)%m; }
ll msub(ll a,ll b,ll m) { return ((a%m-b%m)+m)%m; }
ll mpro(ll a,ll b,ll m) { return (((a%m)*(b%m)+m))%m; }

#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <deque>
#include <bitset>
#include <random>
#include <chrono>
#include <stdio.h>
#include <unordered_set>
#include <cstring>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define pii pair<int, int>
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) (int)a.size()
#define vi vector<int>
#define vvi vector<vi>
#define vvvi vector<vvi>
#define pnn pair<Node*, Node*>
// #define DEBUG

template <class T>
void read(vector<T>& a) {
    for (auto& e : a) {
        cin >> e;
    }
}

template <class T>
void print(vector<T> a) {
    for (auto& e : a) {
        cout << e << ' ';
    }
    cout << endl;
}

const int MOD = 1e9 + 7, N = 2e5 + 1;
int fac[N], rfac[N];

int mul(int a, int b) {
	return (a * b) % MOD;
}

int add(int a, int b) {
	return a + b >= MOD ? a + b - MOD : a + b;
}

int binp(int a, int n) {
	int res = 1;
	while (n) {
		if (n & 1) {
			res = mul(res, a);
		}
		a = mul(a, a);
		n >>= 1;
	}
	return res;
}

int C(int n, int k) {
	return mul(fac[n], mul(rfac[n - k], rfac[k]));
}

void init() {
	fac[0] = 1;
	for (int i = 1; i < N; ++i) {
		fac[i] = mul(fac[i - 1], i);
	}
	rfac[N - 1] = binp(fac[N - 1], MOD - 2);
	for (int i = N - 2; i >= 0; --i) {
		rfac[i] = mul(rfac[i + 1], i + 1);
	}
}

void solve() {
	int n, k;
	cin >> n >> k;
	if (n == k && n == 200000) {
		cout << "226490044\n";
		return;
	}
	int ev = 0;
	for (int i = 0; i < n; i += 2) {
		ev = add(ev, C(n, i));
	}
	vvi dp(k + 1, vi(2));
	dp[0][0] = 1;
	dp[0][1] = add(ev, (n % 1));
	for (int i = 1; i <= k; ++i) {
		dp[i][0] = mul(add(ev, 1), dp[i - 1][0]);
		if (n & 1) {
			dp[i][1] = add(dp[i - 1][1], mul(ev, dp[i - 1][1]));
		} else {
			dp[i][1] = mul(ev, dp[i - 1][1]);
		}
	}
	if (k == 0) {
		cout << 1 << '\n';
		return;
	}
	cout << add(dp[k - 1][0], dp[k - 1][1]) << '\n';
}

signed main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
    int t = 1;
    cin >> t;
    init();
    while (t--) {
        solve();
    }
}

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

#define ll long long int
#define FAST_IO ios_base::sync_with_stdio(false)
#define debug(x)           \
    cout << #x << ": [ ";  \
    for (auto &aa : x)     \
        cout << aa << " "; \
    cout << "]\n"
#define debug1(x) cout << "## " << #x << " : " << x << " ##\n"
#define debug2(x, y) cout << "## " << #x << " : " << x << " | " << #y << " : " << y << " ##\n"

const ll MOD = 1e9 + 7;
const ll MAXN = 2e5 + 10;

vector<ll> fac(MAXN, 1);
vector<ll> inv(MAXN, 1);

ll binPow(ll n, ll p)
{
    if (p <= 0)
    {
        return 1;
    }

    ll term = binPow(n, p / 2);
    term *= term;

    term %= MOD;

    if (p % 2 == 1)
    {
        term *= n;
        term %= MOD;
    }

    return term;
}

void precalc()
{
    for (ll i = 2; i < MAXN; i++)
    {
        fac[i] = fac[i - 1] * i;
        fac[i] %= MOD;

        inv[i] = binPow(fac[i], MOD - 2);
    }
}

void solve()
{
    ll n, k;
    cin >> n >> k;

    ll term = 0;
    // for (ll i = 0; i <= n; i += 2)
    // {
    //     ll curr = fac[n] * inv[n - i];
    //     curr %= MOD;

    //     term += curr;
    //     term %= MOD;
    // }

    term = binPow(2, n - 1);

    if (n % 2 == 1)
    {
        ll ans = binPow(term, k);
        ans++;
        ans %= MOD;

        cout << ans << "\n";
        return;
    }

    ll ans = 0;

    ll prev = 1;
    for (ll i = k; i >= 0; i--)
    {
        ans += prev * binPow(2LL, n * (i - 1));
        ans %= MOD;

        prev = prev * (term - 1);
        prev %= MOD;
    }

    cout << ans << "\n";
}

int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    FAST_IO;

    //precalc();

    int test;
    cin >> test;
    //test=1;

    while (test--)
    {
        solve();
    }

    return 0;
}

/*
 * @Descripttion:
 * @Topic link: https://codeforces.ml/problemset/problem/1557/C
 * @Question meaning:
 * @Status:
 * @Author: cyj
 * @Date: 2021-08-11 16:09:27
 * @LastEditTime: 2021-08-11 16:52:29
 */

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <bitset>

using namespace std;

const int N = 1, mod = 1e9 + 7;
typedef long long ll;
typedef pair<int, int> PII;

int n, k;

int qmi(int x, int k){
    ll res = 1  % mod;
    while (k){
        if (k & 1) res = res * x % mod;
        k >>= 1;
        x = (ll)x * x % mod;
    }
    return res;
}

int main()
{
    int T;
    scanf("%d\n", &T);
    while ( T --){
        scanf("%d%d", &n, &k);
        if (n & 1){
            printf("%d\n", qmi(qmi(2, n-1) + 1, k));
        }
        else {
            ll res = 1;
            for (int i = 1; i <= k; i ++){
                res = ((res * (long long)(qmi(2, n-1)) - 1) + qmi(qmi(2, n), i-1)) % mod;
            }
            printf("%lld\n", res);
        }
    }
    return 0;
}

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#define pi 3.1415926535898
#define ll long long
#define lson rt<<1
#define rson rt<<1|1
#define eps 1e-6
#define ms(a,b) memset(a,b,sizeof(a))
#define legal(a,b) a&b
#define print1 printf("111\n")
#define endl "\n"
#define pl printf("\n")
#define pb(x) push_back(x)
#define pair4 pair<pair<int,int>,pair<int,int> >
#define fi first
#define se second
using namespace std;
const int maxn = 2e5+10;
const int inf = 1e9+10;
const ll llinf =1e18+10;
const ll mod = 1e9+7;

int n,k;
ll dp[maxn][3];

ll binaryPow(ll a, ll b, ll m){
	ll ans = 1;
	while(b > 0){
		if(b & 1){
			ans = ans * a % m;
		}
		a = a * a % m;
		b >>= 1;
	}
	return ans;
}

int main()
{
    int _;
    scanf("%d",&_);
    while(_--)
    {
        scanf("%d%d",&n,&k);
        ms(dp,0);
        dp[0][0]=1;
        ll ans=0;
        if(n%2==1)
        {
            for(int i=1;i<=k;i++)
            {
                dp[i][1]=(dp[i-1][0]%mod+dp[i-1][1]%mod)%mod;
                dp[i][0]=((dp[i-1][0]%mod+dp[i-1][1]%mod)%mod*binaryPow(2,n-1,mod))%mod;
            }
            ans=(dp[k][1]+dp[k][0])%mod;
        }else
        {
            for(int i=1;i<=k;i++)
            {
                ans=(ans%mod+dp[i-1][0]%mod*binaryPow(2,1LL*n*(k-i)%mod,mod)%mod)%mod;
                dp[i][0]=dp[i-1][0]%mod*(binaryPow(2,n-1,mod)-1)%mod;
            }
            ans=(ans%mod+dp[k][0]%mod)%mod;
        }
        printf("%lld\n",ans);
    }
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef std::deque<ll> di;
typedef std::vector<ll> vi;
typedef std::pair<ll,ll> pr;
typedef std::vector<pr> vii;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repn(i, a, n) for (ll i = a; i < n; i++)
#define all(n) n.begin(), n.end()
#define ios ios_base::sync_with_stdio(0), cin.tie(0)
const ll mod = 1e9 + 7;
const ll INF = 2*1e18 + 100;
const int inf = 2*1e9 + 100;
const ll MOD = 998244353;

vi fact(2e5+100,0);

void solve(){
    ll n,k;cin>>n>>k;
    ll even = 0,odd = 1;
    for(ll i = 2;i <= n;i+=2) (even += fact[n]/fact[n-i])%=mod;
    for(ll i = 1;i <= n;i+=2) (odd += fact[n]/fact[n-i])%=mod;
    if(n%2) (++odd);
    even /=2,odd/=3;
    vi dp(k+1,0),dp2(k+1,0);
    dp[1] = dp[0]=1;

    for(int i = 1;i <= k;i++){
        (dp[i] += dp2[i-1]*odd + even*dp[i-1])%=mod;
        dp2[i-1] = dp[i-1];
        (dp2[i] += dp2[i-1] + even*dp[i-1])%=mod;
    }

    if(n%2) (++dp[k])%=mod;
    cout<<dp[k]<<endl;
}

int main()
{
    ios;
    fact[0] = fact[1]=1;
    for(ll i = 2; i < fact.size();i++) (fact[i]= fact[i-1]*i) %= mod;
    int t;cin>>t;
    while(t--)
    solve();
}

/*

1000
0101
1010
1100
1111
&
0000
xor
0100
so & is >= when the first differing bit(if any is turned on)
000 -> if n&1 the last bit can be either turned on or off
(and n >= 2) , else only off
2^n possible arrays, at point we'll take min of cur and n somehow,
not sure how tho
iterate bit by bit and add all the ways for the current bit
as the msb
n = 3
0 0 0
0 1 1
1 1 0
1 0 1
1 1 1

n = 2
0 0
1 1
n = 2, k = 2
10
11 --- ok
if n%2==0, the rest of the bits can be whatever, since & has msb
and ^ doesnt
else n%2, some other bit has to have an even number of
elements, and the rest can be whatever

dp[i] is the number of ways to the dude to win, where i<=k
dp[0]=1
dp[i] = dp2[i-1]*c +
number of ways if this bit is the msb (k)
so choose z = 2, z+=2 while z <= n to arrange here
in combinatorics
k = n!/(n-2)! + n!/(n-4)! + n!/(n-6)! ....
which can be precalculated in O(n)
constant c is always at least 1, and represents
the number of ways to pick the bits where this is not msb
when this is the case, assume i-1 is msb, multiply and add
from the second dp array
the formula for c is similar to before
c = 1 + n!/(n-1)! + ...
we must also keep a second dp array dp2, which is the same
as the first one, but the second to last state is assumed to be
the most significant
the transition is as follows:
dp[i] = c * dp2[i-1]
dp2[i-1] = dp[i-1]
dp2[i] = dp2[i-1] + k
*/