#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a > b * c) {
      cout << "-1\n";
      continue;
    }
    c = min(c, (a + b - 1) / b);
    long long l = 1, r = (c + 1) / d + 1;
    while (l < r) {
      long long md = (l + r + 1) >> 1;
      if (a > (md * (md - 1) / 2 - (md - 1) * (md - 2) / 2) * d * b)
        l = md;
      else
        r = md - 1;
    }
    cout << l * a - l * (l - 1) / 2 * d * b << "\n";
  }
  return 0;
}
