#include <bits/stdc++.h>
using namespace std;
int T;
int a, b, c, d;
void solve() {
  scanf("%d%d%d%d", &a, &b, &c, &d);
  if (1ll * a > 1ll * b * c) {
    puts("-1");
    return;
  }
  int tme = c / d;
  int l = 0, r = tme;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (1ll * mid * d * b <= 1ll * a)
      l = mid + 1;
    else
      r = mid - 1;
  }
  l--;
  long long ans = 1ll * a * (l + 1);
  ans -= 1ll * (l + 1) * l / 2 * d * b;
  printf("%lld\n", ans);
}
int main() {
  scanf("%d", &T);
  while (T--) solve();
  return 0;
}
