#include<bits/stdc++.h> usingnamespacestd; typedeflonglong ll; constint P = 1e9 + 7; constint U = 200000; int f[U + 3], rf[U + 3]; ll inv(ll a, ll m){ return (a == 1 ? 1 : inv(m % a, m) * (m - m / a) % m); } voidinit(){ f[0] = 1; for (int i = 1; i <= U; i++) f[i] = (ll)f[i - 1] * i % P; rf[U] = inv(f[U], P); for (int i = U; i; i--) rf[i - 1] = (ll)rf[i] * i % P; } ll C(int n, int m){ if (m < 0 || m > n) return0; return (ll)f[n] * rf[m] % P * rf[n - m] % P; } ll powmod(ll a, ll b, ll P){ ll t = 1; for (; b; b >>= 1, a = a * a % P) if (b & 1) t = t * a % P; return t; } int T, m; ll n; intmain(){ init(); scanf("%d", &T); while (T--) { scanf("%lld%d", &n, &m); ll ans = 0; int t = m >> 1; for (int i = 0; i <= t; i++) { ans = (ans + C(t, i) * powmod(m - 2 * i, n, P) % P) % P; } ans = ans * powmod(powmod(2, t, P), P - 2, P) % P; printf("%lld\n", ans); } return0; }