#include <bits/stdc++.h>
using namespace std;
long long t, a, b, c, d, ans;
long long F(long long x) {
  if (x >= c / d) {
    return a * (x + 1) - b * d * ((1 + c / d) * (c / d) / 2) -
           (x - (c / d)) * b * c;
  } else {
    return a * (x + 1) - b * d * ((1 + x) * x / 2);
  }
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> a >> b >> c >> d;
    if (a > b * c) {
      cout << "-1\n";
      continue;
    }
    long long l = 0, r = 1e6, m1, m2;
    for (long long i = 0; i < 50; i++) {
      m1 = (l + r) / 2;
      m2 = (m1 + r) / 2;
      if (m1 == m2) {
        if (m1 - 1 >= l) {
          m1--;
        } else if (m2 + 1 <= r) {
          m2++;
        } else {
          break;
        }
      }
      if (F(m1) > F(m2)) {
        r = m2;
      } else {
        l = m1;
      }
    }
    cout << F((l + r) / 2) << '\n';
  }
  return 0;
}
