from math import lcm T = int(input()) def func(n): return n-n//A-n//B+n//LCM for _ in range(T): A, B, K = map(int, input().split()) LCM = lcm(A, B) left = 0 right = 10**18*6 while left+1 < right: mid = (left+right)//2 if func(mid) < K: left = mid else: right = mid print(right)