#include <bits/stdc++.h>
using namespace std;
inline long long rint() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
inline long long gcd(long long a, long long b) {
  return (b) ? gcd(b, a % b) : a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long pow(long long a, long long b, long long q) {
  long long rtn = 1;
  while (b) {
    if (b & 1) rtn = rtn * a % q;
    a = a * a % q;
    b >>= 1;
  }
  return rtn;
}
inline long long mysqrt(long long n) {
  long long x = sqrt(n);
  while (x * x < n) x++;
  while (x * x > n) x--;
  return x;
}
void solve() {
  long long a = rint(), b = rint(), c = rint(), d = rint();
  if (a > b * c) {
    cout << -1 << "\n";
    return;
  }
  if (d >= c) {
    cout << a << "\n";
    return;
  }
  long long l = 1, r = c / d + 1, res = 1;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (a > b * d * (mid - 1))
      res = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  cout << a * res - res * (res - 1) / 2 * b * d << "\n";
}
int main() {
  int t = rint();
  while (t--) solve();
  return 0;
}
