The binomial coefficient $C_n^m$ represents the number of ways to choose $m$ items from $n$ items. For example, choosing two items from the three items $(1, 2, 3)$ can be done in $(1, 2), (1, 3), (2, 3)$, which are $3$ ways. Based on the definition of binomial coefficients, we can provide the general formula for $C_n^m$:
$$C_n^m = \frac{n!}{m!(n - m)!}$$
where $n! = 1 \times 2 \times \dots \times n$.
Given $n, m$ and $k$, for all $0 \le i \le n, 0 \le j \le \min(i, m)$, how many pairs $(i, j)$ satisfy that $C_i^j$ is a multiple of $k$?
Input
The first line contains two integers $t, k$, where $t$ is the total number of test cases, and $k$ is as defined above.
The next $t$ lines each contain two integers $n, m$, where $n, m$ are as defined above.
Output
Output $t$ lines, each containing an integer representing the number of pairs $(i, j)$ such that $0 \le i \le n, 0 \le j \le \min(i, m)$ and $C_i^j$ is a multiple of $k$.
Examples
Input 1
1 2 3 3
Output 1
1
Note 1
Among all possible cases, only $C_2^1 = 2$ is a multiple of $2$.
Input 2
2 5 4 5 6 7
Output 2
0 7
Subtasks
| Test Case | $n$ | $m$ | $k$ | $t$ |
|---|---|---|---|---|
| 1 | $\le 3$ | $\le 3$ | $= 2$ | $= 1$ |
| 2 | $= 3$ | $\le 10^4$ | ||
| 3 | $\le 7$ | $\le 7$ | $= 4$ | $= 1$ |
| 4 | $= 5$ | $\le 10^4$ | ||
| 5 | $\le 10$ | $\le 10$ | $= 6$ | $= 1$ |
| 6 | $= 7$ | $\le 10^4$ | ||
| 7 | $\le 20$ | $\le 100$ | $= 8$ | $= 1$ |
| 8 | $= 9$ | $\le 10^4$ | ||
| 9 | $\le 25$ | $\le 2000$ | $= 10$ | $= 1$ |
| 10 | $= 11$ | $\le 10^4$ | ||
| 11 | $\le 60$ | $\le 20$ | $= 12$ | $= 1$ |
| 12 | $= 13$ | $\le 10^4$ | ||
| 13 | $\le 100$ | $\le 25$ | $= 14$ | $= 1$ |
| 14 | $= 15$ | $\le 10^4$ | ||
| 15 | $\le 60$ | $= 16$ | $= 1$ | |
| 16 | $= 17$ | $\le 10^4$ | ||
| 17 | $\le 2000$ | $\le 100$ | $= 18$ | $= 1$ |
| 18 | $= 19$ | $\le 10^4$ | ||
| 19 | $\le 2000$ | $= 20$ | $= 1$ | |
| 20 | $= 21$ | $\le 10^4$ |