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