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