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