#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  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 == 1 ? x : -x;
}
inline void print(long long x) {
  if (x < 0) putchar('-'), x = ~x + 1;
  if (x >= 10) print(x / 10);
  putchar((x % 10) | 48);
}
long long T;
long long a, b, c, d, ans;
long long solve(long long x) {
  long long res = x * a;
  if (x * d >= c) res -= (x * d - c) / d * c * b;
  long long k = (c - 1) / d;
  if (x * d >= c)
    res -= (d + k * d) * k / 2 * b;
  else {
    res -= (d + (x - 1) * d) * (x - 1) / 2 * b;
  }
  ans = max(ans, res);
  return res;
}
signed main() {
  T = read();
  while (T--) {
    a = read(), b = read(), c = read(), d = read();
    if (a > b * c)
      printf("-1\n");
    else {
      long long tmp = a / b;
      printf("%lld\n", max(solve(tmp / d), solve(tmp / d + 1)));
    }
  }
}
