#include <bits/stdc++.h>
using namespace std;
template <class T, class T1>
int chkmin(T &x, const T1 &y) {
  return x > y ? x = y, 1 : 0;
}
template <class T, class T1>
int chkmax(T &x, const T1 &y) {
  return x < y ? x = y, 1 : 0;
}
const int MAXN = (1 << 20);
const int64_t inf = (int64_t)4e18;
int a, b, c, d;
void read() { cin >> a >> b >> c >> d; }
int64_t eval(int64_t x) {
  int64_t dmg = -x * a;
  int64_t moments = (x - 1) * d;
  int64_t full_heals = moments / c;
  if (full_heals > inf / (b * 1ll * c)) return inf;
  dmg += full_heals * b * 1ll * c;
  int64_t partial = (x - 1) - full_heals;
  if (partial > (int64_t)2e9) return inf;
  if (partial > inf / d) return inf;
  int64_t S = (partial + 1) * partial / 2ll;
  if (S > inf / (d * 1ll * b)) return inf;
  S *= d * 1ll * b;
  dmg += S;
  return dmg;
}
void solve() {
  if (a > b * 1ll * c) {
    cout << -1 << '\n';
    return;
  } else {
    if (a <= b * 1ll * d) {
      cout << a << '\n';
      return;
    }
    int64_t low = 1, high, mid, ret = -a;
    high = 1;
    int64_t tmp;
    while ((tmp = eval(high)) <= -a) {
      high *= 2;
      chkmin(ret, tmp);
    }
    while (high - low >= 2) {
      mid = low + (high - low) / 2;
      int64_t e1 = eval(mid), e2 = eval(mid + 1);
      chkmin(ret, e1);
      chkmin(ret, e2);
      if (e1 <= e2) {
        high = mid;
      } else {
        low = mid + 1;
      }
    }
    for (int i = low; i <= high; i++) {
      chkmin(ret, eval(i));
    }
    cout << -ret << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  cin >> T;
  while (T--) {
    read();
    solve();
  }
  return 0;
}
