#nt801. 阶
阶
Modular Order
Problem Description
Given a prime , answer queries. Given an , find the smallest positive integer such that .
Input Format
The first line contains two integers .
The next lines each contain one integer .
Output Format
A total of lines, each containing one integer: the answer.
Sample Input
7 3
2
3
4
Sample Output
3
6
3
Constraints
For all data, , are guaranteed, and is prime.