#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
const int mod=1e9+7;
int c[2005][2005];
void f1()
{
int i,j;
for(i=0;i<2005;i++)
for(j=0;j<=i;j++)if(!j)c[i][j]=1;
else c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
}
int main()
{
f1();
int n,a,b;
scanf("%d",&n);
while(n--){
scanf("%d%d",&a,&b);
printf("%d\n",c[a][b]);
}
return 0;
}