#include <bits/stdc++.h>
using namespace std;
long long t, a, b, c, d;
long long ch(long long x) { return a * (x + 1) - x * d * b * (1 + x) / 2; }
signed main() {
  cin >> t;
  while (t--) {
    cin >> a >> b >> c >> d;
    if (a > b * c) {
      puts("-1");
      continue;
    }
    long long l = 0, r = c / d;
    while (r - l > 2) {
      long long mid1 = (r + 2 * l) / 3;
      long long mid2 = (2 * r + l) / 3;
      if (ch(mid1) > ch(mid2))
        r = mid2;
      else
        l = mid1;
    }
    long long ans = 0;
    for (long long i = l; i <= r; i++) ans = max(ans, ch(i));
    printf("%lld\n", ans);
  }
}
