#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    long long a, b, c, d;
    scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
    if (a > b * c) {
      puts("-1");
      continue;
    }
    int l = 0, r = c / d + 1;
    while (l < r) {
      int m = l + r >> 1;
      if (m * d * b < a)
        l = m + 1;
      else
        r = m;
    }
    long long ans = l * a;
    ans -= 1ll * l * (l - 1) / 2 * d * b;
    printf("%lld\n", ans);
  }
}
