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