from math import gcd t = int(input()) for _ in range(t): ai, bi, ki = [int(x) for x in input().split()] li = ai // gcd(ai, bi) * bi left = 0 right = li * ki 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)