#include <bits/stdc++.h>
using namespace std;
long long inline read() {
  long long num = 0, neg = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') neg = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    num = (num << 3) + (num << 1) + c - '0';
    c = getchar();
  }
  return num * neg;
}
const long long maxn = 100010, mod = 998244353;
long long T, a, b, c, d;
long long S(long long x) { return x * (x + 1) / 2; }
long long S1(long long n) {
  long long now = (n + 1) * a, s = min(n, c / d);
  return now - (n - s) * b * c - S(s) * d * b;
}
signed main() {
  T = read();
  while (T--) {
    a = read();
    b = read();
    c = read();
    d = read();
    if (a > b * c) {
      cout << -1 << endl;
      continue;
    }
    long long l = 1, r = 1e12, ans = 0;
    while (l <= r) {
      long long mid = l + r >> 1;
      if (S1(mid) > S1(mid - 1))
        l = mid + 1, ans = mid;
      else
        r = mid - 1;
    }
    cout << S1(ans) << endl;
  }
  return 0;
}
