Fun Count Not Fun#12383

Fun Count Not Fun

2 seconds
256 megabytes
Hard

You are given two integers and . An initial array is constructed as [1, 2, 3, \dots, n].

While the length of the array is at least , you perform the following process:

  1. Select any contiguous subarray of length exactly .

  2. Delete this subarray from .

  3. Concatenate the remaining left and right parts to form a new array .

The process terminates when |A| < k.

Determine the number of distinct arrays that can exist when the process stops. Since the count can be large, output the result modulo .

Input

The first line contains an integer (1 \le T \le 10^6) — the number of test cases.

Each of the following lines contains two space-separated integers and (1 \le n, k \le 10^6).

Output

For each test case, output a single integer representing the number of distinct terminal arrays modulo .

Examples

Example 1

Loading
Loading

Scoring

  1. Subtask ( points): 1 \le n, k \le 10.

  2. Subtask ( points): \sum n \cdot k \le 10^6 over all test cases.

  3. Subtask ( points): \sum n \le 10^6 over all test cases.

  4. Subtask ( points): is the same across all test cases.

  5. Subtask ( points): No additional constraints.