Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/guruhlashlar-soni

Number of combinations

Hard 2000 ms 128 MB 67%
Share

A class has $n$ students. Find the number of ways to choose $k$ of them for an olympiad (the order of choice does not matter). Answer $q$ such queries.

All ways to choose two students out of five

Input

The first line contains a positive integer $q$. Each of the next $q$ lines contains two integers: $n$ and $k$.

Output

For each query, on a separate line, one integer — the number of ways modulo $10^{9} + 7$.

Note

$1 \le q \le 10^{5}$
$0 \le k \le n \le 10^{6}$

Examples

Input #1
3
5 2
4 0
10 10
Output #1
10
1
1
Input #2
1
1000000 500000
Output #2
996692777

Sign in to submit a solution

Signing up is free and takes a minute.