import math t = int(input()) for _ in range(t): a, b, k = map(int, input().split()) l = math.lcm(a, b) lo, hi = 0, 2 * 10 ** 18 while lo + 1 < hi: mid = (lo + hi) // 2 cnt = mid - mid // a - mid // b + mid // l if cnt >= k: hi = mid else: lo = mid print(hi)