#include <bits/stdc++.h>
using namespace std;
long long T, a, b, c, d;
inline int read() {
  int ret = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -f;
    ch = getchar();
  }
  while (isdigit(ch)) ret = (ret << 1) + (ret << 3) + ch - '0', ch = getchar();
  return ret * f;
}
int main() {
  T = read();
  while (T--) {
    a = read(), b = read(), c = read(), d = read();
    if (b * c < a) {
      puts("-1");
      continue;
    }
    if (c <= d) {
      cout << a << '\n';
      continue;
    }
    long long t = min(c / d, a / (b * d));
    cout << max(a, a + t * a - b * d * (t + 1) * t / 2) << '\n';
  }
  return 0;
}
