Problem: You are given a positive integer . Let's build the following graph from it:
- each vertex is a divisor of (not necessarily prime, and itself are also included);
- two vertices and () have an undirected edge between them if is divisible by and is a prime;
- the weight of an edge is the number of divisors of that are not divisors of .
For example, here is the graph for :
Edge has weight because has divisors and has divisors . Thus, there are divisors of that are not divisors of — .
There is no edge between and because is not divisible by . There is no edge between and because is not a prime.
Let the length of the path between some vertices and in the graph be the total weight of edges on it. For example, path has length . The empty path has length .
So the shortest path between two vertices and is the path that has the minimal possible length.
Two paths and are different if there is either a different number of edges in them or there is a position such that and are different edges.
You are given queries of the following form:
- — calculate the number of the shortest paths between vertices and .
The answer for each query might be large so print it modulo .
Input Format: The first line contains a single integer () — the number the graph is built from.
The second line contains a single integer () — the number of queries.
Each of the next lines contains two integers and (). It is guaranteed that is divisible by both and (both and are divisors of ).
Output Format: Print integers — for each query output the number of the shortest paths between the two given vertices modulo .
Note: In the first example:
- The first query is only the empty path — length ;
- The second query are paths (length ), (length ) and (length ).
- The third query is only the path (length ).