#include #include using namespace std; using namespace atcoder; typedef long long ll; int main(){ int t; cin >> t; while(t){ t--; ll p,q,k; cin >> p >> q >> k; ll le = 0,ri = 1000000000000000000; while(ri - le>1){ ll mid = (le + ri)/2; ll n = min(mid/p,q - 1); if(floor_sum(n + 1,q,p,mid + q - n*p)>=k + 1) ri = mid; else le = mid; } cout << ri << "\n"; } }