#include <bits/stdc++.h>
using namespace std;
long long solve(long long a, long long b, long long c, long long d) {
  if (a - c * b > 0) return -1;
  long long l = a / (b * d), r = (a + b * d - 1) / (b * d) + 1;
  __int128 res = a;
  for (long long i = l, ggdem = r + 1; i < ggdem; ++i) {
    if (0 <= i && i <= c / d) {
      __int128 va = 1;
      va *= i + 1;
      va *= i;
      va *= d;
      va *= b;
      va /= 2;
      res = max(res, (i + 1) * a - va);
    }
  }
  assert(res == (long long)res);
  return res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << solve(a, b, c, d) << "\n";
  }
  return 0;
}
