//组合数2,取值在1e5
//Cab = a! / (a - b)! * b!
#include<iostream>
using namespace std;
using ll = long long;
const ll N = 1e4 + 9, mod = 1e9 + 7;
ll fact[N], infact[N];//阶乘,逆元阶乘ll qmi(ll a, ll k, ll p)//逆元模板
{ll res = 1;while (k){if (k & 1) res = res * a % p;a = a * a % p;k >>= 1;}return res;
}int main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);fact[0] = infact[0] = 1;//初始化数组for (ll i = 1; i < N; ++i){fact[i] = fact[i - 1] * i % mod;infact[i] = infact[i - 1] * qmi(i, mod - 2, mod) % mod;}int n; cin >> n;while (n--){int a, b; cin >> a >> b;//多取模的原因是防止超出long long的数据范围cout << fact[a] * infact[a - b] % mod * infact[b] % mod << '\n';}return 0;
}