from math import gcd def floor_sum(n,m,a,b): ans=0 while True: if a>=m: ans+=(n-1)*n*(a//m)//2 a%=m if b>=m: ans+=n*(b//m) b%=m y_max=(a*n+b)//m x_max=(y_max*m-b) if y_max==0: return ans ans+=(n-(x_max+a-1)//a)*y_max n,m,a,b=y_max,a,m,(a-x_max%a)%a T = int(input()) for _ in range(T): P,Q,K=map(int,input().split()) ok = 10 ** 18 ng = 0 def isok(z): r = z//P if floor_sum(r+1,Q,P,Q+z-P*r)-1>= K: return True else: return False while ok -ng > 1: z = (ok+ng)>>1 if isok(z): ok = z else: ng = z print(ok)