logo AlgoBeat OnlineJudge
登录 注册

#216181. [ICPC 2019 NAIPC] It' s a Mod, Mod, Mod, Mod World

内存限制:1024 MiB 时间限制:3000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

You are given multiple problems with three integers , , and . Find . That is, the first multiples of , modulo , summed. Note that the overall sum has no modulus.

输入格式

Each input will begin with a line with a single integer (), which is the number of cases you must solve.

Each of the next lines will contain three space-separated integers , and (), which are the parameters of the problem as described above.

输出格式

Output lines, each with the answer for a given instance of the problem, in the order that they appear in the input.

样例

样例输入 1

3
2 7 2
1 4 5
3 8 10

样例输出 1

6
7
37