#include <bits/stdc++.h>
long long n, k;
long long fastPower(long long base, long long power, long long mod) {
  base = base % mod;
  long long ans = 1;
  while (power) {
    if (power & 1) {
      ans = ans * base;
      ans = ans % mod;
    }
    base = base * base;
    base = base % mod;
    power = power >> 1;
  }
  ans = ans % mod;
  return ans;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%lld %lld", &n, &k);
    if (!k) {
      printf("1\n");
      continue;
    }
    long long ans = 0;
    if (n & 1) {
      ans = fastPower(fastPower(2, n - 1, 1000000007) + 1, k, 1000000007);
    } else {
      ans = fastPower(2, n - 1, 1000000007);
      for (long long i = 2; i <= k; ++i) {
        ans = (((fastPower(2, n - 1, 1000000007) - 1) * ans) % 1000000007 +
               fastPower(2, (i - 1) * n, 1000000007)) %
              1000000007;
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
