from collections import * from functools import * from itertools import * from heapq import * import sys,math input = sys.stdin.buffer.readline # sys.maxsize = (1<<64) - 1 def answer(): A,B,K = map(int,input().split()) def is_ok(x): tmp = (x//A) + (x//B) - (x//(A*B//math.gcd(A,B))) return x-tmp >= K y = min((1<<62),K*A*B) x = K-1 while y-x>1: mid = (y+x)//2 if is_ok(mid): y = mid else: x = mid print(y) for _ in range(int(input())): answer()