#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long a = 0, fh = 1;
  char c = getchar();
  while (c > '9' || c < '0') {
    if (c == '-') fh = -1;
    c = getchar();
  }
  while ('0' <= c && c <= '9') {
    a = a * 10 + c - 48;
    c = getchar();
  }
  return a;
}
long long a, b, c, d;
long long calc(long long k) {
  if (k == 1) return 0;
  if ((k - 1) * d <= c) {
    return (k * (0 + (k - 1) * d * b)) / 2;
  }
  long long val = (k - 1) * b * c;
  long long cnt = c / d, tmp = c % d;
  val -= cnt * (tmp + c - d) * b / 2;
  return val;
}
signed main() {
  long long T = read();
  while (T--) {
    a = read(), b = read(), c = read(), d = read();
    if (a > b * c) {
      puts("-1");
      continue;
    }
    if (c <= d) {
      printf("%lld\n", a);
      continue;
    }
    long long l = 0, r = 2e6;
    while (l + 1 < r) {
      long long mid = (l + r) >> 1;
      if (calc(mid) - calc(mid - 1) <= a) {
        l = mid;
      } else
        r = mid;
    }
    printf("%lld\n", a * l - calc(l));
  }
  return 0;
}
