#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 6;
int main() {
  int T;
  cin >> T;
  while (T--) {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    if (a > (long long)b * c) {
      puts("-1");
      continue;
    }
    if (c < d) {
      printf("%d\n", a);
      continue;
    }
    int t = a / ((long long)b * d);
    printf("%lld\n",
           (long long)(t + 1) * a - (long long)(t + 1) * t / 2 * b * d);
  }
  return 0;
}
