#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
void solve() {
  long long int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a > c * b) {
    cout << -1 << '\n';
    return;
  }
  if (c <= d) {
    cout << a << '\n';
    return;
  }
  long long int t = (a) / (d * b);
  long long int ans = (t + 1) * a - ((t * (t + 1) / 2) * d * b);
  cout << max(a, ans) << '\n';
}
void init() {}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  init();
  long long int T;
  cin >> T;
  for (long long int TT = 1; TT <= T; TT++) {
    solve();
  }
  cerr << "Time : "
       << 1000 * ((long double)clock()) / (long double)CLOCKS_PER_SEC << "ms\n";
  return 0;
}
