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) { /* 二分探索 */ /* 1WA: 条件が間違ってた */ long LCM = lcm(A, B); bool f (long x) { return K <= (x - x/A - x/B + x/LCM); } long ok = 9*10L^^18, ng = 0; 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)); } }