I=input 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 L,R=1,2**62 while L