#include <bits/stdc++.h>
using namespace std;
long long t, a, b, c, d;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> t;
  while (t--) {
    cin >> a >> b >> c >> d;
    long long l = 0, r = (c + d - 1) / d;
    while (l < r) {
      long long mid = l + r + 1 >> 1;
      long long sum1 = (mid + 1) * mid / 2 * d * b - (mid + 1) * a;
      if (mid == (c + d - 1) / d) sum1 -= (mid * d - c) * b;
      long long sum2 = (mid - 1) * mid / 2 * d * b - mid * a;
      if (sum1 >= sum2)
        r = mid - 1;
      else
        l = mid;
    }
    if (l == (c + d - 1) / d)
      cout << "-1\n";
    else {
      long long sum = (l + 1) * l / 2 * d * b - (l + 1) * a;
      cout << -sum << '\n';
    }
  }
}
