#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 10, p = 1e9 + 7;
inline long long ksm(long long a, long long b, const long long p) {
  long long c = 1;
  for (a %= p; b; a = a * a % p, b >>= 1)
    if (b & 1) c = c * a % p;
  return c;
}
void solve() {
  long long n, k, res = 0;
  cin >> n >> k;
  long long bs = ksm(2, n - 1, p), bs2 = bs * 2 % p;
  if (n & 1)
    cout << ksm(bs + 1, k, p) << '\n';
  else {
    for (long long x = k; x; --x) {
      long long a = ksm(bs + p - 1, k - x, p), b = ksm(bs2, x - 1, p);
      res = (res + a * b % p) % p;
    }
    res = (res + ksm(bs + p - 1, k, p)) % p;
    cout << res << '\n';
  }
}
signed main() {
  cout.tie(0)->sync_with_stdio(0);
  long long _;
  for (cin >> _; _--;) solve();
  return 0;
}
