import sys sys.setrecursionlimit(10**7) #sys.set_int_max_str_digits(0) T=int(input()) import math for _ in range(T): a,b,k=map(int, input().split()) c=a*b//math.gcd(a,b) cc=c-c//a-c//b+1 ans=c*(k//cc) k=k%cc ok,ng=0,c+1 while (ng-ok)>1: mid=(ok+ng)//2 d=mid-mid//a-mid//b if d>=k: ng=mid else: ok=mid print(ans+ng)