import math def gcd(a, b): return math.gcd(a, b) def judge(X, A, B, C, K): return X - (X//A + X//B - X//C) <= K def solve(): A, B, K = map(int, input().split()) assert A != B assert 2 <= A <= 1e9 assert 2 <= B <= 1e9 assert 1 <= K <= 1e18 C = A * B // gcd(A, B) l = 0 r = 4e18 while r - l > 1: c = (l + r) // 2 if judge(c, A, B, C, K): l = c else: r = c l = int(l) mi = max(1, l - 5) for X in range(mi, l + 1): if X - (X//A + X//B - X//C) == K and X % A != 0 and X % B != 0: print(X) return assert False T = int(input()) for _ in range(T): solve()