#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    long long total = 0;
    total += b;
    a -= b;
    if (a <= 0) {
      cout << b << "\n";
      continue;
    }
    if (c <= d) {
      cout << -1 << "\n";
      continue;
    }
    long long ci = (a + c - d - 1) / (c - d);
    total += ci * (c);
    cout << total << "\n";
  }
  return 0;
}
