#include <bits/stdc++.h>
using namespace std;
int t, a, b, c, d;
long long int check(int x) {
  long long int rt = 1LL * x * a - 1LL * d * b * (1LL * x * (x - 1) / 2);
  return rt;
}
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;
    }
    int l = 0, r = c / d + 1, m1 = 0, m2 = 0;
    while (l < r) {
      m1 = l + (r - l) / 3;
      m2 = l + 2 * (r - l) / 3;
      if (check(m2) > check(m1)) {
        l = m1 + 1;
      } else {
        r = m2;
      }
    }
    printf("%lld\n", max(check(l), max(check(l - 1), check(l + 1))));
  }
}
