Each input will begin with a line with a single integer W (1 ≤ W ≤ 105), which is the number of cases you must solve.
Each of the next W lines will contain three space-separated integers p, q and n (1 ≤ p, q, n ≤ 106), which are the parameters of the problem as described above.