# Description

传送门: HDU-5667

Holion August will eat every thing he has found. Now there are many foods,but he does not want to eat all of them at once,so he find a sequence. \[f_n=\left\{\begin{matrix} 1 ,&n=1 \\ a^b,&n=2 \\ a^bf_{n-1}^cf_{n-2},&otherwise \end{matrix}\right.\] He gives you 5 numbers n,a,b,c,p,and he will eat fn foods.But there are only p foods,so you should tell him fn mod p.