#include <bits/stdc++.h>
using namespace std;
const int next_x[8] = {0, 1, -1, 0, 1, 1, -1, -1};
const int next_y[8] = {1, 0, 0, -1, 1, -1, -1, 1};
const int inf = 1e9 + 5;
const long long linf = 1e18 + 5;
const double PI = acos(-1.0);
const int MAXN = 1e6 + 5;
const int N = 4e6 + 5;
const long double eps = 1e-8;
const long double fix = 1e-2;
int h[MAXN];
int test(int a, int b, int c, int d) {
  memset(h, 0, sizeof(h));
  long long cur = 0;
  for (int i = (0), I = (50) + 1; i < I; ++i) {
    cur += h[i];
    if (i % d == 0) {
      cur -= a;
      for (int j = (i + 1), I = (i + c) + 1; j < I; ++j) h[j] += b;
    }
    if (i % d == 0) printf("%lld ", cur);
  }
  cout << endl;
}
long long a, b, c, d;
long long sum(long long l, long long r) { return (l + r) * (r - l + 1) / 2; }
long long calc(long long tim) {
  long long res = 0, cur = (tim - 1) * d;
  res -= a * tim;
  if (c < d) return res + (tim - 1) * c * b;
  if (tim == 1) return -a;
  long long l = 1, r = tim - 1, ans = r;
  while (l <= r) {
    long long s = (((l + r) / 2) - 1) * d;
    if (s + c >= cur)
      ans = ((l + r) / 2), r = ((l + r) / 2) - 1;
    else
      l = ((l + r) / 2) + 1;
  }
  res += (tim - 1) * c * b;
  long long L = ans, R = tim - 1, len = (R - L + 1);
  res -= b * (sum(L - 1, R - 1) * d + len * c - len * cur);
  return res;
}
bool check(long long x) { return calc(x + 1) - calc(x) < 0; }
int work() {
  int _CASE;
  scanf("%d", &_CASE);
  for (int case_num = (1), I = (_CASE) + 1; case_num < I; ++case_num) {
    scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
    if ((b * c) < a) {
      puts("-1");
      continue;
    }
    long long l = 1, r = 1e6, ans = l;
    while (l <= r) {
      if (check(((l + r) / 2)))
        ans = ((l + r) / 2), l = ((l + r) / 2) + 1;
      else
        r = ((l + r) / 2) - 1;
    }
    ++ans, printf("%lld\n", -min(calc(1), calc(ans)));
  }
  return 0;
}
int main() {
  work();
  return 0;
}
