#include <bits/stdc++.h>
using namespace std;
long long t, a, b, c, d;
long long ff(long long s) {
  long long ret = -s * a;
  long long p;
  long long times = min(s - 1, (c - 1) / d);
  p = s - 1 - times;
  return ret + p * c * b + times * (d * b + d * b * times) / 2;
}
long long f(long long a, long long b, long long c, long long d) {
  long long l = 1, r = 1e7, m1, m2;
  while (r - l > 50) {
    m1 = (l + l + r) / 3, m2 = (l + r + r) / 3;
    long long f1 = ff(m1), f2 = ff(m2);
    if (f1 < f2)
      r = m2;
    else
      l = m1;
  }
  long long ans = 1e18;
  for (long long i = l; i <= r; i++) ans = min(ans, ff(i));
  return ans;
}
int main() {
  cin >> t;
  while (t--) {
    scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
    if (b * c < a)
      puts("-1");
    else
      printf("%lld\n", -f(a, b, c, d));
  }
}
