#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a, ll b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
ll a, b, c, d;
ll get(ll time) {
  if (time <= 0) return -a;
  ll hp = -a;
  hp -= time / d * a;
  ll ended = (time - c) / d + 1;
  if (time < c) ended = 0;
  ended = max(ended, 0ll);
  hp += ended * c * b;
  ll started = time / d;
  ll cur = started - ended;
  hp += d * (cur) * (cur + 1) / 2 * b;
  return hp;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    cin >> a >> b >> c >> d;
    if (a > b * c) {
      cout << -1 << '\n';
      continue;
    }
    if (d >= c) {
      cout << a << '\n';
      continue;
    }
    ll res = 0;
    ll L = 0, R = ((c + 1 + d) / d) * 2;
    while (R - L > 1) {
      ll m = (R + L) / 2;
      if (get(m * d - d) > get(m * d)) {
        L = m;
        res = get(m * d);
      } else
        R = m;
    }
    for (int i = -10; i < 10; i++) {
      res = min(res, get((L + i) * d));
    }
    cout << -res << '\n';
  }
  return 0;
}
