ZZ#6573

ZZ

10 seconds
128 megabytes
Easy

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

![prb6573](https://static.e-olymp.com/content/54/549c372178b271ffaf9cce931aa85135610e2639.jpg)

Given integers , , and your task is to find ZZ(c, d).

Input

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).

Output

For each test case print ZZ(c, d) mod .

Examples

Example 1

Loading
Loading