#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){ 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; } } printf("%lld\n",-R*(R+1)/2); } } else{ if(a==0){ if(w>=1+(n-k)){ printf("-1\n"); } else{ printf(":(\n"); } } else{ ll L=-1,R=2e9; while(R-L>1){ ll mid=(L+R)/2; if((k-1)*(mid+1)+mid<=a)L=mid; else R=mid; } if(L==-1)printf(":(\n"); else printf("%lld\n",L); } } } }