LogiQuest

26. nCr Modulo 1e9+7

MediumCombinatoricsModular Arithmetic

For each query, print C(n, r) modulo 1 000 000 007.

Input format

Line 1: q Next q lines: n r

Output format

q lines.

Example 1

Input

3
5 2
10 0
10 10

Output

10
1
1

Example 2

Input

2
1000 500
100 50

Output

159835829
538992043

Constraints

1 ≤ q ≤ 10⁴, 0 ≤ r ≤ n ≤ 1000

Read input from standard input and print the answer to standard output. Your code is judged against 3 test cases, most of them hidden.

Loading the MyLoginn IDE…