## AMR10I - Dividing Stones

There are N stones, which can be divided into some piles arbitrarily. Let the value of each division be equal to the product of the number of stones in all the piles modulo P. How many possible distinct values are possible for a given N and P?

**INPUT**

The first line contains the number of test cases T. T lines follow, one corresponding to each test case, containing 2 integers: N and P.

**OUTPUT**

Output T lines, each line containing the required answer for the corresponding test case.

**CONSTRAINTS**

T <= 20

2 <= N <= 70

2 <= P <= 1e9

**SAMPLE INPUT**

2

3 1000

5 1000

**SAMPLE OUTPUT**

3

6

**EXPLANATION**

In the first test case, the possible ways of division are (1,1,1), (1,2), (2,1) and (3) which have values 1, 2, 2, 3 and hence, there are 3 distinct values.

In the second test case, the numbers 1 to 6 constitute the answer and they can be obtained in the following ways:

1=1*1*1*1*1

2=2*1*1*1

3=3*1*1

4=4*1

5=5

6=2*3

Added by: | Varun Jalan |

Date: | 2010-12-13 |

Time limit: | 0.981s |

Source limit: | 50000B |

Memory limit: | 1536MB |

Cluster: | Cube (Intel G860) |

Languages: | All except: ASM64 |

Resource: | own problem, ICPC Asia regionals, Amritapuri 2010 |