#include <bits/stdc++.h>
using namespace std;
long long f(long long k, long long a, long long b, long long c, long long d) {
  return a * (k + 1) - b * d * k * (k + 1) / 2;
}
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a > c * b) {
      cout << -1 << endl;
      continue;
    }
    long long l = 0, r = c / d;
    long long k;
    if (2 * a - b * d < 0)
      k = 0;
    else if (2 * a - b * d > r * 2 * b * d)
      k = r;
    else {
      long double x = 1.0l * a / (b * d) - 0.5l;
      long long k1 = floor(x), k2 = ceil(x);
      if (k1 < 0) k1 = 0;
      if (k2 > r) k2 = r;
      if (f(k1, a, b, c, d) > f(k2, a, b, c, d))
        k = k1;
      else
        k = k2;
    }
    cout << f(k, a, b, c, d) << endl;
  }
  return 0;
}
