Bacteria Growth (Small)

Apply the map x to x^x exactly B times starting from A and report the result modulo C.

Medium7Number theoryRecursionNo attempts yetTime limit5sMemory limit512 MB

Problem

Pascal studies microorganisms and found a bacterium with an unusual growth pattern. If xx of them are present at one moment, then in an ideal environment there are xxx^x of them one hour later.

Given three integers AA, BB and CC, compute how many bacteria there are BB hours after a colony of AA bacteria starts. Every hour the count xx turns into xxx^x, and that change happens BB times. The answer grows very large, so print its remainder modulo CC.

Input

The first line contains the number of test cases TT. Each of the following TT lines contains one test case.

A test case is three integers separated by spaces: AA, BB and CC, in that order.

Constraints

  • 1T5001 \le T \le 500
  • 1A10001 \le A \le 1000
  • 1B10001 \le B \le 1000
  • 1C10001 \le C \le 1000

Output

For each test case, print one line in the following format.

Case #X: N

XX is the number of the test case, counting from 1, and NN is the number of bacteria after BB hours, taken modulo CC.