#nt602. 组合数取模4

组合数取模4

Binomial Coefficient Modulo 4

Problem Description

You are given a modulus qq. Answer TT queries; for each query output the value of (nm) mod q{n \choose m} \bmod q.

Input Format

The first line contains two integers q,Tq, T.

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

Output Format

For each query, output one line: the answer.

Sample Input

10000 3
5 2
50 20
50000000 20000000

Sample Output

10
3960
8800

Constraints

For all data, 1≤T≤1051 \leq T \leq 10^5, 1≤m≤n≤10181 \leq m \leq n \leq 10^{18}, 2≤q≤1062 \leq q \leq 10^6.