#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
template <class T>
bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
void solve() {
  ll A, B, C, D;
  cin >> A >> B >> C >> D;
  if (B * C < A) {
    cout << -1 << "\n";
    return;
  }
  if (C <= D) {
    cout << A << "\n";
    return;
  }
  auto calc = [&](ll t) {
    ll x = max(0LL, (t * D - C) / D);
    ll h = -A * t + x * B * C;
    ll y = t - 1 - x;
    h += B * (y * (t - 1) * D - (2 * x * D + (y - 1) * D) * y / 2);
    return h;
  };
  ll l = 1, r = 1e6;
  while (l + 1 < r) {
    ll m = (l + r) / 2;
    (calc(m) >= calc(m + 1) ? l : r) = m;
  }
  cout << -min(calc(l), calc(l + 1)) << "\n";
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--) {
    solve();
  }
}
