#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 1, M = 1e9 + 7;
int fact[N], ifact[N];
int Pow(int a, int b) {
int res = 1;
while (b != 0) {
if (b & 1)
res = ((ll) res * a) % M;
a = ((ll) a * a) % M;
b >>= 1;
}
return res;
}
inline int nCk(int n, int k) {
if (k > n)
return 0;
return (((ll) fact[n] * ifact[k]) % M * ifact[n - k]) % M;
}
inline int calcP(int n, int m) {
if (m == 0 && n == 0)
return 1;
if (m == 0 || abs(n) > m || (abs(n) & 1) != (m & 1))
return 0;
return nCk(m, (m + n) >> 1);
}
int main(int argc, char **argv) {
fact[0] = ifact[0] = 1;
for (int i = 1; i < N; ++i) {
fact[i] = ((ll) fact[i - 1] * i) % M;
ifact[i] = Pow(fact[i], M - 2);
}
int T;
scanf("%d", &T);
while (T-- != 0) {
int n, m;
scanf("%d%d", &n, &m);
int p = calcP(n, m);
int q = Pow(2, m);
printf("%lld\n", ((ll) p * Pow(q, M - 2)) % M);
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKCmNvbnN0IGludCBOID0gMmU1ICsgMSwgTSA9IDFlOSArIDc7CmludCBmYWN0W05dLCBpZmFjdFtOXTsKCmludCBQb3coaW50IGEsIGludCBiKSB7CglpbnQgcmVzID0gMTsKCXdoaWxlIChiICE9IDApIHsKCQlpZiAoYiAmIDEpCgkJCXJlcyA9ICgobGwpIHJlcyAqIGEpICUgTTsKCQlhID0gKChsbCkgYSAqIGEpICUgTTsKCQliID4+PSAxOwoJfQoJcmV0dXJuIHJlczsKfQoKaW5saW5lIGludCBuQ2soaW50IG4sIGludCBrKSB7CglpZiAoayA+IG4pCgkJcmV0dXJuIDA7CglyZXR1cm4gKCgobGwpIGZhY3Rbbl0gKiBpZmFjdFtrXSkgJSBNICogaWZhY3RbbiAtIGtdKSAlIE07Cn0KCmlubGluZS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