#include <bits/stdc++.h>
using namespace std;
int T;
long long a, b, c, d;
int main() {
  scanf("%d", &T);
  for (; T--;) {
    scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
    if (b * c < a) {
      printf("-1\n");
      continue;
    }
    long long c2 = a / b + (a % b > 0) - 1;
    if (d > c2) {
      printf("%lld\n", a);
      continue;
    }
    long long k = c2 / d;
    long long ans = a * (k + 1) - d * b * (k + 1) * k / 2;
    printf("%lld\n", ans);
  }
  return 0;
}
