A Simple Sum
Medium
Execution time limit is 1 second
Runtime memory usage limit is 128 megabytes
Given three integers x, m and n. Evaluate (1 + x + x^2
+ .. + x^m
) (mod n).
Input
First line contains the number of test cases. Each next line contains three space separated integers x, m and n (1 ≤ x, m, n ≤ 10^16
).
Output
For each test case print the answer on a separate line.
Examples
Input #1
Answer #1
Submissions 1K
Acceptance rate 12%