import math def LCM(n,m): if n or m: return abs(n)*abs(m)//math.gcd(n,m) return 0 def Bisect_Int(ok,ng,is_ok): while abs(ok-ng)>1: mid=(ok+ng)//2 if is_ok(mid): ok=mid else: ng=mid return ok T=int(input()) for t in range(T): A,B,K=map(int,input().split()) def is_ok(x): return x-1-(x-1)//A-(x-1)//B+(x-1)//LCM(A,B)