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