Recently you went to a fair. There were a lots of rides and stalls. You enjoyed the fair a lot, but the most entertaining part was to play ThrowBall. In ThrowBall, you need to pay Rs 100 as the fee, and then throw N identical balls into K distinct boxes, such that there is at least one ball in each box. You tried your best but couldn’t throw all balls properly, so you lost your money. But the shopkeeper was generous, he gave you a last chance. He asked you a question, which if solved correctly will give your money back.

The question is **What was the distinct number of ways in which you could throw those balls into the boxes?**

As the answer could be very large, print it modulo M, where M is a prime number.

**Input:**

The first line of input contains an integer T, denoting the number of test cases. The only line of each test case contains 3 space seperated integers N,K and M as described above.

**Output:**

For each test case output a single integer corresponding to the answer of the question asked by the shopkeeper, in new line.

**Constraints:**

1<= T <=100

1<= N <= 10^{18}

1<= K <= 10^{18}

1<= M <= 10^{6}

**Example:
Input:**

2

13 9 7

5 5 7

5

1

In first test case distinct number of ways of throwing 13 identical balls into 9 distinct boxes is 495.

So the answer modulo 7 is 5.

Author: tanujyadav97

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

GustavoMéndez | 191 |

VivSisMMM | 182 |

d_Coder00 | 177 |

ajayjadhav35 | 161 |

Astikeysingh | 154 |

Pulkit__Sharma__ | 694 |

Anirban166 | 652 |

abducodes | 562 |

Found_me | 542 |

Sathvik Avasarala | 514 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4559 |

Login to report an issue on this page.