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