#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    long long ans = 0;
    if (a > b && c <= d) {
      cout << -1 << '\n';
    } else if (b >= a) {
      cout << b << '\n';
    } else {
      a -= b;
      if (a % (c - d) == 0)
        ans = b + c * (a / (c - d));
      else
        ans = b + c * (a / (c - d) + 1);
      cout << ans << '\n';
    }
  }
  return 0;
}
