#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
const int MOD = 1e9 + 7;
const long double PI = 3.1415926535898;
const long long INF = LLONG_MAX;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  cin >> t;
  while (t--) {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    if (b * c < a) {
      cout << -1 << "\n";
      continue;
    }
    if (d > c) {
      cout << a << "\n";
      continue;
    }
    long long num = (2 * a / (b * d) - 1) / 2;
    long long ans = (num + 1) * a - num * (num + 1) / 2 * d * b;
    num++;
    ans = max(ans, (num + 1) * a - num * (num + 1) / 2 * d * b);
    cout << ans << "\n";
  }
}
