#include <bits/stdc++.h>
using namespace std;
inline long long mod(long long n, long long m) {
  long long ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}
long long gcd(long long a, long long b) {
  return (b == 0LL ? a : gcd(b, a % b));
}
long long exp(long long a, long long b, long long m) {
  if (b == 0LL) return 1LL;
  if (b == 1LL) return mod(a, m);
  long long k = mod(exp(a, b / 2, m), m);
  if (b & 1LL) {
    return mod(a * mod(k * k, m), m);
  } else
    return mod(k * k, m);
}
long long a, b, c, d;
long long pa(long long a1, long long an, long long n) {
  return n * (a1 + an) / 2;
}
long long f(long long K) {
  long long totA = (K + 1) * a;
  long long K1;
  if (K * d < c) {
    K1 = 0;
  } else {
    K1 = 1 + (K * d - c) / d;
    while ((K1)*d + c <= K * d) K1++;
    while ((K1 - 1) * d + c > K * d) K1--;
  }
  long long val1 = K1 * c * b;
  long long cnt = (K - K1);
  long long val2 = 0;
  if (cnt > 0) {
    long long T = K * d;
    val2 = b * (T * cnt - d * pa(K1, (K - 1), cnt));
  }
  long long totB = val1 + val2;
  return totA - totB;
}
void solve() {
  cin >> a >> b >> c >> d;
  if (a > b * c) {
    cout << -1 << "\n";
    return;
  }
  if (d >= c) {
    if (a > b * c)
      cout << -1 << "\n";
    else
      cout << a << "\n";
    return;
  } else {
    long long mult = c * d;
    if (a * d > b * mult) {
      cout << -1 << "\n";
      return;
    }
    long long ans = a;
    long long L = 0, R = c;
    while (R - L > 10) {
      long long m1 = L + (R - L) / 3;
      long long m2 = L + 2 * (R - L) / 3;
      long long fm1 = f(m1), fm2 = f(m2);
      ans = max({ans, fm1, fm2});
      if (fm1 < fm2) {
        L = m1;
      } else
        R = m2;
    }
    for (long long i = L; i <= R; i++) {
      ans = max(ans, f(i));
    }
    cout << ans << "\n";
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
}
