#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int a, b, c, d, ans;
  cin >> a >> b >> c >> d;
  if (a - b * c > 0)
    ans = -1;
  else {
    long long int low = (2 * a + b * d) / (2 * b * d), up = min(low + 1, c);
    ans = max(low * a - low * (low - 1) * b * d / 2,
              up * a - up * (up - 1) * b * d / 2);
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
