#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  long long arr[t];
  for (int i = 0; i < t; i++) {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a <= b) {
      arr[i] = b;
    } else {
      a = a - b;
      if (c <= d) {
        arr[i] = -1;
      } else {
        d = c - d;
        a % d == 0 ? arr[i] = (b + (c * (a / d)))
                   : arr[i] = (b + (c * (a / d + 1)));
      }
    }
  }
  for (int i = 0; i < t; i++) cout << arr[i] << endl;
}
