import sys input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 63 - 1 mod = 998244353 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 def solve(): p, q, k = mi() ok = 9 * 10 ** 18 ng = 0 while abs(ok - ng) > 1: mid = (ok + ng) // 2 if check(mid, p, q) > k: ok = mid else: ng = mid print(ok - 10) def check(n, p, q): b = n - p * (n // p) return floor_sum(n // p - 1, q, p, b) for _ in range(ii()): solve()