import math t=int(input()) for i in range(t): a,b,k = map(int,input().split()) lc = (a*b)//math.gcd(a,b) ok = 0 ng = 2000000000000000000 while abs(ok-ng)>1: mid = (ok+ng)//2 cna = mid//a cnb = mid//b cnab = mid//(lc) if (mid-(cna+cnb-cnab)<=k):ok=mid else:ng = mid while ok%a==0 or ok%b==0:ok-=1 print(ok)