#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long inf = 1ll << 60, a, b, c, d;
;
bool check(long long mid) {
  if (b * c < a) return 1;
  long long t = (c - 1) / d;
  long long t2 = min(t, a / (b * d));
  return (t2 + 1) * a - t2 * (t2 + 1) / 2 * b * d >= mid;
}
void solve() {
  cin >> a >> b >> c >> d;
  long long l = 0, r = inf;
  while (l < r) {
    long long mid = l + r >> 1;
    if (check(mid))
      l = mid + 1;
    else
      r = mid;
  }
  if (l >= inf)
    cout << -1 << '\n';
  else
    cout << l - 1 << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
}
