#include <bits/stdc++.h>
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
void solve() {
  long long initial, heal, cnt, resp;
  std::cin >> initial >> heal >> cnt >> resp;
  const auto& f = [&](long long first) {
    long long damage = initial * first;
    long long total_heal = 0;
    if (resp > cnt) {
      total_heal = cnt * heal * (first - 1);
    } else {
      long long need_saturate = cnt / resp;
      long long in_satur = need_saturate * resp * heal;
      in_satur += (cnt % resp) * heal;
      if (first > need_saturate) {
        long long in_begin =
            (need_saturate + 1) * (need_saturate) / 2 * resp * heal;
        total_heal = in_begin + in_satur * (first - need_saturate - 1);
      } else {
        total_heal = first * (first - 1) / 2 * resp * heal;
      }
    }
    return damage - total_heal;
  };
  long long l = 1, r = 1e6 + 10;
  while (r - l > 5) {
    long long m = (l + r) / 2;
    if (f(m) < f(m + 1)) {
      l = m;
    } else {
      r = m;
    }
  }
  if (l > 1e6) {
    std::cout << "-1" << std::endl;
  } else {
    long long ans = l;
    for (long long x = l; x <= r; x++) {
      if (f(ans) < f(x)) ans = x;
    }
    std::cout << f(ans) << std::endl;
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  int t;
  std::cin >> t;
  while (t--) solve();
  return 0;
}
