#include <bits/stdc++.h>
using namespace std;
long long T;
long long a, b, c, d, t;
long long cal(long long k) {
  long long ans = 0;
  if (k <= t)
    ans = b * d * k * (k + 1) / 2 - (k + 1) * a;
  else
    ans = b * d * t * (t + 1) / 2 + (k - t) * b * c - (k + 1) * a;
  if (ans > 0) return 0;
  return ans;
}
signed main() {
  scanf("%lld", &T);
  while (T--) {
    scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
    if (a > b * c) {
      puts("-1");
      continue;
    }
    long long l = 0, r = t = c / d, mid1, mid2, minn = 0;
    while (l < r) {
      if (r - l < 3) {
        minn = min(minn, cal(l));
        minn = min(minn, cal(l + 1));
        minn = min(minn, cal(r));
        break;
      }
      mid1 = (l + r) >> 1;
      mid2 = mid1 + 1;
      if (cal(mid1) <= cal(mid2)) r = mid2;
      if (cal(mid1) > cal(mid2)) l = mid1;
    }
    if (l == r) minn = min(minn, cal(l));
    minn = min(minn, cal(t + 1));
    printf("%lld\n", -minn);
  }
  return 0;
}
