import math T=int(input()) answers=[] def solve(A,B,K): c=math.lcm(A,B) ng=0 ok=10**19 while (ok-ng)>1: m=(ok+ng)//2 if(m-(m//B)-(m//A)+(m//c)>=K): ok=m else: ng=m return ok def gutyoku(A,B,K): ans=0 while K>0: ans+=1 if(ans%A==0 or ans%B==0): continue else: K-=1 return ans for i in range(T): A,B,K=map(int,input().split()) ans=solve(A,B,K) answers.append(ans) for ans in answers: print(ans)