-function, a shorter name of ZeedZaad-function is defined as follows.

Given integers , , and your task is to find ZZ(c, d).
First line is a number of test cases (t \leq 200).
Each test case is a line containing integers , , and (0 \leq a, b \leq 10^9, 1 \leq c \leq 100, 1 \leq c \cdot d \leq 10^8).
For each test case print ZZ(c, d) mod .
Example 1