#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  long long k = c / d;
  long long period = k * d * b + (c - k * d) * b - a;
  if (period < 0) {
    cout << -1 << "\n";
    return;
  }
  long long L = -1, R = k + 1;
  while (R - L > 1) {
    long long m = (R + L) / 2;
    if (m * d * b < a)
      L = m;
    else
      R = m;
  }
  long long h = R - 1;
  long long ans = 0 - (1 + h) * h / 2 * b * d + a * (h + 1);
  cout << ans << "\n";
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
