#include <bits/stdc++.h>
using namespace std;
#define int              long long int
#define double           long double
#define print(a)         for(auto x : a) cout << x << " "; cout << endl


const int M = 1000000007;
const int N = 3e5+9;
const int INF = 2e9+1;
const int LINF = 2000000000000000001;

inline int power(int a, int b, int mod=M) {
    int x = 1;
    a %= mod;
    while (b) {
        if (b & 1) x = (x * a) % mod; 
        a = (a * a) % mod;
        b >>= 1;
    }
    return x;
}


//_ ***************************** START Below *******************************



//* Case 2 : n <= 1e9  &&  r <= 20

//* With Modulo : 
//* TC = O(r + logM)	SC = O(1)
int nCr(int n, int r){
	if(r>n || r<0) return 0;
	
	if(r>n-r) r = n-r; //* optimization nCr == nCn-r
	
	int res = 1;
	for(int i=1; i<=r; i++){
		res = (res * (n-i+1)) % M;
	}
	
	int rFact = 1;
	for(int i=1; i<=r; i++){
		rFact = (rFact * i)%M;
	}
	
	res = (res%M * power(rFact, M-2, M)  ) % M;	
	
	return res;
}



//* Without Modulo : 
//* TC = O(r)	, SC = O(1)
int nCr2(int n, int r){
	if(r>n || r<0) return 0;
	
	if(r>n-r) r = n-r; //* optimization nCr == nCn-r
	
	int res = 1;
	for(int i = 1; i <= r; i++){
	    res = (res * (n - i + 1)) / i;
	}
	
	return res;
}



//* recursive 
//* 	TC = O(rLogM)	SC = O(r)
int nCr3(int n, int r, int M) {
    if (r > n || r < 0) return 0;
    if (r == 0) return 1;
    
    if (r > n - r) r = n - r;

    int res = (n * nCr3(n-1,r-1, M) ) % M;
    res = (res * power(r, M - 2, M)) % M;

    return res;
}





int consistency(int n, int r){
	
	return nCr(n, r);

}















int practice(int n, int r){
	
	

    return 0;
}





void solve() {
	
    int n, r;
    cin>> n >> r;
    
    
    cout << consistency(n, r) << endl;


}





int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}