#include <bits/stdc++.h>
using namespace std;
int t;
long long a, b, c, d, ans, sum;
long long calc(long long i) {
  sum = 0;
  long long tim = (i - 1) * d + 1;
  sum = a * i;
  sum -= b * c * i;
  sum += b * i * (1 + c - tim) + b * d * (i - 1) * i / 2;
  return sum;
}
void solve() {
  scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
  if (b * c < a) {
    printf("-1\n");
    return;
  }
  long long answ = (a - 1) / (b * d) + 1;
  printf("%lld\n", calc(answ));
}
int main() {
  scanf("%d", &t);
  while (t--) solve();
  return 0;
}
