#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d;
long long calc(long long pos) {
  long long done = pos / d + 1;
  long long res = done * (2 * pos + (done - 1) * (-d)) / 2;
  return done * a - res * b;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> a >> b >> c >> d;
    if (b >= a) {
      cout << a << "\n";
      continue;
    }
    if (c * b < a) {
      cout << "-1\n";
      continue;
    }
    long long ans = 0;
    int left = 0, right = c / d;
    while (left <= right) {
      int mid = (left + right) >> 1;
      if (calc(mid * d) < calc((mid + 1) * d)) {
        left = mid + 1;
      } else {
        ans = max(ans, calc(mid * d));
        right = mid - 1;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
