#include <bits/stdc++.h>
using namespace std;
void blowback() {
  long long i, j, l, k, n, m, x, y, r, ans = 0, sum = 10e17;
  string s;
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a > (b * c)) {
    cout << "-1\n";
    return;
  }
  k = (2 * a - b * d) / (2 * b * d);
  l = k + 1;
  k = min(k, c / d);
  l = min(l, c / d);
  ans = (a * (k + 1)) - ((k * (k + 1)) * b * d) / 2;
  k = l;
  sum = (a * (k + 1)) - ((k * (k + 1)) * b * d) / 2;
  cout << max({ans, sum, a}) << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  cin >> t;
  while (t--) {
    blowback();
  }
  return 0;
}
