#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 200000 + 10, M = 1000000007;
int fact[N];
int power(int x, int n) {
if(n == 0) return 1;
if(n == 1) return x;
int y = power(x, n/2);
y = (ll)y*y%M;
if(n&1) y = (ll)y*x%M;
return y;
}
int C(int n, int k) {
return int((ll)fact[n] * power((ll)fact[n-k] * fact[k] % M, M-2) % M);
}
int main() {
fact[0] = 1;
for(int i=1; i<N; ++i)
fact[i] = (ll)fact[i-1]*i%M;
int n, m;
int t;
scanf("%d", &t);
while(t--) {
scanf("%d%d", &n, &m);
n = abs(n);
if(((m-n)&1) || n>m) puts("0");
else printf("%d\n", int((ll)C(m, n+(m-n)/2) * power(power(2, m), M-2) % M));
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnR5cGVkZWYgbG9uZyBsb25nIGxsOwp1c2luZyBuYW1lc3BhY2Ugc3RkOwpjb25zdCBpbnQgTiA9IDIwMDAwMCArIDEwLCBNID0gMTAwMDAwMDAwNzsKaW50IGZhY3RbTl07CgppbnQgcG93ZXIoaW50IHgsIGludCBuKSB7CglpZihuID09IDApIHJldHVybiAxOwoJaWYobiA9PSAxKSByZXR1cm4geDsKCWludCB5ID0gcG93ZXIoeCwgbi8yKTsKCXkgPSAobGwpeSp5JU07CglpZihuJjEpIHkgPSAobGwpeSp4JU07CglyZXR1cm4geTsKfQoKaW50IEMoaW50IG4sIGludCBrKSB7CglyZXR1cm4gaW50KChsbClmYWN0W25dICogcG93ZXIoKGxsKWZhY3Rbbi1rXSAqIGZhY3Rba10gJSBNLCBNLTIpICUgTSk7Cn0KCgppbnQgbWFpbigpIHsKCWZhY3RbMF0gPSAxOwoJZm9yKGludCBpPTE7IGk8TjsgKytpKQoJCWZhY3RbaV0gPSAobGwpZmFjdFtpLTFdKmklTTsKCWludCBuLCBtOwoJaW50IHQ7CglzY2FuZigiJWQiLCAmdCk7Cgl3aGlsZSh0LS0pIHsKCQlzY2FuZigiJWQlZCIsICZuLCAmbSk7CgkJbiA9IGFicyhuKTsKCQlpZigoKG0tbikmMSkgfHwgbj5tKSBwdXRzKCIwIik7CgkJZWxzZSBwcmludGYoIiVkXG4iLCBpbnQoKGxsKUMobSwgbisobS1uKS8yKSAqIHBvd2VyKHBvd2VyKDIsIG0pLCBNLTIpICUgTSkpOwoJfQoJcmV0dXJuIDA7Cn0=