import java.util.*;
public class Main {
static final int N = 2010, MOD = (int) 1e9 + 7;
static int[][] C = new int[N][N];
static int n;
public static void main(String[] args) {
init();
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
while (n -- > 0) {
int i = sc.nextInt(), j = sc.nextInt();
System.out.println(C[i][j]);
}
}
static void init() {
for (int i = 0; i < N; i++)
for (int j = 0; j <= i; j++) {
if (j == 0) C[i][j] = 1;
else C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;
}
}
}
import java.util.Scanner;
public class Main {
static final int N = (int)1e7 + 10, mod = (int)1e9 + 7;
static long[] high = new long[N], low = new long[N];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//预处理
high[0] = 1; low[0] = 1;
for (int i = 1; i < N; i++) {
high[i] = high[i - 1] * i % mod;
low[i] = quick_mi(high[i], mod - 2, mod);
}
int q = sc.nextInt();
while (q -- > 0) {
int n = sc.nextInt(), m = sc.nextInt();
System.out.println(C(n, m));
}
sc.close();
}
static long C(int n, int m) {
return high[n] * low[m] % mod * low[n - m] % mod;
}
static long quick_mi(long a, long k, long q) {
long res = 1;
while (k != 0) {
if ((k & 1) == 1) res = res * a % q;
a = a * a % q;
k >>= 1;
}
return res;
}
}
import java.util.*;
public class Main {
static int n, p;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t -- > 0) {
long a = sc.nextLong(), b = sc.nextLong();
p = sc.nextInt();
long res = lucas(a, b);
System.out.println(res);
}
}
static long lucas(long a, long b) {
if (a < p && b < p) return C(a, b);
return C(a % p, b % p) * lucas(a / p, b / p) % p;
}
static long C(long a, long b) {
if (a == b || b == 0) return 1;
long res = 1;
for (long i = 1, j = a; i <= b; i++, j--) {
res = res * j % p;
res = res * quickMi(i, p - 2) % p;
}
return res;
}
static long quickMi(long a, long k) {
long res = 1;
while (k != 0) {
if ((k & 1) == 1) res = res * a % p;
a = a * a % p;
k >>= 1;
}
return res;
}
}
无模数
直接使用高精度或者BigInteger