CF1836B Astrophysicists
/* 5 3 3 100 2 1 14 91 2 13 36 16 6 73 8 22 100 0 26 72 176 */ /* */ #include<cstdio> #include<iostream> #include<algorithm> #include<cmath> #include<string.h> //#include<queue> //#include<vector> //#include<bits/stdc++.h> #define ll long long #define ddd printf("-----------------------\n"); using namespace std; const int maxn=1e1 +10; const int mod=998244353; const int inf=0x3f3f3f3f; ll n,g,k; int main() { ios::sync_with_stdio(false); int T;cin>>T; while(T--) { cin>>n>>k>>g; ll t=max(0ll,k*g-(n-1)*((g-1)/2)); if(t%g>=((g+1)/2)) cout<<(k-(t+g-1)/g)*g<<'\n'; else cout<<(k-t/g)*g<<'\n'; } return 0; }