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