from collections import * from functools import * from itertools import * from heapq import * import sys,math input = sys.stdin.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<<100) x = 0 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()