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