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