#include<stdio.h>
#include<stdlib.h>
long long a[1005][1005];
int main()
{
int t,n,m,i,j;
for(i=0;i<=1000;i++){
a[0][i]=1;
}
for(i=1;i<=1000;i++){
for(j=i;j<=1000;j++){
a[i][j]=a[i-1][j-1]+a[i][j-1];
if(a[i][j]>=1000000007) a[i][j]%=1000000007;
}
}
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
if(n<m) printf("%lld\n",a[n][m]);
else printf("%lld\n",a[m][n]);
}
return 0;
}