from math import gcd import sys input = sys.stdin.readline 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 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)