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