#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d;
long long cal(long long ci) {
  long long ans = ci * a;
  long long t = (ci - 1) * d + 1;
  long long mxl = t;
  long long mil = 1;
  ans -= b * (mxl + mil) * ci / 2 - b * ci;
  return ans;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
    if (a > b * c) {
      puts("-1");
      continue;
    }
    if (a <= b) {
      printf("%lld\n", a);
      continue;
    }
    int maxci = (c - 1) / d + 1;
    int l = 1, r = maxci + 1;
    long long ans = 0;
    while (l < r) {
      int mid = (l + r) / 2;
      int mmid = (mid + r) / 2;
      long long x = cal(mid);
      long long y = cal(mmid);
      if (x >= y) {
        r = mmid;
        ans = max(x, ans);
      } else {
        l = mid;
        ans = max(y, ans);
      }
    }
    printf("%lld\n", ans);
  }
}
