Under construction

Still being built. Things may change

Binomial coefficient queries

Time limit1sMemory limit512 MB

Summary
Given M pairs N and K, print the binomial coefficient C(N, K) modulo 1,000,000,007.
Level

Medium5 of 10

Topics
Combinatorics, Math, Prefix sum
Solved
No attempts yet

Problem

You are given MM pairs, each made of a positive integer NN and an integer KK. For every pair, compute the binomial coefficient (NK)\binom{N}{K} modulo 1,000,000,007.

Input

The first line contains the number of pairs MM (1≤M≤100,0001 \le M \le 100{,}000).

Each of the next MM lines contains NN and KK, separated by a space (1≤N≤4,000,0001 \le N \le 4{,}000{,}000, 0≤K≤N0 \le K \le N).

Output

Print MM lines. On the ii-th line, print (NK)\binom{N}{K} modulo 1,000,000,007 for the ii-th pair, in input order.

Examples1

  1. Example 1

    Input
    5
    5 2
    5 3
    10 5
    20 10
    10 0
    
    Expected output
    10
    10
    252
    184756
    1