#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    if (a > 1ll * b * c) {
      puts("-1");
      continue;
    }
    printf("%lld\n", 1ll * (2 * a - 1ll * a / (1ll * b * d) * (1ll * b * d)) *
                         (a / (1ll * b * d) + 1) / 2);
  }
}
