#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d;
long long check(long long t) {
  if (t < 0) return 99999999;
  if (t == 0) return -a;
  long long aa = t / d;
  long long A = (aa + 1) * a;
  long long cha = min(c / d, aa);
  long long sheng = aa - cha;
  return ((d + cha * d) * cha / 2 + sheng * c) * b - A;
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    cin >> a >> b >> c >> d;
    long long l = 0, r = 5 * c;
    while (r - l > 1) {
      long long mid1 = l + (r - l) / 3, mid2 = l + (r - l) / 3 * 2;
      long long ans1 = check(mid1 * d), ans2 = check(mid2 * d);
      if (ans1 == ans2) r = mid2;
      if (ans1 > ans2) {
        l = mid1 + 1;
      } else
        r = mid2;
    }
    if (r > c) {
      cout << -1 << endl;
    } else
      cout << -min(check(r * d), min(check((l + 1) * d), check(l * d))) << endl;
  }
  return 0;
}
