#include <bits/stdc++.h>
using namespace std;
long long brut(long long a, long long b, long long c, long long d) {
  long long h = 0;
  long long heal = 0;
  long long mx = 0;
  long long cnt = 0;
  while (h >= 0) {
    h -= heal;
    if (cnt % d == 0) {
      h += a;
      mx = max(mx, h);
      heal += b;
    }
    if ((cnt - c) > 0 && (cnt - c) % d == 0) {
      heal -= b;
    }
    cnt++;
  }
  return mx;
}
void solve() {
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a > b * c)
    cout << -1 << endl;
  else {
    long long e = d * b;
    long long f = (a + e - 1) / e;
    if (c <= d) {
      cout << a * f - b * c * (f - 1) << endl;
    } else {
      long long tot = (f - 1) * d;
      if (c >= tot) {
        long long t = f * d * (f - 1) / 2;
        cout << a * f - t * b << endl;
      } else {
        long long full = c / d;
        long long heal = (f - 1 - full) * c * b;
        long long sum = (full + 1) * d * (full) / 2;
        cout << a * f - heal - sum * b << endl;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
