#include <bits/stdc++.h>
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout.tie(0);
  int32_t num_tests;
  std::cin >> num_tests;
  for (int32_t t = 0; t < num_tests; t++) {
    int64_t a, hps, c, cool;
    std::cin >> a >> hps >> c >> cool;
    int32_t heals_max = c / cool;
    int64_t cycle_net = -a + (heals_max * (int64_t)(c % cool) +
                              (heals_max - 1) * (int64_t)(cool - (c % cool)) +
                              (int64_t)(cool)) *
                                 hps;
    if (cycle_net < 0) {
      std::cout << -1 << "\n";
      continue;
    }
    int32_t left = -1, right = heals_max;
    while (right - left > 1) {
      int32_t m = (left + right) / 2;
      int32_t active_heals = std::min(m + 1, heals_max);
      int64_t cycle_net2 =
          -a + (active_heals * (int64_t)std::min(c, cool)) * hps;
      if (cycle_net2 < 0)
        left = m;
      else
        right = m;
    }
    if (left == -1)
      std::cout << a << "\n";
    else {
      int32_t best_cycle = left;
      int32_t partial = std::min(best_cycle + 1, heals_max);
      int32_t full = best_cycle + 1 - partial;
      int64_t full_healed = full * c * hps;
      int64_t partial_healed =
          ((int64_t)partial * (partial + 1) / 2) * hps * cool;
      std::cout << a * (best_cycle + 2) - full_healed - partial_healed << "\n";
    }
  }
  return 0;
}
