#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng(
    (unsigned)chrono::system_clock::now().time_since_epoch().count());
const long double PI = acosl(-1);
long long int f(long long int a, long long int bd, long long int k) {
  return a * k - bd * (k - 1) * k / 2;
}
int main() {
  int tc;
  scanf("%d", &tc);
  for (int cs = 1; cs <= tc; cs++) {
    double a, b, c, d;
    scanf("%lf %lf %lf %lf", &a, &b, &c, &d);
    double bd = b * d;
    if (b * c < a) {
      printf("-1\n");
      continue;
    }
    long long int k = ((a + bd / 2) / (bd / 2) / 2);
    long long int x = f(a, bd, k);
    if ((k - 1) * d > c) x = f(a, bd, c / d + 1);
    long long int y = f(a, bd, k + 1);
    if (k * d > c) y = f(a, bd, c / d + 1);
    printf("%lld\n", max(x, y));
  }
  return 0;
}
