'''
先递推算出所有结果,然后查表
'''
dp = [[0]*2001 for _ in range(2001)]
dp[1][0], dp[1][1] = 1, 1
for i in range(2, 2001):
dp[i][0] = 1
for j in range(1, i+1):
dp[i][j] = dp[i-1][j] + dp[i-1][j-1]
n = int(input())
for _ in range(n):
a, b = map(int, input().split())
print(dp[a][b] % 1000000007)