def gcd(a,b): if b==0: return a return gcd(b,a%b) T = int(input()) for _ in range(T): a,b,k = map(int,input().split()) d = gcd(a,b) m = a*b//d high = 10**19 low = 0 while high-low>1: mid = (high+low)//2 cnt = mid//a+mid//b-mid//m cnt = mid-cnt if cnt>=k: high = mid else: low = mid print(high)