T=int(input()) import math for _ in range(T): a,b,k=map(int, input().split()) c=a*b//math.gcd(a,b) ok,ng=0,2**62 while (ng-ok)>1: mid=(ok+ng)//2 d=mid-mid//a-mid//b+mid//c if d>=k: ng=mid else: ok=mid print(ng)