#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  register long long x = 0;
  register bool f = 0;
  register char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + c - 48;
    c = getchar();
  }
  return f ? -x : x;
}
char cr[200], str[200];
long long tt;
inline void print(long long x, char k = '\n') {
  if (!x) putchar('0');
  if (x < 0) putchar('-'), x = -x;
  while (x) cr[++tt] = x % 10 + '0', x /= 10;
  while (tt) putchar(cr[tt--]);
  putchar(k);
}
const long long maxn = 120005;
long long t;
signed main() {
  t = read();
  while (t--) {
    long long a = read(), b = read(), c = read(), d = read();
    long long tim = c / d;
    long long mx = tim * b * d + (c - d * tim) * b;
    if (a > mx) {
      print(-1);
      continue;
    }
    long long g = a / (b * d);
    long long sh = (g + 1) * a;
    long long hf = (b * d) * (g + 1) * g / 2;
    print(sh - hf);
  }
  return 0;
}
