T=int(input()) def gcd(x, y): if y == 0: return x else: return gcd(y, x % y) for _ in range(T): a,b,k=map(int, input().split()) c=a*b//gcd(a,b) ok,ng=0,10**20+1 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)