#include <bits/stdc++.h>
using namespace std;
template <typename T>
void rd(T& x) {
  long long f = 0, c;
  while (!isdigit(c = getchar())) f ^= !(c ^ 45);
  x = (c & 15);
  while (isdigit(c = getchar())) x = x * 10 + (c & 15);
  if (f) x = -x;
}
template <typename T>
void pt(T x, long long c = -1) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) pt(x / 10);
  putchar(x % 10 + 48);
  if (c != -1) putchar(c);
}
long long T;
signed main() {
  rd(T);
  while (T--) {
    long long a, b, c, d;
    rd(a), rd(b), rd(c), rd(d);
    if (b * c < a) {
      puts("-1");
    } else {
      long long ans = a;
      long long num = a / b / d;
      ans = max(ans, (num + 1) * a - num * (num + 1) / 2 * b * d);
      pt(ans, '\n');
    }
  }
  return 0;
}
