#include <bits/stdc++.h>
using namespace std;
long long mo(long long a) { return a % (long long)(1e9 + 7); }
long long po(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y >>= 1;
    x = (x * x) % p;
  }
  return res % p;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a - b * c > 0) {
      cout << -1 << "\n";
    } else {
      if (d >= c) {
        cout << a << "\n";
      } else {
        long long k = (2 * a + b * d) / d / b / 2;
        long long ans = max(k * a - ((k * (k - 1)) / 2) * d * b,
                            (k + 1) * a - (k * (k + 1) / 2) * d * b);
        cout << ans << "\n";
      }
    }
  }
  return 0;
}
