import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); } long mod = 10^^9 + 7; //long mod = 998_244_353; //long mod = 1_000_003; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); } void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); } T binarySearch(alias pred, T)(T ok, T ng) { while (abs(ok-ng) > 1) { auto mid = (ok+ng)/2; if (unaryFun!pred(mid)) ok = mid; else ng = mid; } return ok; } void main() { auto T = RD; auto ans = new long[](T); foreach (ti; 0..T) { auto N = RD; auto A = RD; auto W = RD; auto K = RD; if (A < K-1 && W < N+1-K) ans[ti] = -1; else if (N != K) ans[ti] = (A-1) / K; else { auto cnt = (W+N) / N; auto rem = W % N; auto w1 = cnt*(cnt+1)/2; auto w2 = cnt*(cnt-1)/2; auto B = A - (w1 * rem + w2 * (N - rem)); if (A >= rem-1) ans[ti] = (B-1) / K; else { auto ww = cnt+1; auto w = (W-ww+(N-1)) / (N-1); auto rem2 = (W-ww) % (N-1); auto v1 = cnt*(cnt+1)/2; auto v2 = cnt*(cnt-1)/2; auto C = v1 * rem2 + v2 * (N - 1 - rem2); bool f(long x) { auto D = ((A-x) - C + N - 2) / (N-1); return x + ww*(ww+1)/2 < D; } auto r = binarySearch!(f)(0, A+1); ans[ti] = r + ww*(ww+1)/2; } } } foreach (e; ans) writeln(e == -1 ? ":(" : e.to!string); stdout.flush; debug readln; }