#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  for (__int128 q = 0; q < t; q++) {
    long long dmg, heal, k, d;
    cin >> dmg >> heal >> k >> d;
    if ((__int128)heal * k < (__int128)dmg) {
      cout << -1 << '\n';
      continue;
    }
    __int128 c = dmg / (__int128)(heal * d);
    __int128 ans;
    if (dmg % (heal * d) == 0) {
      ans = (__int128)dmg * c - heal * d * (__int128)(c * (c - 1) / 2);
    } else {
      c++;
      ans = (__int128)dmg * c - heal * d * (__int128)(c * (c - 1) / 2);
    }
    cout << (long long)ans << "\n";
  }
  return 0;
}
