#include <bits/stdc++.h>
using namespace std;
void LINE(vector<int> &vec) {
  int N = vec.size();
  for (int i = 0; i < N; i++) {
    if (i == N - 1) {
      cout << vec[i] << endl;
    } else {
      cout << vec[i] << " ";
    }
  }
}
int64_t A, B, C, D;
int64_t calc(__int128 K) {
  if (K == 0) {
    return A;
  }
  __int128 S = C - D;
  __int128 ret = A * K - B * C * (K - 1);
  ret += B * (K - 1) * (2 * S + (K - 2) * (-D)) / 2;
  if (ret < 0) {
    return -1;
  }
  int64_t R = ret;
  return max(R, (int64_t)-1);
}
void solve() {
  cin >> A >> B >> C >> D;
  if (A > B * C) {
    cout << -1 << endl;
    return;
  }
  int64_t L = 0;
  int64_t R = 1e6;
  while (R - L > 2) {
    int64_t c1 = (L * 2 + R) / 3;
    int64_t c2 = (L + R * 2) / 3;
    if (calc(c1) >= calc(c2)) {
      R = c2;
    } else {
      L = c1;
    }
  }
  int64_t ans = A;
  for (int i = -10; i <= 10; i++) {
    if (L + i < 0) {
      continue;
    }
    ans = max(ans, calc(L + i));
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  cin >> T;
  for (int i = 0; i < T; i++) {
    solve();
  }
}
