403_D. Beautiful Pairs of Numbers_13607
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.
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const double eps = 1e-10;
const int inf = 0x3f3f3f3f;
const long long infLL = 0x3f3f3f3f3f3f3f3fLL;
const int maxn = 2000 + 5;
const long long mod = 1000000007;
long long fac[maxn], ifac[maxn];
void gcd(long long a, long long b, long long &d, long long &x0, long long &y0) {
  if (!b) {
    d = a;
    x0 = 1;
    y0 = 0;
  } else {
    gcd(b, a % b, d, y0, x0);
    y0 -= x0 * (a / b);
  }
}
long long inv(long long a, long long m = mod) {
  long long d, x, y;
  gcd(a, m, d, x, y);
  return d == 1 ? (x + m) % m : -1;
}
void mk_fac() {
  fac[0] = 1;
  for (int i = 1; i < maxn; ++i) fac[i] = fac[i - 1] * i % mod;
  for (int i = 0; i < maxn; ++i) ifac[i] = inv(fac[i]);
}
long long A(int n, int m) {
  if (!fac[0]) mk_fac();
  return fac[n] * ifac[n - m] % mod;
}
long long C(int n, int m) {
  if (!fac[0]) mk_fac();
  return fac[n] * ifac[n - m] % mod * ifac[m] % mod;
}
long long s[maxn];
long long f[maxn][maxn];
void init() {
  s[0] = 0;
  for (int i = 1; i < maxn; ++i) s[i] = s[i - 1] + i;
  for (int i = 1; i < maxn; ++i) f[i][1] = 1;
  for (int j = 2; j < maxn; ++j) {
    if (s[j] >= maxn) break;
    f[s[j]][j] = fac[j];
    for (int i = s[j] + 1; i < maxn; ++i) {
      f[i][j] += f[i - j][j] + f[i - j][j - 1] * j % mod;
      f[i][j] %= mod;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  mk_fac();
  init();
  int T;
  cin >> T;
  while (T--) {
    int n, k;
    cin >> n >> k;
    --n;
    long long res = 0;
    for (int i = s[k - 1]; i <= n; ++i) {
      int t = n - i - (k - 1);
      if (t < 0) break;
      res += f[i + k][k] * C(k + t, t) % mod;
      res %= mod;
    }
    cout << res << endl;
  }
  return 0;
}
