#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; } } vector v(n); v[n-1]=-R*(R+1)/2; ll tmp=(w-R)/(n-1); ll u=w-R-tmp*(n-1); for(int i=0;i+1a)break; ll uu=min(rem,a/j); v[0]+=uu; a-=uu*j; } } printf("%lld\n",v[0]); } } else{ if(a==0){ // ここもOK if(w>=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