#include <bits/stdc++.h>
using namespace std;
long long T, a, b, c, d;
inline long long read() {
  long long f = 1, x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = x * 10 + s - '0';
    s = getchar();
  }
  return x * f;
}
inline long long f(long long t) {
  return t * (t + 1) / 2 * b * d - (t + 1) * a;
}
signed main() {
  T = read();
  while (T--) {
    a = read();
    b = read();
    c = read();
    d = read();
    if (b * c < a) {
      printf("-1\n");
      continue;
    }
    long long n = c / d, MAX = 1, t;
    long double x = 1.0 * a / (b * d) - 0.5;
    t = ceil(x);
    if (t <= n && t >= 0) MAX = max(MAX, -f(t));
    t = floor(x);
    if (t <= n && t >= 0) MAX = max(MAX, -f(t));
    MAX = max(MAX, -f(0));
    MAX = max(MAX, -f(n));
    MAX = max(MAX, -f(n + 1) + b * ((n + 1) * d - c));
    printf("%lld\n", MAX);
  }
}
