from math import gcd def bis(ok, ng): while abs(ok - ng) > 1: md = (ng + ok) // 2 cnt = md - md//A - md//B + md//L if cnt >= K: ok = md else: ng = md return ok T = int(input()) for _ in range(T): A, B, K = map(int, input().split()) L = A // gcd(A, B) * B print(bis(10**19, 0))