from math import ceil
t = int(input())
for _ in range(t):
    a, b, c, d = map(int, input().split())
    if b >= a:
        print(b)
    elif c <= d:
        print(-1)
    else:
        diff = a - b
        print(ceil(diff / (c - d)) * c + b)

5d216873c65b66417aa69609ee59b35e4f201577
<mask token>

<mask token>
for _ in range(t):
    a, b, c, d = map(int, input().split())
    if b >= a:
        print(b)
    elif c <= d:
        print(-1)
    else:
        diff = a - b
        print(ceil(diff / (c - d)) * c + b)

<mask token>
t = int(input())
for _ in range(t):
    a, b, c, d = map(int, input().split())
    if b >= a:
        print(b)
    elif c <= d:
        print(-1)
    else:
        diff = a - b
        print(ceil(diff / (c - d)) * c + b)

from math import ceil
t = int(input())
for _ in range(t):
    a, b, c, d = map(int, input().split())
    if b >= a:
        print(b)
    elif c <= d:
        print(-1)
    else:
        diff = a - b
        print(ceil(diff / (c - d)) * c + b)
