T = int(input()) import math def is_ok(x,a,b,k): # xに対して、aでもbでも割り切れない数がk個以上存在すればTrue g = math.gcd(a, b) L = a // g * b cnt = x - (x // a) - (x // b) + (x // L) return cnt >= k for _ in range(T): A,B,K = map(int,input().split()) ok = 10 ** 19 ng = 0 while abs(ok - ng) > 1: mid = abs(ok + ng) // 2 if is_ok(mid, A, B, K): ok = mid else: ng = mid print(ok)