from math import * t = int(input()) for i in range(t): a,b,k = map(int,input().split()) g = gcd(a,b) n = a//g*b right = 10**20 left = 0 while abs(right-left) > 1: mid = (right+left)//2 if mid-(mid//a)-(mid//b)+(mid//n) >= k: right = mid else: left = mid print(right)