import math T = int(input()) for _ in range(T) : a, b, k = map(int, input().split()) L = math.lcm(a, b) num = L - (L // a) - (L // b) + 1 ans1 = k // num k %= num k += 1 ok = L - 1 ng = 0 while abs(ok - ng) > 1 : md = (ok + ng) // 2 nn = (md + 1) - (md // a + 1) - (md // b + 1) + 1 if nn >= k : ok = md else : ng = md print(ans1 * L + ok)