
Given integers and , compute the value of the expression shown above modulo .
The first line contains a single integer (1 \leq T \leq 10^5) — the number of test cases.
Each of the following lines contains two integers and (1 \leq N \leq 10^9, 1 \leq K \leq 4).
For each test case, output the value of the expression modulo .
Example 1