#include <bits/stdc++.h>
long long solve(long long a, long long b, long long c, long long d,
                long long x) {
  long long p = c / d, ans = 0;
  if (x - 1 >= p) return x * a - p * (p + 1) / 2 * d * b - (x - 1 - p) * b * c;
  return ans = x * a - b * d * x * (x - 1) / 2;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    long long a, b, c, d;
    scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
    a > b* c ? puts("-1")
             : printf("%lld\n",
                      solve(a, b, c, d, (int)(a / (long double)(b * d)) + 1));
  }
  return 0;
}
