#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC target("avx")
using namespace std;
int64_t fpow(int64_t x, int64_t y) {
  int64_t temp;
  if (y == 0) return 1;
  temp = fpow(x, y / 2);
  if (y % 2 == 0)
    return temp * temp;
  else
    return x * temp * temp;
}
int64_t gcd(int64_t a, int64_t b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void sieve(int64_t n) {
  bool prime[5 * 200005];
  memset(prime, true, sizeof(prime));
  for (int64_t p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int64_t i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
  prime[1] = 0;
}
int64_t cnt, sum = 0, mid, mx = -1e17, mn = 1e17;
int64_t n, m, d, t, i, j, k, l, r, x, y, z;
bool f, f1, f2;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  for (int64_t tt = 1; tt <= t; ++tt) {
    int64_t a, b, c, d;
    cin >> a >> b >> c >> d;
    if (b >= a) {
      cout << b;
      cout << "\n";
    } else {
      if (d >= c) {
        cout << -1;
        cout << "\n";
      } else {
        cnt = b;
        a -= b;
        cnt += ((int64_t)ceil((double)(a) / (c - d))) * c;
        cout << cnt;
        cout << "\n";
      }
    }
  }
}
