11680 - Big Mod   

Description

Writer : jjjjj19980806

Description : pclightyear

jjjjj doesn't like long description.

Given integers a, n, p, please calculate the value of an mod p.

Input

The first line contains an integer T, representing the number of testcases.

Each testcase contains a line with three integer anm.

It is guaranteed that :

  • 1 ≤ T ≤ 1000
  • 1 ≤ a, n, p ≤ 109

Output

For each testcase, please output a line contains one integer representing your answer.

Sample Input  Download

Sample Output  Download

Tags




Discuss