405232: GYM101853 G Hard Equation

Memory Limit:256 MB Time Limit:10 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

G. Hard Equationtime limit per test10 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Consider the following equation

Given a, b and m, your task is to find a value x that satisfy the equation for the given values. Can you?

Input

The first line contains an integer T (1 ≤ T ≤ 500), in which T is the number of test cases.

Each test case consists of a line containing three integers a, b and m (0 ≤ a, b < m ≤ 109).

Output

For each test case, print a single line containing an integer x (0 ≤ x ≤ 1017) that satisfy the equation , for the given a, b and m.

If there are multiple solutions, print any of them. It is guaranteed that an answer always exist for the given input.

ExampleInput
3
3 9 11
2 3 5
2 1 5
Output
2
3
4

加入题单

上一题 下一题 算法标签: