SP33046 FACTMODP - Factorial Modulo Prime
Description
Find $ N! $ **modulo** $ P $ .
Input Format
The first line contains $ T $ ( $ 1 \le T \le 100,000 $ ), the number of test cases.
Each of the next $ T $ lines contains two integers $ N $ ( $ 0 \le N \le 10^{11} $ ) and $ P $ ( $ 2 \le P \le 10^{11} $ ), where $ P $ is a prime.
Output Format
For each $ N $ and $ P $ , output $ N! $ **modulo** $ P $ .
For each input file, It is guaranteed that (the sum of $\sqrt{P} \le 320000$)