#include using namespace std; typedef long long int ll; typedef unsigned long long ull; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll myRand(ll B) { return (ull)rng() % B; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int q; cin >> q; while(q--){ ll n,a,w,k; cin >> n >> a >> w >> k; if(k==1){ // 多分OK if(a)printf("%lld\n",a); else{ if(w1){ ll mid=(L+R)/2; ll tmp=(w-mid)/(n-1); ll m=tmp*(tmp+1)/2*(n-1); ll u=w-tmp-tmp*(n-1); ll uu=(n-1)-u; ll aa=((mid*(mid+1)/2-1)>=m+(tmp+1)?0:(mid*(mid+1)/2-1)-m-(tmp+1)); aa*=u; ll aaa=((mid*(mid+1)/2-1)>=m?0:(mid*(mid+1)/2-1)-m); aaa*=uu; if(aa+aaa<=a){ R=mid; } else{ L=mid; } } ll pi=(w+n-1)/n; L=max(R,pi); ll ans=-1e18; auto calc=[&](ll val,ll rem)->ll{ ll b=(w-val)/(n-1); ll bb=b+1; ll cc=w-val-b*(n-1); ll c=n-1-cc; b=b*(b+1)/2,bb=bb*(bb+1)/2; val=val*(val+1)/2; ll res=-val; ll u=min(max(0LL,val-bb-1),rem); rem-=u; val+=u; res+=u; u=min(max(0LL,val-b-1),rem/(cc+1)); res+=u; val+=u; rem-=u*(cc+1); res+=rem/n; return res; }; R=w; for(int i=0;i<50 and L+100=1+(n-k)){ printf("-1\n"); } else{ printf(":(\n"); } } else if(k-1<=a){ // ここも多分OKなはず… ll L=0,R=2e9; while(R-L>1){ ll mid=(L+R)/2; if((k-1)*(mid+1)+mid<=a)L=mid; else R=mid; } printf("%lld\n",L); } else{ if(w