#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("popcnt")
#pragma GCC target("avx2")
using namespace std;
template <typename T1, typename T2>
inline void mine(T1 &x, T2 y) {
  if (x > y) x = y;
}
template <typename T1, typename T2>
inline void maxe(T1 &x, T2 y) {
  if (x < y) x = y;
}
ostream &operator<<(ostream &a, const vector<int> &b) {
  for (auto k : b) cout << k << ' ';
  return a;
}
const int MOD = 1000000007;
const int INF = 1000000050;
const long long BIG = (long long)2e18 + 50;
const int MX = 1010;
const double EPS = 1e-9;
const int K = 47;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long add(long long a, long long b) {
  a += b;
  if (a >= MOD) return a - MOD;
  return a;
}
long long sub(long long a, long long b) {
  a -= b;
  if (a < 0) return a + MOD;
  return a;
}
long long mult(long long a, long long b) { return a * b % MOD; }
long long powmod(long long a, long long p) {
  if (p == 0) return 1;
  if (p & 1) return mult(a, powmod(a, p - 1));
  return powmod(mult(a, a), p / 2);
}
long long rev(long long a) { return powmod(a, MOD - 2); }
int dp[K][MX][MX];
int f[MX];
void ps(int x) {
  for (int i = 0; i < MX; i++) {
    for (int j = 0; j < MX; j++) {
      dp[x][i][j] = add(
          dp[x][i][j],
          sub(add((i > 0 ? dp[x][i - 1][j] : 0), (j > 0 ? dp[x][i][j - 1] : 0)),
              (i * j > 0 ? dp[x][i - 1][j - 1] : 0)));
    }
  }
}
void solve() {
  f[0] = 1;
  for (int i = 1; i < MX; i++) f[i] = mult(f[i - 1], i);
  for (int last = 1; last < MX; ++last) {
    for (int delta = 0; delta < last; ++delta) {
      dp[1][last][delta] = 1;
    }
  }
  ps(1);
  for (int len = 2; len < K; ++len) {
    for (int last = 1; last < MX; ++last) {
      for (int delta = 1; delta < last; ++delta)
        dp[len][last][delta] = dp[len - 1][last - delta - 1][delta - 1];
    }
    ps(len);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  ;
  ;
  ;
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n, k;
    cin >> n >> k;
    if (k >= K)
      cout << "0\n";
    else
      cout << mult(dp[k][n][n - 1], f[k]) << '\n';
  }
}

### Prompt

Please formulate 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>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("popcnt")
#pragma GCC target("avx2")
using namespace std;
template <typename T1, typename T2>
inline void mine(T1 &x, T2 y) {
  if (x > y) x = y;
}
template <typename T1, typename T2>
inline void maxe(T1 &x, T2 y) {
  if (x < y) x = y;
}
ostream &operator<<(ostream &a, const vector<int> &b) {
  for (auto k : b) cout << k << ' ';
  return a;
}
const int MOD = 1000000007;
const int INF = 1000000050;
const long long BIG = (long long)2e18 + 50;
const int MX = 1010;
const double EPS = 1e-9;
const int K = 47;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long add(long long a, long long b) {
  a += b;
  if (a >= MOD) return a - MOD;
  return a;
}
long long sub(long long a, long long b) {
  a -= b;
  if (a < 0) return a + MOD;
  return a;
}
long long mult(long long a, long long b) { return a * b % MOD; }
long long powmod(long long a, long long p) {
  if (p == 0) return 1;
  if (p & 1) return mult(a, powmod(a, p - 1));
  return powmod(mult(a, a), p / 2);
}
long long rev(long long a) { return powmod(a, MOD - 2); }
int dp[K][MX][MX];
int f[MX];
void ps(int x) {
  for (int i = 0; i < MX; i++) {
    for (int j = 0; j < MX; j++) {
      dp[x][i][j] = add(
          dp[x][i][j],
          sub(add((i > 0 ? dp[x][i - 1][j] : 0), (j > 0 ? dp[x][i][j - 1] : 0)),
              (i * j > 0 ? dp[x][i - 1][j - 1] : 0)));
    }
  }
}
void solve() {
  f[0] = 1;
  for (int i = 1; i < MX; i++) f[i] = mult(f[i - 1], i);
  for (int last = 1; last < MX; ++last) {
    for (int delta = 0; delta < last; ++delta) {
      dp[1][last][delta] = 1;
    }
  }
  ps(1);
  for (int len = 2; len < K; ++len) {
    for (int last = 1; last < MX; ++last) {
      for (int delta = 1; delta < last; ++delta)
        dp[len][last][delta] = dp[len - 1][last - delta - 1][delta - 1];
    }
    ps(len);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  ;
  ;
  ;
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n, k;
    cin >> n >> k;
    if (k >= K)
      cout << "0\n";
    else
      cout << mult(dp[k][n][n - 1], f[k]) << '\n';
  }
}

```