#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &item) {
  out << '(' << item.first << ", " << item.second << ')';
  return out;
}
template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  for (const auto &item : v) out << item << ' ';
  return out;
}
const int N = 1010;
const int K = 46;
const int MOD = 1000000007;
int fact[N];
int ans[K][N], comb[2 * N][2 * N];
int waysToWrite[K][N][N];
void precompute() {
  fact[0] = 1;
  for (int i = 1; i < N; ++i) fact[i] = (1LL * fact[i - 1] * i) % MOD;
  for (int i = 0; i < 2 * N; ++i) {
    comb[i][0] = comb[i][i] = 1;
    for (int j = 1; j < i; ++j) {
      comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
      if (comb[i][j] >= MOD) comb[i][j] -= MOD;
    }
  }
  for (int last = 0; last < N; ++last) waysToWrite[0][0][last] = 1;
  for (int nr = 1; nr < K; ++nr)
    for (int s = 0; s < N; ++s) {
      waysToWrite[nr][s][0] = (nr == 1 && s == 0);
      for (int last = 1; last < N; ++last) {
        waysToWrite[nr][s][last] =
            waysToWrite[nr][s][last - 1] +
            (last <= s ? waysToWrite[nr - 1][s - last][last - 1] : 0);
        if (waysToWrite[nr][s][last] >= MOD) waysToWrite[nr][s][last] -= MOD;
      }
    }
  for (int k = 1; k < K; ++k)
    for (int n = 1; n < N; ++n) {
      for (int space = 0; space <= n - 1; ++space) {
        int term =
            1LL * comb[n - space][k] * waysToWrite[k][space][N - 1] % MOD;
        term = 1LL * term * fact[k] % MOD;
        ans[k][n] += term;
        if (ans[k][n] >= MOD) ans[k][n] -= MOD;
      }
    }
}
int main() {
  ios_base::sync_with_stdio(false);
  precompute();
  int t, n, k;
  for (cin >> t; t; --t) {
    cin >> n >> k;
    if (k < K)
      cout << ans[k][n] << '\n';
    else
      cout << 0 << '\n';
  }
  return 0;
}

### Prompt

Create a solution in CPP for 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;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &item) {
  out << '(' << item.first << ", " << item.second << ')';
  return out;
}
template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  for (const auto &item : v) out << item << ' ';
  return out;
}
const int N = 1010;
const int K = 46;
const int MOD = 1000000007;
int fact[N];
int ans[K][N], comb[2 * N][2 * N];
int waysToWrite[K][N][N];
void precompute() {
  fact[0] = 1;
  for (int i = 1; i < N; ++i) fact[i] = (1LL * fact[i - 1] * i) % MOD;
  for (int i = 0; i < 2 * N; ++i) {
    comb[i][0] = comb[i][i] = 1;
    for (int j = 1; j < i; ++j) {
      comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
      if (comb[i][j] >= MOD) comb[i][j] -= MOD;
    }
  }
  for (int last = 0; last < N; ++last) waysToWrite[0][0][last] = 1;
  for (int nr = 1; nr < K; ++nr)
    for (int s = 0; s < N; ++s) {
      waysToWrite[nr][s][0] = (nr == 1 && s == 0);
      for (int last = 1; last < N; ++last) {
        waysToWrite[nr][s][last] =
            waysToWrite[nr][s][last - 1] +
            (last <= s ? waysToWrite[nr - 1][s - last][last - 1] : 0);
        if (waysToWrite[nr][s][last] >= MOD) waysToWrite[nr][s][last] -= MOD;
      }
    }
  for (int k = 1; k < K; ++k)
    for (int n = 1; n < N; ++n) {
      for (int space = 0; space <= n - 1; ++space) {
        int term =
            1LL * comb[n - space][k] * waysToWrite[k][space][N - 1] % MOD;
        term = 1LL * term * fact[k] % MOD;
        ans[k][n] += term;
        if (ans[k][n] >= MOD) ans[k][n] -= MOD;
      }
    }
}
int main() {
  ios_base::sync_with_stdio(false);
  precompute();
  int t, n, k;
  for (cin >> t; t; --t) {
    cin >> n >> k;
    if (k < K)
      cout << ans[k][n] << '\n';
    else
      cout << 0 << '\n';
  }
  return 0;
}

```