P5160 WD and Loops
Background
WD is immersed in loops all day long and cannot break free.
Description
One day, WD (a “juruo”, i.e., a newbie) wrote a very, very long `for` loop to solve a small problem:
```cpp
int cnt = 0;
for (int a_1 = 0; a_1
Input Format
The first line contains an integer $T$, the number of test cases. Each of the following lines contains two integers $n, m$, representing the number of nested loops and the upper bound of each loop level, respectively.
Output Format
Output $T$ lines. Each line contains one integer, the answer.
Explanation/Hint
$\text{subtask1}(23pts):~n,m\le 1,000,~1\le T\le 10,000$
$\text{subtask2}(35pts):~n,m\le 10^7,~1\le T\le 5$
$\text{subtask3}(42pts):~n,m\le 10^{18},~1\le T\le 100,000$
For Sample 1, you can just write some code and you will know the answer is 55 (just kidding).
Translated by ChatGPT 5