from math import gcd def solve(): A, B, K = map(int, input().split()) L = A * B // gcd(A, B) lo = 0 hi = 10 ** 19 while hi - lo > 1: md = (hi + lo) // 2 cnt = md - md // A - md // B + md // L if cnt >= K: hi = md else: lo = md print(hi) T = int(input()) for _ in range(T): solve()