#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, j, k, m, t, a, b, c, d, sum, max, count;
  cin >> t;
  while (t > 0) {
    cin >> a >> b >> c >> d;
    if (a > b && d >= c) {
      cout << "-1" << endl;
    } else {
      if (a <= b) {
        cout << b << endl;
      } else {
        sum = b;
        if (d >= c) {
          cout << "-1" << endl;
        } else {
          a = a - b;
          k = a / (c - d);
          if (a % (c - d) != 0) {
            k = k + 1;
          }
          sum = (k * c) + sum;
          cout << sum << endl;
        }
      }
    }
    t--;
  }
  return 0;
}
