#P1630. 求和

求和

Description

Find the remainder when the sum 1b+2b++ab1^b+2^b+\cdots + a^b is divided by 10410^4.

Input Format

This problem contains multiple test cases.

The first line contains an integer NN, indicating that there are NN test cases.

For each test case, one line contains two integers a,ba,b.

Output Format

For each test case, output one integer per line, the answer.

1
2 3

9

Hint

For 30% of the testdata, N10N \le 10, a,b103a,b \le 10^3.

For 100% of the testdata, 1N1001 \le N \le 100, 1a,b1091 \le a,b \le 10^9.

Translated by ChatGPT 5