def gcd(a,b): if b==0: return a return gcd(b,a%b) def lcm(a,b): return (a*b)//gcd(a,b) for _ in range(int(input())): A,B,K=map(int,input().split()) C=lcm(A,B) L,R=0,1<<65 while R-L>1: mid=(L+R)//2 cnt=mid-(mid//A+mid//B-mid//C) if cnt>=K: R=mid else: L=mid print(R)