#include <bits/stdc++.h>
using namespace std;
int main() {
  int k;
  cin >> k;
  while (k--) {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    long long t = 0;
    if (a > b && c <= d) {
      cout << "-1\n";
    } else if (a <= b) {
      cout << b << "\n";
    } else {
      t += b;
      a -= b;
      t += c * 1ll * (a / (c - d) + (a % (c - d) != 0));
      cout << t << "\n";
    }
  }
  return 0;
}
