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,k=c*(k//cc),k%cc ok,ng=0,c 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)