#include using namespace std; using ll = long long; ll mod = 1e9 + 7; ll qpow(ll a, ll b) { ll ans = 1; for (; b; b >>= 1, a = a * a % mod) if (b & 1) ans = ans * a % mod; return ans; } ll inv(ll x) { return qpow(x, mod - 2); } int main() { ios::sync_with_stdio(false), cin.tie(nullptr); ll T, n, m; cin >> T; while (T--) { cin >> n >> m; cout << (qpow(qpow(2, n) - 1, m - 1) * 2 + (n & 1)) * inv(3) % mod << endl; } }