import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random #sys.setrecursionlimit(10**9) input = sys.stdin.readline def solve(): a,b,k = map(int,input().split()) c = a*b//math.gcd(a,b) l,r = 0,10**20 while r-l > 1: m = (l+r)//2 cnt = m // a + m // b - m // c if m - cnt >= k: r = m else: l = m print(r) for _ in range(int(input())): solve()