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.
import java.io.*;
import java.util.*;

public class D_new {

    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;

    int[] fact, invFact, inv;
    static final int N = 2000;
    static final int P = 1000000007;

    int C(int n, int k) {
        if (n < 0 || k < 0 || k > n) {
            return 0;
        }
        return (int) ((long) fact[n] * invFact[k] % P * invFact[n - k] % P);
    }

    int[][] cntDiff = new int[47][1001];
    int[][] memo = new int[1001][1001];
    {
        for (int i = 0; i < memo.length; i++) {
            Arrays.fill(memo[i], -1);
        }
    }

    int solve(int n, int k) {
        if (memo[n][k] != -1) {
            return memo[n][k];
        }

        int free = n - k;
        if (free < k * (k - 1) / 2) {
            return memo[n][k] = 0;
        }
        
        // System.err.println(free);

        int ret = 0;
        for (int i = 0; i <= free; i++) {
            ret += (int) ((long) C(i + k, i) * cntDiff[k][free - i] % P);
            if (ret >= P) {
                ret -= P;
            }
        }

        ret = (int) ((long) ret * fact[k] % P);

        return memo[n][k] = ret;

    }

    D_new() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);

        fact = new int[N + 1];
        invFact = new int[N + 1];
        inv = new int[N + 1];

        fact[0] = invFact[0] = 1;
        inv[1] = invFact[1] = fact[1] = 1;
        for (int x = 2; x <= N; x++) {
            inv[x] = P - (int) ((long) (P / x) * inv[P % x] % P);
            fact[x] = (int) ((long) fact[x - 1] * x % P);
            invFact[x] = (int) ((long) invFact[x - 1] * inv[x] % P);
        }

        Arrays.fill(cntDiff[1], 1);

        int[][] dp = new int[1001][1001]; // sum last
        int[][] next = new int[1001][1001];
        for (int i = 0; i <= 1000; i++) {
            for (int j = 0; j <= 1000; j++) {
                dp[i][j] = i <= j ? 1 : 0;
            }
        }

        for (int j = 2; j < cntDiff.length; j++) {
            for (int i = 0; i <= 1000; i++) {
                Arrays.fill(next[i], 0);
            }
            for (int prevSum = 0; prevSum <= 1000; prevSum++)
                for (int maxLast = 0; maxLast <= 1000; maxLast++) {
                    if (dp[prevSum][maxLast] != 0) {
                        if (prevSum + maxLast + 1 <= 1000
                                && maxLast + 1 <= 1000) {
                            next[prevSum + maxLast + 1][maxLast + 1] += dp[prevSum][maxLast];
                            if (next[prevSum + maxLast + 1][maxLast + 1] >= P) {
                                next[prevSum + maxLast + 1][maxLast + 1] -= P;
                            }
                        }
                    }
                }

            for (int sum = 0; sum <= 1000; sum++)
                for (int last = 0; last <= 1000; last++) {
                    cntDiff[j][sum] += next[sum][last];
                    if (cntDiff[j][sum] >= P) {
                        cntDiff[j][sum] -= P;
                    }
                }

            for (int sum = 0; sum <= 1000; sum++)
                for (int last = 1; last <= 1000; last++) {
                    next[sum][last] += next[sum][last - 1];
                    if (next[sum][last] >= P) {
                        next[sum][last] -= P;
                    }
                }
            int[][] tmp = dp;
            dp = next;
            next = tmp;
        }

        int t = nextInt();
        while (t-- > 0) {
            int n = nextInt();
            int k = nextInt();
            out.println(solve(n, k));
        }
        out.close();
    }

    public static void main(String[] args) throws IOException {
        new D_new();
    }

    String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }

    String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}