#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 *******************************


vector<int> fact(N+1);
vector<int> iFact(N+1);


void compute(){
	fact[0] = 1;
	
	for(int i=1; i<=N; i++){
		fact[i] = ( fact[i-1] * i%M )%M;
	}
	
	//* TC = O( N * logM )
	// iFact[0] = 1;
	// for(int i=1; i<=N; i++){
	// 	iFact[i] = power(fact[i], M-2, M);
	// }
	
	//* TC = O( N + logM )
	iFact[N] = power(fact[N], M-2, M);
	for(int i=N-1; i>=0; i--){
		iFact[i] = (iFact[i+1] * (i+1))%M;
	}
	
	
}




//* Case 1 : n <= 1e6  &&  r <= 1e6

int nCr(int n, int r){
	if(r>n || r<0) return 0;
	
	return (fact[n] * ( iFact[r]%M * iFact[n-r]%M )%M ) % M;
}


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

}















int practice(int n, int r){
	
	

    return 0;
}





void solve() {
	
    static int _ = (compute(), 0);
    
    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;
}