#Lutece0477. A number sequence problem
A number sequence problem
Migrated from Lutece 477 A number sequence problem
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
Here is a general term of a number sequence
$G(n)=(\sqrt{a}+\sqrt{b})^{2n}+(\sqrt{a}-\sqrt{b})^{2n}$
You are asked to calculate it mod .
Input
The first line of the input contains a positive integer () representing the number of test cases.
Then for every case, only one line containing positive integers , , and . ()
Output
For each case output one line contained the answer.
Samples
3
2 3 1
2 2 2
1 1 2
10
64
16
Resources
2011 UESTC ACM Training for Math