#include <bits/stdc++.h>
using namespace std;
const int maxn = 1002;
const int MAXN = 3111;
const int mod = (int)(1e9 + 7);
const int INF = (~0u >> 2);
void read(int& ret) {
  char ch;
  while (ch = getchar(), ch < '0' || ch > '9')
    ;
  ret = ch ^ 0x30;
  while (ch = getchar(), ch >= '0' && ch <= '9') ret = ret * 10 + (ch ^ 0x30);
}
long long f[maxn][maxn];
long long dp[maxn][maxn];
long long C[MAXN][MAXN];
long long F[MAXN];
int main() {
  ios::sync_with_stdio(false);
  int i, j, k;
  f[0][0] = 1;
  for (k = 1; k < maxn; ++k) {
    for (i = maxn - 1; i >= k; --i) {
      for (j = 1; j <= 46; ++j) {
        f[i][j] += f[i - k][j - 1];
        if (f[i][j] >= mod) f[i][j] -= mod;
      }
    }
  }
  for (i = 0; i < MAXN; ++i) C[i][i] = C[i][0] = 1;
  F[0] = 1;
  for (i = 1; i < MAXN; ++i) {
    F[i] = F[i - 1] * i % mod;
  }
  for (i = 1; i < MAXN; ++i) {
    for (j = 1; j < i; ++j) {
      C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
      if (C[i][j] >= mod) C[i][j] -= mod;
    }
  }
  for (k = 1; k < maxn; ++k) {
    for (j = 1; j <= 46 && j <= i; ++j) {
      for (i = 1; i <= k; ++i) {
        dp[k][j] += f[i][j] * C[k - i + j][j];
        if (dp[k][j] >= mod) dp[k][j] %= mod;
      }
    }
    for (j = 1; j <= 46 && j <= i; ++j) {
      dp[k][j] = dp[k][j] * F[j] % mod;
    }
  }
  int x, y;
  int T;
  cin >> T;
  while (T--) {
    cin >> x >> y;
    cout << dp[x][y] << endl;
  }
  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 maxn = 1002;
const int MAXN = 3111;
const int mod = (int)(1e9 + 7);
const int INF = (~0u >> 2);
void read(int& ret) {
  char ch;
  while (ch = getchar(), ch < '0' || ch > '9')
    ;
  ret = ch ^ 0x30;
  while (ch = getchar(), ch >= '0' && ch <= '9') ret = ret * 10 + (ch ^ 0x30);
}
long long f[maxn][maxn];
long long dp[maxn][maxn];
long long C[MAXN][MAXN];
long long F[MAXN];
int main() {
  ios::sync_with_stdio(false);
  int i, j, k;
  f[0][0] = 1;
  for (k = 1; k < maxn; ++k) {
    for (i = maxn - 1; i >= k; --i) {
      for (j = 1; j <= 46; ++j) {
        f[i][j] += f[i - k][j - 1];
        if (f[i][j] >= mod) f[i][j] -= mod;
      }
    }
  }
  for (i = 0; i < MAXN; ++i) C[i][i] = C[i][0] = 1;
  F[0] = 1;
  for (i = 1; i < MAXN; ++i) {
    F[i] = F[i - 1] * i % mod;
  }
  for (i = 1; i < MAXN; ++i) {
    for (j = 1; j < i; ++j) {
      C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
      if (C[i][j] >= mod) C[i][j] -= mod;
    }
  }
  for (k = 1; k < maxn; ++k) {
    for (j = 1; j <= 46 && j <= i; ++j) {
      for (i = 1; i <= k; ++i) {
        dp[k][j] += f[i][j] * C[k - i + j][j];
        if (dp[k][j] >= mod) dp[k][j] %= mod;
      }
    }
    for (j = 1; j <= 46 && j <= i; ++j) {
      dp[k][j] = dp[k][j] * F[j] % mod;
    }
  }
  int x, y;
  int T;
  cin >> T;
  while (T--) {
    cin >> x >> y;
    cout << dp[x][y] << endl;
  }
  return 0;
}

```