#include <bits/stdc++.h>
using namespace std;
const int D = 46;
const int MOD = 1000000007;
int sum[1005][1005];
int f[D + 1][1005][1005];
int g[D + 1][1005];
int c[2010][2010];
int res[1010][1010];
int fac[1010];
void update(int &x, int y) {
  x += y;
  if (x >= MOD) x -= MOD;
}
int main() {
  for (int i = 0; i <= 2000; i++) {
    c[i][0] = c[i][i] = 1;
    for (int j = 1; j < i; j++) c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % MOD;
  }
  for (int i = 0; i <= 1000; i++) f[1][i][i] = 1;
  for (int i = 2; i <= D; i++) {
    for (int k = 0; k <= 1000; k++) {
      sum[0][k] = f[i - 1][0][k];
      for (int j = 1; j <= 1000; j++)
        sum[j][k] = (sum[j - 1][k] + f[i - 1][j][k]) % MOD;
    }
    for (int j = 1; j <= 1000; j++)
      for (int k = j; k <= 1000; k++) f[i][j][k] = sum[j - 1][k - j];
  }
  for (int i = 1; i <= D; i++)
    for (int j = 0; j <= 1000; j++)
      for (int k = 0; k <= 1000; k++) update(g[i][k], f[i][j][k]);
  int hhh = 0;
  for (int i = 1; i <= D; i++)
    for (int j = 0; j <= 1000; j++)
      if (g[i][j]) {
        int cnt = g[i][j];
        for (int k = j; k <= 1000; k++) {
          int t = k - j - i;
          if (t >= 0) update(res[k][i], (long long)c[t + i][i] * cnt % MOD);
        }
      }
  int T;
  fac[0] = 1;
  for (int i = 1; i <= 1000; i++) fac[i] = (long long)fac[i - 1] * i % MOD;
  for (cin >> T; T--;) {
    int n, m;
    scanf("%d%d", &n, &m);
    int out = (long long)res[n][m] * fac[m] % MOD;
    printf("%d\n", out);
  }
  return 0;
}

### Prompt

Generate a CPP solution to the following problem:

The sequence of integer pairs (a1, b1), (a2, b2), ..., (ak, bk) is beautiful, if the following statements are fulfilled: 

  * 1 ≤ a1 ≤ b1 < a2 ≤ b2 < ... < ak ≤ bk ≤ n, where n is a given positive integer; 
  * all numbers b1 - a1, b2 - a2, ..., bk - ak are distinct. 



For the given number n find the number of beautiful sequences of length k. As the answer can be rather large, print the remainder after dividing it by 1000000007 (109 + 7).

Input

The first line contains integer t (1 ≤ t ≤ 2·105) — the number of the test data.

Each of the next t lines contains two integers n and k (1 ≤ k ≤ n ≤ 1000).

Output

For each test from the input print the answer to the problem modulo 1000000007 (109 + 7). Print the answers to the tests in the order in which the tests are given in the input.

Examples

Input

6
1 1
2 1
2 2
3 1
3 2
3 3


Output

1
3
0
6
2
0

Note

In the first test sample there is exactly one beautiful sequence: (1, 1).

In the second test sample, the following sequences are beautiful: 

  * (1, 1); 
  * (1, 2); 
  * (2, 2). 



In the fourth test sample, the following sequences are beautiful: 

  * (1, 1); 
  * (1, 2); 
  * (1, 3); 
  * (2, 2); 
  * (2, 3); 
  * (3, 3). 



In the fifth test sample, the following sequences are beautiful: 

  * (1, 1), (2, 3); 
  * (1, 2), (3, 3). 



In the third and sixth samples, there are no beautiful sequences.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int D = 46;
const int MOD = 1000000007;
int sum[1005][1005];
int f[D + 1][1005][1005];
int g[D + 1][1005];
int c[2010][2010];
int res[1010][1010];
int fac[1010];
void update(int &x, int y) {
  x += y;
  if (x >= MOD) x -= MOD;
}
int main() {
  for (int i = 0; i <= 2000; i++) {
    c[i][0] = c[i][i] = 1;
    for (int j = 1; j < i; j++) c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % MOD;
  }
  for (int i = 0; i <= 1000; i++) f[1][i][i] = 1;
  for (int i = 2; i <= D; i++) {
    for (int k = 0; k <= 1000; k++) {
      sum[0][k] = f[i - 1][0][k];
      for (int j = 1; j <= 1000; j++)
        sum[j][k] = (sum[j - 1][k] + f[i - 1][j][k]) % MOD;
    }
    for (int j = 1; j <= 1000; j++)
      for (int k = j; k <= 1000; k++) f[i][j][k] = sum[j - 1][k - j];
  }
  for (int i = 1; i <= D; i++)
    for (int j = 0; j <= 1000; j++)
      for (int k = 0; k <= 1000; k++) update(g[i][k], f[i][j][k]);
  int hhh = 0;
  for (int i = 1; i <= D; i++)
    for (int j = 0; j <= 1000; j++)
      if (g[i][j]) {
        int cnt = g[i][j];
        for (int k = j; k <= 1000; k++) {
          int t = k - j - i;
          if (t >= 0) update(res[k][i], (long long)c[t + i][i] * cnt % MOD);
        }
      }
  int T;
  fac[0] = 1;
  for (int i = 1; i <= 1000; i++) fac[i] = (long long)fac[i - 1] * i % MOD;
  for (cin >> T; T--;) {
    int n, m;
    scanf("%d%d", &n, &m);
    int out = (long long)res[n][m] * fac[m] % MOD;
    printf("%d\n", out);
  }
  return 0;
}

```