#Lutece1177. pow(a, C(n,m) ) % k

pow(a, C(n,m) ) % k

Migrated from Lutece 1177 pow(a, C(n,m) ) % k

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

One day, Peter was given an easy math problem.

Given four integers aa, nn, mm, kk and two formulas x=ab(mod k)x=a^b( mod\ k), b=Cnmb=C_n^m, you are supposed to calculate the result of xx.

However, Peter found that the ranges of aa, nn, mm, kk are so large that Peter could not solve it. Could you help him?

Input

The first line contains an integer T(1T500)T(1 \leq T \leq 500) representing the number of test cases.

Each of the following TT lines contains four integers aa, nn, mm, kk. The ranges of them are following.

1a10181 \leq a \leq 10^{18} , 0n10180 \leq n \leq 10^{18}, 0m10180 \leq m \leq 10^{18}, 1k1051 \leq k \leq 10^5

Output

Output T lines as the sample output. Output each line as "Case #k: ans". kk means the number of test case, ansans means the result of those two formulas when given those four integers.

Samples

4
5 0 0 4
100 10 5 3
233035515918638532 700708637 28 32886
999999999992226432 251468460246892460 313092 280
Case #1: 1
Case #2: 1
Case #3: 26244
Case #4: 64

Resources

peterpan