#include <bits/stdc++.h>
using namespace std;
const int N = 1;
const int M = N + 7;
const int MOD = 1e9 + 7;
const long long INF = 1e16 + 17;
void solve() {
  long long a, b, c, d;
  scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
  long long ans = -1;
  if (d >= c) {
    if (a <= 1LL * b * c) ans = a;
  } else {
    long long cnt = c / d;
    long long delt = cnt * b * d + (c % d * b);
    if (delt >= a) {
      long long l = 0, r = cnt + 1;
      while (r - l > 1) {
        long long m = (l + r) >> 1;
        long long cur = m * b * d;
        if (cur >= a)
          r = m;
        else
          l = m;
      }
      ans = (l + 1) * l / 2 * b * d;
      ans = (l + 1) * a - ans;
    }
  }
  printf("%lld\n", ans);
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}
