## https://yukicoder.me/problems/no/573 def calc_gcd(A, B): """ 正の整数A, Bの最大公約数を計算する """ a = max(A, B) b = min(A, B) while a % b > 0: c = a % b a = b b = c return b def func(value, A, B, lcm, K): a = value // A b = value // B l = value // lcm x = value - a - b + l return x >= K def solve(A, B, K): gcd = calc_gcd(A, B) lcm = (A // gcd) * B low = 2 high = 2 * (10 ** 18) while high - low > 1: mid = (high + low) >> 1 if func(mid, A, B, lcm, K): high = mid else: low = mid if func(low ,A, B, lcm, K): return low else: return high def main(): T = int(input()) answers = [] for _ in range(T): A, B, K = map(int, input().split()) ans = solve(A, B, K) answers.append(ans) for ans in answers: print(ans) if __name__ == '__main__': main()