#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(NULL);
  int t{0};
  long long a{0}, b{0}, c{0}, d{0}, cycles{0}, totalTime{0};
  cin >> t;
  while (t--) {
    cin >> a >> b >> c >> d;
    if (a <= b) {
      totalTime = b;
    } else if (d >= c) {
      totalTime = -1;
    } else {
      cycles = ceil(((long double)a - b) / (c - d));
      totalTime = b + cycles * c;
    }
    cout << totalTime << "\n";
  }
  return 0;
}
