import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); PrintWriter pw = new PrintWriter(System.out); for (int z = 0; z < t; z++) { String[] sa = br.readLine().split(" "); int a = Integer.parseInt(sa[0]); int b = Integer.parseInt(sa[1]); long k = Long.parseLong(sa[2]); long lcm = lcm(a, b); long ok = 4000000000000000000L; long ng = 0; while (Math.abs(ok - ng) > 1) { long mid = (ok + ng) / 2; long v1 = mid / a; long v2 = mid / b; long v3 = mid / lcm; long v4 = mid - v1 - v2 + v3; if (v4 >= k) { ok = mid; } else { ng = mid; } } pw.println(ok); } pw.flush(); br.close(); } static long lcm(long a, long b) { BigInteger ba = BigInteger.valueOf(a); BigInteger bb = BigInteger.valueOf(b); return ba.multiply(bb).divide(ba.gcd(bb)).longValue(); } }