A Simple Sum
Given three integers x, m and n. Evaluate (1 + x +
x2 + .. +
xm) (mod n).
First line contains the number of test cases. Each next line contains three space separated integers x, m and n (1 ≤ x, m, n ≤
For each test case print the answer on a separate line.
1 3 2 5