import std; void main () { int T = readln.chomp.to!int; foreach (_; 0..T) { int A, B; long K; readln.read(A, B, K); auto ans = solve(A, B, K); writeln(ans); } } auto solve (int A, int B, long K) { /* 二分探索 */ long LCM = lcm(A, B); bool f (long x) { return (x - x/A - x/B + x/LCM) <= K; } long ok = 0, ng = 9*10L^^18; while (1 < abs(ok-ng)) { long mid = (ok+ng) / 2; if (f(mid)) { ok = mid; } else { ng = mid; } } return ok; } long gcd (long A, long B) { enforce(0 <= A && 0 <= B); enforce(!(A == 0 && B == 0)); while (0 < A) { long tmp = A; A = B % A; B = tmp; } return B; } long lcm (long A, long B) { return A/gcd(A, B)*B; } void read(T...)(string S, ref T args) { auto buf = S.split; foreach (i, ref arg; args) { arg = buf[i].to!(typeof(arg)); } }