#nt801. 阶

阶

Modular Order

Problem Description

Given a prime pp, answer TT queries. Given an aa, find the smallest positive integer xx such that ax≡1(modp)a^x \equiv 1 \pmod p.

Input Format

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

The next TT lines each contain one integer aa.

Output Format

A total of TT lines, each containing one integer: the answer.

Sample Input

7 3
2
3
4

Sample Output

3
6
3

Constraints

For all data, T≤105T\leq 10^5, 1≤a<p≤1091\leq a < p \leq 10^9 are guaranteed, and pp is prime.