#P11000. [2015杭电多校]PowMod

[2015杭电多校]PowMod

PowMod

Problem Description

Declare: k=i=1mφ(in) mod 1000000007k=\sum_{i=1}^{m} \varphi (i*n)\ mod\ 1000000007 nn is a square-free number. φ\varphi is the Euler's totient function . find: ans=kkkk...k mod pans=k^{k^{k^{k^{...^k}}}}\ mod \ p There are infinite number of kk

Input

Multiple test cases(test cases 100\leq 100), one line per case. Each line contains three integers, n,mn, m and pp. 1n,m,p1071 \leq n, m, p \leq 10^{7}

Output

For each case, output a single line with one integer, ans.

Sample Input

1 2 6
1 100 9

Sample Output

4
7

Author

HIT

Source

2016 Multi-University Training Contest 1