#include <bits/stdc++.h>
using namespace std;
char ss[1 << 24], *A = ss, *B = ss;
inline char gc() {
  return A == B && (B = (A = ss) + fread(ss, 1, 1 << 24, stdin), A == B) ? EOF
                                                                         : *A++;
}
template <class T>
void read(T &x) {
  register long long f = 1, c;
  while (c = gc(), c < 48 || c > 57)
    if (c == '-') f = -1;
  x = (c ^ 48);
  while (c = gc(), c > 47 && c < 58) x = (x << 3) + (x << 1) + (c ^ 48);
  x *= f;
}
char sr[1 << 24], z[20];
long long Z, C1 = -1;
template <class T>
void wer(T x) {
  if (x < 0) sr[++C1] = '-', x = -x;
  while (z[++Z] = x % 10 + 48, x /= 10)
    ;
  while (sr[++C1] = z[Z], --Z)
    ;
}
inline void wer1() { sr[++C1] = ' '; }
inline void wer2() { sr[++C1] = '\n'; }
long long a, b, c, d;
long long js(long long x) {
  long long f = 1ll * x * a;
  long long k2 = x - 1.00 * c / d;
  k2 = max(k2, 0ll);
  f -= k2 * b * c;
  k2++;
  f -= ((x - k2 + 1) * x * d - (x - k2 + 1) * (x + k2) * d / 2) * b;
  return f;
}
int main() {
  long long T;
  cin >> T;
  while (T--) {
    cin >> a >> b >> c >> d;
    if (a > b * c) {
      cout << -1 << endl;
    } else {
      long long t = a / b;
      long long t2 = t / d;
      long long ans = 0;
      for (long long i = max(t2 - 10, 1ll); i <= t2 + 10; i++)
        ans = max(ans, js(i));
      cout << ans << endl;
    }
  }
  return 0;
}
