#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long aa, bb, cc, dd;
  cin >> aa >> bb >> cc >> dd;
  long long a = aa, b = bb, c = cc, d = dd;
  if (-a + b * c < 0) {
    cout << -1 << endl;
    return;
  }
  long long k;
  if (a % b == 0) {
    k = a / b;
  } else {
    if (a < b) {
      k = 0;
    } else {
      k = a / b;
    }
  }
  long long t = (k / d) * d;
  long long ca = (t / d + 1) * a;
  long long cb = (t / d + 1) * t * b - b * t * (t / d + 1) / 2;
  cout << (long long)(ca - cb) << endl;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    solve();
  }
}
