Sum of Powers Version I#6067

Sum of Powers Version I

1 second
64 megabytes
Very easy

Given integers and , compute the value of the expression shown above modulo .

Input

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

Output

For each test case, output the value of the expression modulo .

Examples

Example 1

Loading
Loading