#include using namespace std; int main(){ int T; cin >> T; for (int i = 0; i < T; i++){ int N, A, W, K; cin >> N >> A >> W >> K; if (K != N || W == 0){ if (A < K - 1){ if (W >= N - K + 1){ cout << -1 << endl; } else { cout << ":(" << endl; } } else if (A % K == K - 1){ cout << A / K << endl; } else { cout << A / K - 1 << endl; } } else { long long sum = A - (long long) W * (W + 1) / 2; int r = (sum % N + N) % N; long long q = (sum - r) / N; if (r != N - 1){ q--; } long long fv = 0, tv = W + 1; while (tv - fv > 1){ long long mid = (tv + fv) / 2; if (- mid * (mid + 1) / 2 <= q){ tv = mid; } else { fv = mid; } } long long s = - tv * (tv + 1) / 2; if (s + A > q){ cout << q << endl; } else { cout << s + A << endl; } } } }