#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
const int MX = 2e5 + 5;
const long long inf = 1e18;
const long double PI = acos((long double)-1);
const int xd[4] = {1, 0, -1, 0}, yd[4] = {0, 1, 0, -1};
template <class T>
void remDup(vector<T>& v) {
  sort(begin(v), end(v));
  v.erase(unique(begin(v), end(v)), end(v));
}
template <class A>
void re(complex<A>& c);
template <class A, class B>
void re(pair<A, B>& p);
template <class A>
void re(vector<A>& v);
template <class A, size_t SZ>
void re(array<A, SZ>& a);
template <class T>
void re(T& x) {
  cin >> x;
}
void re(double& d) {
  string t;
  re(t);
  d = stod(t);
}
void re(long double& d) {
  string t;
  re(t);
  d = stold(t);
}
template <class H, class... T>
void re(H& h, T&... t) {
  re(h);
  re(t...);
}
template <class A>
void re(complex<A>& c) {
  A a, b;
  re(a, b);
  c = {a, b};
}
template <class A, class B>
void re(pair<A, B>& p) {
  re(p.f, p.s);
}
template <class A>
void re(vector<A>& x) {
  for (auto& a : x) re(a);
}
template <class A, size_t SZ>
void re(array<A, SZ>& x) {
  for (auto& a : x) re(a);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    if (c > d) {
      long long x = c * b;
      if (x >= a) {
        long long p = b * d;
        long long q = a / p;
        long long r = c / d;
        if (q <= r) {
          long long n1 = ((q + 1) * q) / 2ll;
          long long n2 = a * q;
          long long n3 = p * n1;
          cout << (n2 - n3 + a) << endl;
        } else {
          long long n1 = ((r + 1) * r) / 2ll;
          long long n2 = a * r;
          long long n3 = p * n1;
          cout << (n2 - n3 + a) << endl;
        }
      } else if (x < a) {
        cout << "-1" << endl;
      }
    }
    if (c <= d) {
      if (a > (b * c)) {
        cout << "-1" << endl;
        ;
      } else {
        cout << a << endl;
      }
    }
  }
  return 0;
}
