You are just learning to code and are finished with loops and functions. Now, you are given the following pseudocode:
/*
* The function has two integer parameters: k and n
* The function returns the value of sum
*/
function f(k, n) {
sum = 0;
for (i = 1; i ≤ n; i += 1) {
sum += i;
i *= k;
}
return sum;
}
For three given integers , , and , find the value of , where is defined as:
Input Format
The first line of the input is an integer , the total number of queries. Each of the next lines contains three space separated integers , , and .
Constraints
Output Format
For each query, print the value of on a new line.
Sample Input
4
2 1 5
3 1 5
4 1 5
5 1 5
Sample Output
14
13
10
5
Explanation
Query 2 1 5
So,
Query 3 1 5
So,
Query 4 1 5
So,
Query 5 1 5
So,