#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
bool Debug = true;
ll maxn(vector<ll>& h) {
  ll ans = -1e18;
  for (int ijkl = 0; ijkl < h.size(); ++ijkl) {
    ans = max(ans, (ll)h[ijkl]);
  }
  return ans;
}
ll minn(vector<ll>& h) {
  ll ans = 1e18;
  for (int ijkl = 0; ijkl < h.size(); ++ijkl) {
    ans = min(ans, (ll)h[ijkl]);
  }
  return ans;
}
ll sumn(vector<ll>& h) {
  ll ans = 0;
  for (int ijkl = 0; ijkl < h.size(); ++ijkl) {
    ans += h[ijkl];
  }
  return ans;
}
ll pown(ll n, ll cnt) {
  if (cnt == 0) {
    return 1;
  }
  if (cnt == 1) {
    return n;
  }
  if (cnt % 2 == 0) {
    ll a = pown(n, cnt / 2);
    return (a * a) % ll(998244353);
  } else {
    ll a = pown(n, (cnt - 1) / 2);
    return (a * a) % ll(998244353) * n % ll(998244353);
  }
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
struct Point {
  int x, y;
  Point() : x(0), y(0) {}
  Point(int _x, int _y) : x(_x), y(_y) {}
  Point(Point a, Point b) : x(b.x - a.x), y(b.y - a.y) {}
};
string alph = "abcdefghijklmnopqrstuvwxyz";
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll tq;
  cin >> tq;
  while (tq--) {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    if (c * b < a) {
      cout << "-1\n";
    } else {
      ll t = a / b - !(a % b) + 1;
      ll cnt = (t - 1) / d + 1;
      ll dam = cnt * a;
      if (t == 1) {
        cout << a << "\n";
      } else {
        ll nas = ((cnt - 1) * d) * b * cnt / 2;
        ll ans = dam - nas;
        cout << ans << "\n";
      }
    }
  }
  return 0;
}
