Icebound hates math. But Imp loves math. One day, Imp gave icebound a problem.
The problem is as follows.
S=(∑ni=1qi) mod pS=(∑i=1nqi) mod p
For given q,n,p, you need to help icebound to calculate the value of S.
输入描述:
The first line contains an integer T, denoting the number of test cases.
The next T lines, each line contains three integers q,n,p, separated by spaces.
1≤T≤1001≤T≤100, 1≤n,q,p≤1091≤n,q,p≤109
输出描述:
For each test case, you need to output a single line with the integer S.
示例1
输入
复制
2
2 3 100
511 4 520
输出
复制
14
184
首先有一个基本的公式就是
a/b%c=a%(b*c)/b
此公式是用的就是在分母确定时 并且分子很大
那么我们列出等比数列求和公式