#include <bits/stdc++.h>
using namespace std;
double getTime() { return clock() / (double)CLOCKS_PER_SEC; };
const long long mod = 1e9 + 7;
const long long INF = 3e18;
const long long N = 1000 + 5;
const long long P0 = 437;
const long long P1 = 343;
const long long d = 400;
const double PI = acos(-1);
void solve() {
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  if (b * c < a) {
    cout << "-1\n";
    return;
  }
  if (c <= d) {
    cout << a << '\n';
    return;
  }
  long long an = a;
  long long d1 = a - d * b, del = d * b, cnt = c / d + (c % d != 0);
  long long lastdel = b * (c % d);
  if (c % d == 0) lastdel = b * d;
  long long l = 0, r = cnt + 1;
  while (r - l > 1) {
    long long m = (l + r) / 2;
    long long m1 = min(cnt - 1, m);
    long long last = d1 - del * (m - 1);
    if (m == cnt) last -= lastdel;
    if (last <= 0)
      r = m;
    else
      l = m;
  }
  if (l) {
    an += (2 * d1 + (l - 1) * (-del)) * l / 2;
  }
  cout << an << '\n';
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long qq = 1;
  cin >> qq;
  while (qq--) solve();
}
