#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
long long a, b, c, d;
long long check(long long no_a) {
  long long val = no_a * a;
  long long tim = (no_a - 1) * d;
  no_a--;
  long long val1 = d * ((no_a * (no_a + 1)) / 2);
  if (val1 >= 2000000000000) {
    return 0;
  }
  if (tim >= c) {
    return 0;
  }
  return max(0ll, val - val1 * b);
}
void solve() {
  cin >> a >> b >> c >> d;
  if (a > b * c) {
    cout << "-1\n";
    return;
  }
  if (d >= c) {
    cout << a << '\n';
    return;
  }
  long long ans = a;
  long long st = 1, en = 2000000;
  while (st <= en) {
    long long mid1 = (st + en) / 2;
    long long mid2 = mid1 + 1;
    long long ans1 = check(mid1), ans2 = check(mid2);
    if (ans1 >= ans2) {
      ans = max(ans, ans1);
      en = mid1 - 1;
    } else {
      ans = max(ans, ans2);
      st = mid2 + 1;
    }
  }
  cout << ans << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
