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