t=int(input()) import math for _ in range(t): a,b,k=map(int,input().split()) g=math.gcd(a,b) c=(a*b)//g l=50 m=int(k*a*b*c/(a*b*c-a*c-b*c+a*b)) for i in range(max(1,m-l),m+l): if i-(i//a+i//b-i//((a*b)//g))==k: print(i) break