//https://blog.csdn.net/xiaoming_p/article/details/79644386
#include<bits/stdc++.h>
using namespace std;
int n,a,b;
typedef long long ll;
const int maxn = 2002;
int MOD = 1e9+7;
ll f[maxn],rf[maxn];
long long inv(int i){
if(i==1) return 1;
return (MOD-MOD/i)*inv(MOD%i)%MOD;
}
void init(){
f[0] = rf[0] = 1;
for(int i = 1;i<maxn;i++){
f[i] = f[i-1]*i%MOD;
rf[i] = rf[i-1]*inv(i)%MOD;
}
}
int main()
{
init();
cin>>n;
while(n--){
cin>>a>>b;
cout<<f[a]*rf[b]%MOD*rf[a-b]%MOD<<endl;
}
return 0;
}