from collections import * from functools import * from itertools import * from heapq import * import sys,math input = sys.stdin.buffer.readline 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 = (1<<63) 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()