t=int(input()) import math for _ in range(t): a,b,k=map(int,input().split()) g=math.gcd(a,b) ok=0 ng=10**30 while abs(ok-ng)>1: m=(ok+ng)//2 if m-(m//a+m//b-m//((a*b)//g))<=k: ok=m else: ng=m print(ok)