#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int $k = 1;
  cin >> $k;
  while ($k--) {
    ll a, b, c, d, an = 0;
    cin >> a >> b >> c >> d;
    if (c <= d && b < a)
      cout << -1 << endl;
    else if (a <= b)
      cout << b << endl;
    else {
      an += b;
      a -= b;
      an += ((a + c - d - 1) / (c - d)) * c;
      cout << an << endl;
    }
  }
}
