#include <bits/stdc++.h>
long long MAX = LLONG_MAX;
long long MIN = LLONG_MIN;
using namespace std;
bool sortcol(const vector<long long>& v1, const vector<long long>& v2) {
  return (v1[0] < v2[0]);
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  if (b == 0) return a;
  if (a == b) return a;
  if (a > b) return gcd(a - b, b);
  return gcd(a, b - a);
}
long long lcm(long long a, long long b) { return ((a * b) / gcd(a, b)); }
long long powfun(long long a, long long b) {
  long long res = 1;
  for (long long i = 1; i <= b; i++) {
    res = res * a;
  }
  return res;
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    if (b >= a) {
      cout << b << "\n";
      continue;
    } else if (d >= c) {
      cout << "-1\n";
      continue;
    } else {
      long long sleeptime = b;
      long long printtime = b;
      long long temp = c - d;
      long long temp2 = (a - b) / temp;
      if ((a - b) % temp != 0) temp2++;
      printtime += (temp2 * (c));
      cout << printtime << "\n";
    }
  }
  return 0;
}
