#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a > b * c)
    cout << -1 << '\n';
  else {
    long long g = ((a - (d * b) / 2)) / (d * b);
    long long l = min(g + 1, c);
    g = min(g, c);
    long long ans = 0;
    ans = a * (l + 1) - (l + 1) * l / 2 * d * b;
    ans = max(a * (g + 1) - (g + 1) * g / 2 * d * b, ans);
    cout << ans << '\n';
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long test = 1;
  cin >> test;
  while (test--) {
    solve();
  }
}
