Given three integers

,

, and

, you need to color each
lattice point in the set
%5Cmid1%5Cle%20x%5Cle%20n%2C1%5Cle%20y%5Cle%20m%2Cx%2Cy%5Cin%20%5Cmathbb%7BZ%7D%5C%7D)
on the 2D Cartesian coordinate system using one of

colors. Calculate the number of valid coloring methods. Two methods are considered different if and only if there exists one point in set

with a different color between them.
This problem seems too simple, so Sauden adds a constraint: for any integers
![x\in[1,n-1]](https://www.nowcoder.com/equation?tex=x%5Cin%5B1%2Cn-1%5D)
and
![y\in[1,m-1]](https://www.nowcoder.com/equation?tex=y%5Cin%5B1%2Cm-1%5D)
, if the points
)
and
)
have the same color, the points
)
and
)
must also have the same color. Determine the number of valid coloring methods modulo

.
输入描述:
The first line contains an integer
(
), the number of test cases.
Each test case consists of one line with three integers
,
, and
(
,
), as described in the problem.
输出描述:
For each test case, output a single integer on a line, representing the answer modulo
.