#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  int a, b, c, d;
  while (t--) {
    cin >> a >> b >> c >> d;
    if (a <= b) {
      cout << b << endl;
    } else if (c <= d) {
      cout << -1 << endl;
    } else {
      int x = (a - b);
      int y = (c - d);
      long long q = x / y + (x % y != 0);
      cout << (long long)(b + (q * c)) << endl;
    }
  }
  return 0;
}
