#include <bits/stdc++.h>
using namespace std;
int pp[11];
struct P {
  int x, y;
  bool operator<(const P &a) const { return x - pp[y] > a.x - pp[a.y]; };
};
int a, b, c, d, i, n, m, e, k, dx[10] = {1, 0, -1, 0, 1, 1, -1, -1},
                               dy[10] = {0, 1, 0, -1, 1, -1, 1, -1};
int o[301011];
int l[101011];
int ss[222221];
long long x, y, z, mod = 1000000007, hf = (mod + 1) / 2;
char r[201001][2], r2[1];
vector<int> v;
P u[1];
priority_queue<P> q;
stack<int> s;
map<long long, int> p;
bool as(P a, P b) {
  if (a.x != b.x) return a.x < b.x;
  return a.y < b.y;
}
long long f(long long a, long long b, long long n) {
  if (n && mod * mod / b / d / (n * (n + 1) / 2) == 0) return -mod * mod * 4;
  return a * (n + 1) - b * d * (n + 1) * (n) / 2;
}
int main() {
  int ttt;
  scanf("%d", &ttt);
  for (int tt = 1; tt <= ttt; tt++) {
    scanf("%d %d %d %d", &a, &b, &c, &d);
    if (a > (long long)b * c) {
      puts("-1");
      continue;
    }
    if (c <= d) {
      printf("%d\n", a);
      continue;
    }
    n = 0, m = 1000000;
    for (; n + 1 < m;) {
      int h1 = (n * 2 + m) / 3, h2 = (n + m * 2) / 3 + 1;
      if (f(a, b, h1) < f(a, b, h2))
        n = h1 + 1;
      else
        m = h2 - 1;
    }
    printf("%lld\n", max(f(a, b, n), f(a, b, m)));
  }
}
