#include <bits/stdc++.h>
using namespace std;
long long int shuruHoJaa(long long int test) {
  while (test--) {
    long long int a, b, c, d;
    cin >> a >> b >> c >> d;
    long long int time = 0;
    if (b >= a) {
      cout << b;
    } else if (c <= d) {
      cout << -1;
    } else {
      time += b;
      long long int tmp =
          ((a - b) % (c - d) == 0 ? (a - b) / (c - d) : (a - b) / (c - d) + 1);
      time += (tmp * (c));
      cout << time;
    }
    cout << '\n';
  }
  return 0;
}
int main(int argc, char const *argv[]) {
  int t;
  cin >> t;
  shuruHoJaa(t);
  return 0;
}
