#include <bits/stdc++.h>
using namespace std;
int T, A, B, C, D;
long long ans;
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d%d%d", &A, &B, &C, &D);
    if (A > 1ll * B * C) {
      printf("-1\n");
      continue;
    }
    if (D >= C) {
      printf("%d\n", A);
      continue;
    }
    int k = max(0.0, ((2.0 * A / (1.0 * B * D)) - 1) * 0.5);
    ans = max(1ll * (k + 1) * A - (1ll * k * (k + 1) / 2) * B * D,
              1ll * (k + 2) * A - (1ll * (k + 1) * (k + 2) / 2) * B * D);
    printf("%lld\n", max(ans, 0ll));
  }
  return 0;
}
