#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    if (c <= d) {
      if (a <= b * c)
        cout << a << endl;
      else {
        cout << -1 << endl;
      }
    } else {
      long long len = c % d ? c / d + 1 : c / d;
      long long ans = 0;
      long long x = (b * d + 2 * a) / 2 / b / d;
      x = min(x, len);
      ans = a * x - x * (x - 1) / 2 * b * d;
      x++;
      x = min(x, len);
      ans = max(ans, a * x - x * (x - 1) / 2 * b * d);
      if (a > b * c)
        cout << -1 << endl;
      else {
        ans = max(ans, a * len - (len - 1) * len / 2 * d * b);
        cout << ans << endl;
      }
    }
  }
}
