#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
const int mod = 1e9+7;
using ll = long long;
ll fact[MAXN + 1] , ifact[MAXN + 1];

ll power(ll base , ll exp){
	int res = 1;
	while(exp>0){
		if(exp%2 == 1)res = (res*base)%mod;
		base =  (base*base)%mod;
		exp/=2;
	}
	return res;
}

void pre(){
	fact[0]=ifact[0]=1;
	for(int i = 1 ; i<=MAXN ;i++){
		fact[i] = (fact[i-1]*i)%mod;
	}
	ifact[MAXN] = power(fact[MAXN],mod-2);
	for(int i = MAXN - 1; i>=0 ;i--){
		ifact[i] = (ifact[i+1]*(i+1))%mod;
	}
}

ll nCr(int n,int r){
	if(r>n || r<0)return 0;
	return (((fact[n]*ifact[r])%mod)*ifact[n-r])%mod;
}
int main() {
   pre();
   int t,n,r;
   cin>>t;
   while(t--){
   	cin>>n>>r;
   	cout<<nCr(n,r)<<endl;
   }
   return 0;
}