#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int a, b, c, d;
    cin >> a >> b >> c >> d;
    a = a - b;
    if (a <= 0) {
      cout << b << endl;
      goto end;
    } else {
      long long int diff = c - d;
      if (diff <= 0) {
        cout << "-1" << endl;
        goto end;
      } else {
        long long int ans = 0;
        if (a % diff == 0)
          ans += (c * (a / diff));
        else
          ans += (c * ((a / diff) + 1));
        ans += b;
        cout << ans << endl;
      }
    }
  end:;
  }
}
