/*
Permuation pair
https://w...content-available-to-author-only...f.com/problems/PERMUTATION2?tab=statement
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
ll powerOf(ll n, ll r, ll m) {
ll res = 1;
ll base = n;
while(r>0) {
if(r%2==1) {
res = (res*base)%m;
}
base = (base*base)%m;
r /=2;
}
return res;
}
vector<ll> fact, invfact;
void preComputeFactorial(ll n, ll m)
{
fact.resize(n + 1);
invfact.resize(n + 1);
fact[0] = 1;
for (ll i = 1; i <= n; i++)
{
fact[i] = (i * fact[i - 1]) % m;
}
invfact[n] = powerOf(fact[n], m - 2, m);
for (ll i = n - 1; i >= 0; i--)
{
invfact[i] = ((i + 1) * invfact[i + 1]) % m;
}
}
ll totalPairs(ll n, ll k) {
ll allPairs = 0;
if(k > ((2*n)-1)) {
allPairs = 0;
} else if(k>n) {
allPairs = (2*n -k +1)/2;
}else if(k<=n){
allPairs = (k-1)/2;
}
return allPairs;
}
ll nCr(ll n, ll r, ll m) {
if(r>n) return 0;
return (((fact[n] * invfact[r])%m)*invfact[n-r])%m;
}
void solve() {
ll n, k;
cin >> n >> k;
ll allPairs = totalPairs(n, k);
bool pos = 1;
int ans = 0;
for (ll i = 1; i <= allPairs; i++) {
ll pie = (((nCr(allPairs, i, MOD) * fact[n-i] )% MOD) * powerOf(2, i, MOD)) % MOD;
if (pos) {
ans = (ans + pie) % MOD;
} else {
ans = (ans - pie + MOD) % MOD;
}
pos = 1-pos;
}
cout << ans << endl;
return;
}
int main() {
int t;
cin>>t;
ll n = 100005;
preComputeFactorial(n, MOD);
while(t--) {
solve();
}
return 0;
}
LyoKUGVybXVhdGlvbiBwYWlyCmh0dHBzOi8vdy4uLmNvbnRlbnQtYXZhaWxhYmxlLXRvLWF1dGhvci1vbmx5Li4uZi5jb20vcHJvYmxlbXMvUEVSTVVUQVRJT04yP3RhYj1zdGF0ZW1lbnQKKi8KI2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hb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yOwogICAgfQogICAgcmV0dXJuIGFsbFBhaXJzOwp9CgpsbCBuQ3IobGwgbiwgbGwgciwgbGwgbSkgewoJaWYocj5uKSByZXR1cm4gMDsKCXJldHVybiAoKChmYWN0W25dICogaW52ZmFjdFtyXSklbSkqaW52ZmFjdFtuLXJdKSVtOwp9Cgp2b2lkIHNvbHZlKCkgewogICAgbGwgbiwgazsKICAgIGNpbiA+PiBuID4+IGs7CiAgICBsbCBhbGxQYWlycyA9IHRvdGFsUGFpcnMobiwgayk7CiAgICBib29sIHBvcyA9IDE7CiAgICBpbnQgYW5zID0gMDsKICAgIGZvciAobGwgaSA9IDE7IGkgPD0gYWxsUGFpcnM7IGkrKykgewogICAgICAgIGxsIHBpZSA9ICgoKG5DcihhbGxQYWlycywgaSwgTU9EKSAqIGZhY3Rbbi1pXSApJSBNT0QpICogcG93ZXJPZigyLCBpLCBNT0QpKSAlIE1PRDsKICAgICAgICBpZiAocG9zKSB7CiAgICAgICAgICAgIGFucyA9IChhbnMgKyBwaWUpICUgTU9EOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGFucyA9IChhbnMgLSBwaWUgKyBNT0QpICUgTU9EOwogICAgICAgIH0KICAgICAgICBwb3MgPSAxLXBvczsKICAgIH0KICAgIGNvdXQgPDwgYW5zIDw8IGVuZGw7CiAgICByZXR1cm47Cn0KCmludCBtYWluKCkgewoJaW50IHQ7CgljaW4+PnQ7CglsbCBuID0gMTAwMDA1OwoJcHJlQ29tcHV0ZUZhY3RvcmlhbChuLCBNT0QpOwoJd2hpbGUodC0tKSB7CgkgICAgc29sdmUoKTsKCX0KCXJldHVybiAwOwp9