Bacteria Growth (Small)
Time limit5sMemory limit512 MB
Apply the map x to x^x exactly B times starting from A and report the result modulo C.
- Level
Medium7 of 10
- Topics
- Number theory, Recursion
- Solved
- No attempts yet
Problem
Pascal studies microorganisms and found a bacterium with an unusual growth pattern. If of them are present at one moment, then in an ideal environment there are of them one hour later.
Given three integers , and , compute how many bacteria there are hours after a colony of bacteria starts. Every hour the count turns into , and that change happens times. The answer grows very large, so print its remainder modulo .
Input
The first line contains the number of test cases . Each of the following lines contains one test case.
A test case is three integers separated by spaces: , and , in that order.
Constraints
Output
For each test case, print one line in the following format.
Case #X: N
is the number of the test case, counting from 1, and is the number of bacteria after hours, taken modulo .