#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d;
long long f(long long k) { return (d * b * k - 2 * a) * (k + 1) / -2; }
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> a >> b >> c >> d;
    if (a > b * c) {
      cout << "-1\n";
      continue;
    }
    double k = a * 1.0 / (d * b) - 0.5;
    cout << max(f(k), f(k + 1)) << '\n';
  }
}
