import sys def input(): return sys.stdin.readline().strip() def mapint(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) from math import gcd T = int(input()) for _ in range(T): A, B, K = mapint() lc = A*B//gcd(A, B) l = 0 r = 10**18 * 20 while l+1= K): r = tar else: l = tar print(r)