#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int MAXN = 1010, MAXK = 60;
inline int add(int a, int b) {
  int ret = a + b;
  if (ret >= MOD) ret -= MOD;
  return ret;
}
inline int mul(int a, int b) {
  long long int ret = (long long int)a * b;
  if (ret >= MOD) ret %= MOD;
  return ret;
}
int dp[MAXN][MAXN][MAXK];
int binomial[2 * MAXN][2 * MAXN];
int faktorijel[MAXN];
void postavi() {
  dp[0][0][0] = 1;
  dp[0][0][1] = 1;
  for (int i = 0; i < MAXN; i++)
    for (int j = 0; j < MAXN; j++)
      for (int k = 0; k < MAXK; k++) {
        if (i - 1 >= 0) dp[i][j][k] = add(dp[i][j][k], dp[i - 1][j][k]);
        if (i - 1 >= 0 && j - i >= 0 && k - 1 >= 0)
          dp[i][j][k] = add(dp[i][j][k], dp[i - 1][j - i][k - 1]);
      }
  faktorijel[0] = 1;
  for (int i = 1; i < MAXN; i++) faktorijel[i] = mul(faktorijel[i - 1], i);
}
int povrh(int n, int k) {
  if (k > n) return 0;
  if (n < 0 || k < 0) return 0;
  if (n == k || k == 0) return 1;
  int &ret = binomial[n][k];
  if (ret != -1) return ret;
  return ret = add(povrh(n - 1, k), povrh(n - 1, k - 1));
}
int x_brojeva_suma_y(int x, int y) { return povrh(y + x - 1, x - 1); }
int main() {
  postavi();
  memset(binomial, -1, sizeof(binomial));
  int test;
  scanf("%d", &test);
  for (int br = 0; br < test; br++) {
    int n, k;
    scanf("%d %d", &n, &k);
    int rj = 0;
    n = n - (k - 1) - 1;
    int sum = 0;
    if (k >= MAXK) {
      printf("0\n");
      continue;
    }
    for (int i = 0; i <= n; i++) {
      int val = mul(dp[MAXN - 1][i][k], faktorijel[k]);
      sum = add(sum, val);
      rj = add(rj, mul(sum, x_brojeva_suma_y(k, n - i)));
    }
    printf("%d\n", rj);
  }
  return 0;
}

### Prompt

Develop a solution in Cpp to the problem described below:

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 MOD = 1000000007;
const int MAXN = 1010, MAXK = 60;
inline int add(int a, int b) {
  int ret = a + b;
  if (ret >= MOD) ret -= MOD;
  return ret;
}
inline int mul(int a, int b) {
  long long int ret = (long long int)a * b;
  if (ret >= MOD) ret %= MOD;
  return ret;
}
int dp[MAXN][MAXN][MAXK];
int binomial[2 * MAXN][2 * MAXN];
int faktorijel[MAXN];
void postavi() {
  dp[0][0][0] = 1;
  dp[0][0][1] = 1;
  for (int i = 0; i < MAXN; i++)
    for (int j = 0; j < MAXN; j++)
      for (int k = 0; k < MAXK; k++) {
        if (i - 1 >= 0) dp[i][j][k] = add(dp[i][j][k], dp[i - 1][j][k]);
        if (i - 1 >= 0 && j - i >= 0 && k - 1 >= 0)
          dp[i][j][k] = add(dp[i][j][k], dp[i - 1][j - i][k - 1]);
      }
  faktorijel[0] = 1;
  for (int i = 1; i < MAXN; i++) faktorijel[i] = mul(faktorijel[i - 1], i);
}
int povrh(int n, int k) {
  if (k > n) return 0;
  if (n < 0 || k < 0) return 0;
  if (n == k || k == 0) return 1;
  int &ret = binomial[n][k];
  if (ret != -1) return ret;
  return ret = add(povrh(n - 1, k), povrh(n - 1, k - 1));
}
int x_brojeva_suma_y(int x, int y) { return povrh(y + x - 1, x - 1); }
int main() {
  postavi();
  memset(binomial, -1, sizeof(binomial));
  int test;
  scanf("%d", &test);
  for (int br = 0; br < test; br++) {
    int n, k;
    scanf("%d %d", &n, &k);
    int rj = 0;
    n = n - (k - 1) - 1;
    int sum = 0;
    if (k >= MAXK) {
      printf("0\n");
      continue;
    }
    for (int i = 0; i <= n; i++) {
      int val = mul(dp[MAXN - 1][i][k], faktorijel[k]);
      sum = add(sum, val);
      rj = add(rj, mul(sum, x_brojeva_suma_y(k, n - i)));
    }
    printf("%d\n", rj);
  }
  return 0;
}

```