""" https://yukicoder.me/problems/no/2526 """ import math import sys from sys import stdin TT = int(stdin.readline()) ANS = [] for loop in range(TT): A,B,K = map(int,stdin.readline().split()) lcm = A*B // math.gcd(A,B) L = -1 R = 10**19 while R-L != 1: M = (L+R)//2 now = M now -= M // A now -= M // B now += M // lcm if now >= K: R = M else: L = M ANS.append(R) print (*ANS,sep="\n")