#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b,c,d;
int t;
int main()
{
scanf("%d",&t);
while(t--)
{
cin>>a>>b>>c>>d;
if(b>=a) cout<<b<<endl;
else if(c<=d) cout<<-1<<endl;
else
{
a-=b;
cout<<b+(int)ceil(1.0*a/(c-d)*1.0)*c<<endl;
}
}
}