#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll a, b, c, d;
const ll INF = 1e18;
ll nc2(ll n) { return (n * (n - 1)) / 2; }
ll diff(ll n) { return a - b * d * (nc2(n) - nc2(n - 1)); }
ll value(ll n) { return a * n - b * d * nc2(n); }
void solve() {
  cin >> a >> b >> c >> d;
  if (a > b * c) {
    cout << "-1\n";
  } else {
    ll lo = 1;
    ll hi = c;
    while (lo < hi) {
      ll mid = (hi + lo) / 2;
      if (diff(mid + 1) <= 0) {
        hi = mid;
      } else {
        lo = mid + 1;
      }
    }
    cout << value(lo) << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T;
  cin >> T;
  for (int i = 0; i < T; ++i) {
    solve();
  }
  return 0;
}
