#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d;
long long calc(long long x) { return (1 + x) * x / 2ll; }
long long g(long long x) {
  long long bg = (x - 1) * d + 1;
  long long ans = -x * a + (bg > c ? b * c * ((bg - c - 1) / d + 1) : 0ll) +
                  d * b * calc(min(x - 1, c / d));
  return ans;
}
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int main() {
  long long aq = read();
  while (aq--) {
    a = read(), b = read(), c = read(), d = read();
    if (a > b * c) {
      puts("-1");
      continue;
    }
    long long l = 1, r = 1e9;
    while (l < r) {
      long long mid = (l + r) >> 1;
      if (g(mid) > g(mid + 1))
        l = mid + 1;
      else
        r = mid;
    }
    printf("%lld\n", -g(l));
  }
  return 0;
}
