#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long inff = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
const double eps = 1e-9;
mt19937 rnd(228);
void run() {
  int a, b, c, d;
  scanf("%d%d%d%d", &(a), &(b), &(c), &(d));
  if (a > 1LL * b * c) return (void)(printf("-1\n"));
  int t = (a / b + (a % b > 0)) - 1, k = t / d;
  long long ans = 1LL * (k + 1) * a - 1LL * k * (k + 1) / 2 * b * d;
  printf("%lld\n", ans);
}
int main() {
  int T;
  scanf("%d", &(T));
  while (T--) run();
  return 0;
}
