from math import gcd import sys t = int(input()) for _ in range(t): ai, bi, ki = [int(x) for x in input().split()] li = ai // gcd(ai, bi) * bi ui = li - li // ai - li // bi + 1 pi = (ki + ui - 1) // ui left = li * (pi - 1) right = li * pi + 1 print(ai, bi, ki, li, ui, pi, ";", left, right, file=sys.stderr) while right - left > 1: mid = (right + left) // 2 x = mid - mid // ai - mid // bi + mid // li if x >= ki: right = mid else: left = mid print(right)