T=int(input()) from sys import stdin, setrecursionlimit input = stdin.readline readline = stdin.readline import math for _ in range(T): a,b,k=map(int, input().split()) c=a*b//math.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)