#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T& a) {
  register T x = 0, flag = 1;
  register char ch;
  while (!isdigit(ch = getchar()))
    if (ch == '-') flag = -1;
  while (x = x * 10 + (ch & 15), isdigit(ch = getchar()))
    ;
  a = x * flag;
}
template <class T>
inline void write(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
template <class T>
inline bool Chkmax(T& x, const T& y) {
  return x < y ? x = y, true : false;
}
template <class T>
inline bool Chkmin(T& x, const T& y) {
  return x > y ? x = y, true : false;
}
long long n, a, b, c, d;
signed main() {
  read(n);
  while (n--) {
    read(a);
    read(b);
    read(c);
    read(d);
    if (a <= b) {
      cout << b << endl;
      continue;
    }
    a -= b;
    if (d >= c) {
      cout << -1 << endl;
      continue;
    }
    long long tim = c - d;
    long long pop = a / tim;
    if (a % tim) pop++;
    cout << b + pop * c << endl;
  }
}
