#include <bits/stdc++.h>
using namespace std;
using ll = long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll a, b, c, d;
ll f(ll k) {
  ll day = d * (k - 1LL) + 1LL;
  ll health = -k * a;
  ll pass = 0LL;
  ll fail = k;
  while (fail - pass > 1LL) {
    ll mid = ll((fail + pass) / 2LL);
    if (d * (mid - 1LL) + 1LL + c <= day)
      pass = mid;
    else
      fail = mid;
  }
  health += b * c * pass;
  ll old_pass = pass;
  fail = 1000000000000LL;
  pass = 1LL + ll((day - 1LL) / d);
  ll recov = (pass - old_pass) * (day - 1LL - d * old_pass);
  ll tri = pass - old_pass - 1LL;
  recov -= ll((tri * (tri + 1LL)) / 2LL) * d;
  recov *= b;
  health += recov;
  return health;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  bool thing = 0;
  for (int tes = 1; tes <= t; tes++) {
    cin >> a >> b >> c >> d;
    if (a > b * c) {
      if (!thing) cout << "-1\n";
      continue;
    }
    ll L = 1LL;
    ll R = 1000000LL;
    while (R - L >= 3) {
      ll m1 = L + ll((R - L) / 3LL);
      ll m2 = R - ll((R - L) / 3LL);
      ll f1 = f(m1);
      ll f2 = f(m2);
      if (f1 > f2)
        L = m1;
      else
        R = m2;
    }
    ll minn = 0LL;
    for (ll i = L; i <= R; i++) minn = min(minn, f(i));
    if (!thing) cout << -minn << "\n";
  }
}
