I=input def f(): return N-N//A-N//B+N//C for t in range(int(I())): A,B,K=map(int,I().split()) C,D=A,B if A>B:C,D=D,C while C:C,D=D%C,C C=A*B//D N=int((K+1)/(1-1/A-1/B+1/C)) while f()>=K:N-=1 while f()