#include
#include
using namespace std;
const int N = 2000;
const int MOD = 1007;
int c[N+1][N+1];
void initc()
{
c[0][0] = 1;
for(int i=1; i<=N; i++)
{
c[i][0] = 1;
for(int j=1; j<=N; j++)
c[i][j] = (c[i-1][j-1] + c[i-1][j]) % MOD;
}
}
int main()
{
int t, m, n;
initc();
cin >> t;
while(t--)
{
cin >> m >> n;
cout << c[n][m] << endl;
}
return 0;
}