#include <bits/stdc++.h>
using namespace std;
int n, k;
long long dp[200005];
long long getmod(long long x) {
  long long tmp = 2;
  long long res = 1;
  while (x) {
    if (x & 1) res = (res * tmp) % 1000000007;
    x >>= 1;
    tmp = (tmp * tmp) % 1000000007;
  }
  return res;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    dp[0] = 1;
    for (int i = 1; i <= k; i++) {
      if (n & 1) {
        dp[i] = (dp[i - 1] * getmod(n - 1) + dp[i - 1]) % 1000000007;
      } else {
        dp[i] =
            (dp[i - 1] * getmod(n - 1) - dp[i - 1] + 1000000007) % 1000000007 +
            getmod((long long)n * (i - 1));
        dp[i] %= 1000000007;
      }
    }
    cout << dp[k] << endl;
  }
  return 0;
}
