import math T = int(input()) ans = [0]*T for i in range(T): a, b, k = map(int, input().split()) l = a*b//math.gcd(a, b) lo = 1 hi = 1000000000000000000000 mid = 0 while hi-lo>1: mid = (lo + hi)//2 cnt = mid//a + mid//b - mid//l if mid-cnt<=k: lo = mid else: hi = mid ans[i] = lo for i in range(T): print(ans[i])