#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;
  while (t--) {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    if (c < d) {
      if (a - (c * b) > 0) {
        cout << -1 << '\n';
        continue;
      } else {
        cout << a << '\n';
        continue;
      }
    }
    if (a - (c * b) > 0) {
      cout << -1 << '\n';
      continue;
    }
    long long maxx = c / d;
    long long l = -1, r = maxx + 1;
    while (r - l > 1) {
      long long mid = (l + r) / 2;
      long long pr = (-a) + (mid + 1) * d * b;
      if (pr < 0)
        l = mid;
      else
        r = mid;
    }
    l++;
    long long ans = (-a) * (l + 1) + (l + 1) * l / 2 * d * b;
    cout << -ans << '\n';
  }
}
