#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a > b * c)
      cout << -1 << endl;
    else {
      long long res = 0;
      long long i = a / (b * d);
      res = max(res, a * (i + 1) - i * (i + 1) / 2 * b * d);
      cout << res << endl;
    }
  }
}
