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