#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  return x * f;
}
const int MAXN = 150010;
const int INF = 2147483600;
int N;
long long A, B, C, D;
inline long long Query(long long t) {
  if (t * D > C || t < 0) return INF;
  return (t * (t + 1) / 2 * D) * B - (t + 1) * A;
}
inline long long Qt(long long l, long long r) {
  long long fans = INF, pos = 0;
  r /= D;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (Query(mid + 1) - Query(mid) < 0)
      l = mid + 1;
    else
      pos = mid, r = mid - 1;
  }
  return min(Query(pos - 1), min(Query(pos), Query(pos + 1)));
}
int main() {
  int T = read();
  while (T--) {
    A = read(), B = read(), C = read(), D = read();
    if (A > C * B) {
      puts("-1");
      continue;
    }
    if (D >= C) {
      printf("%lld\n", A);
    } else {
      long long l = 0, r = C - 1;
      long long ans = Qt(0, C);
      printf("%lld\n", max(-ans, 0LL));
    }
  }
  return 0;
}
