#include <bits/stdc++.h>
using namespace std;
namespace C {
const int N = 200002, mod = 1000000007;
int n, i = 1, F[N], I[N];
int pow(int a, int b, int mod, int r = 1) {
  for (int i = b; i; i >>= 1, a = (1LL * a * a) % mod)
    if (i & 1) r = (1LL * r * a) % mod;
  return r;
}
void init() {
  for (F[0] = 1; i < N; i++) F[i] = (1LL * F[i - 1] * i) % mod;
  i--;
  for (I[N - 1] = pow(F[N - 1], mod - 2, mod); i; i--)
    I[i - 1] = (1LL * I[i] * i) % mod;
}
int nCr(int n, int r) {
  return n >= r ? (1LL * F[n] * ((1LL * I[n - r] * I[r]) % mod)) % mod : 0;
}
}  // namespace C
const int N = 1001;
int dp0[N][N][46], dp1[N][46];
int f(int sum, int p, int k) {
  if (k == 0) return sum == 0;
  if (p == 0) return 0;
  if (~dp0[sum][p][k]) return dp0[sum][p][k];
  int res = f(sum, p - 1, k);
  if (sum >= p) {
    res += f(sum - p, p - 1, k - 1);
    res %= C::mod;
  }
  return dp0[sum][p][k] = res % C::mod;
}
int solve(int n, int k) {
  if (~dp1[n][k]) return dp1[n][k];
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    int x = f(i, i, k);
    int y = 1LL * C::nCr(n - i + k, k) * C::F[k] % C::mod;
    ans += 1LL * x * y % C::mod;
    ans %= C::mod;
  }
  return dp1[n][k] = ans;
}
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  C::init();
  memset(dp0, -1, sizeof dp0);
  memset(dp1, -1, sizeof dp1);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    if (k > 45) {
      cout << 0 << "\n";
    } else {
      cout << solve(n, k) << "\n";
    }
  }
}

### 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;
namespace C {
const int N = 200002, mod = 1000000007;
int n, i = 1, F[N], I[N];
int pow(int a, int b, int mod, int r = 1) {
  for (int i = b; i; i >>= 1, a = (1LL * a * a) % mod)
    if (i & 1) r = (1LL * r * a) % mod;
  return r;
}
void init() {
  for (F[0] = 1; i < N; i++) F[i] = (1LL * F[i - 1] * i) % mod;
  i--;
  for (I[N - 1] = pow(F[N - 1], mod - 2, mod); i; i--)
    I[i - 1] = (1LL * I[i] * i) % mod;
}
int nCr(int n, int r) {
  return n >= r ? (1LL * F[n] * ((1LL * I[n - r] * I[r]) % mod)) % mod : 0;
}
}  // namespace C
const int N = 1001;
int dp0[N][N][46], dp1[N][46];
int f(int sum, int p, int k) {
  if (k == 0) return sum == 0;
  if (p == 0) return 0;
  if (~dp0[sum][p][k]) return dp0[sum][p][k];
  int res = f(sum, p - 1, k);
  if (sum >= p) {
    res += f(sum - p, p - 1, k - 1);
    res %= C::mod;
  }
  return dp0[sum][p][k] = res % C::mod;
}
int solve(int n, int k) {
  if (~dp1[n][k]) return dp1[n][k];
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    int x = f(i, i, k);
    int y = 1LL * C::nCr(n - i + k, k) * C::F[k] % C::mod;
    ans += 1LL * x * y % C::mod;
    ans %= C::mod;
  }
  return dp1[n][k] = ans;
}
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  C::init();
  memset(dp0, -1, sizeof dp0);
  memset(dp1, -1, sizeof dp1);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    if (k > 45) {
      cout << 0 << "\n";
    } else {
      cout << solve(n, k) << "\n";
    }
  }
}

```