#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
template <typename T>
inline T& ckmin(T& a, T b) {
  return a = a > b ? b : a;
}
template <typename T>
inline T& ckmax(T& a, T b) {
  return a = a < b ? b : a;
}
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
void solve() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a > b * c) return cout << -1 << '\n', void();
  ll h = c / d;
  auto result_after = [&](ll k) {
    ll res = -a * k;
    if (k <= h) {
      res += k * (k - 1) / 2 * b * d;
      return res;
    }
    res += (k - 1 - h) * b * c;
    res += h * (h + 1) / 2 * b * d;
    return res;
  };
  ll t = (2 * a + b * d) / (2 * b * d);
  42;
  42;
  cout << abs(min(result_after(t), result_after(t + 1))) << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
