#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll a, b, c, d;
ll q(ll x) { return x * (x + 1) / 2 * d * b - a * x - a; }
void solve() {
  cin >> a >> b >> c >> d;
  ll l = 0, r = c / d, ans = 0;
  while (l <= r) {
    ll m1 = l + (r - l) / 3, m2 = r - (r - l) / 3;
    ll c1 = -q(m1), c2 = -q(m2);
    if (c1 > c2) {
      ans = c1;
      r = m2 - 1;
    } else {
      ans = c2;
      l = m1 + 1;
    }
  }
  ll k = c / d;
  ll pre = k * (k + 1) / 2 * d * b - k * a;
  ll add = k * d * b + (c % d) * b - a;
  if (add < 0) {
    cout << -1;
    return;
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    solve();
    cout << "\n";
  }
}
