#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e6 + 7;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  for (long long _ = 0; _ < t; ++_) {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a > b * c) {
      cout << -1 << endl;
      continue;
    }
    long long l = 0;
    long long r = INF;
    while (r - l > 1) {
      long long med = (l + r) / 2;
      if (d * med >= c) {
        r = med;
        continue;
      }
      if (d * med * b < a) {
        l = med;
      } else {
        r = med;
      }
    }
    long long ans = (l * (l + 1) / 2ll) * d * b - (l + 1) * a;
    cout << -ans << endl;
  }
  return 0;
}
