#nt601. 组合数取模3

组合数取模3

Binomial Coefficient Modulo (3)

Problem Description

Given a prime pp. Answer TT queries; for each, output the value of (nm) mod p{n \choose m} \bmod p.

Input Format

The first line contains two integers p,Tp, T.

The following TT lines each contain two integers n,mn, m.

Output Format

For each query, output one line containing the answer.

Sample Input

10007 3
5 2
50 20
50000000 20000000

Sample Output

10
2551
0

Constraints

For all data, 1≤T≤1051\leq T\leq 10^5, 1≤m≤n≤10181\leq m\leq n\leq 10^{18}, and 2≤p≤1062\leq p \leq 10^6 are guaranteed, where pp is prime.