t = int(input())
for _ in range(t):
n, a = map(int, input().split())
l, r, mid, res = 0, n, -1, -1
t = 2 * (n * a - n)
while l <= r:
mid = (l + r) // 2
if t >= mid * mid - mid:
res = mid
l = mid + 1
else:
r = mid - 1
print(res)
dCA9IGludChpbnB1dCgpKQoKZm9yIF8gaW4gcmFuZ2UodCk6CiAgbiwgYSA9IG1hcChpbnQsIGlucHV0KCkuc3BsaXQoKSkKICBsLCByLCBtaWQsIHJlcyA9IDAsICBuLCAtMSwgLTEKICB0ID0gIDIgKiAobiAqIGEgLSBuKQogIHdoaWxlIGwgPD0gcjoKICAgIG1pZCA9IChsICsgcikgLy8gMgogICAgaWYgdCA+PSBtaWQgKiBtaWQgLSBtaWQ6CiAgICAgIHJlcyA9IG1pZAogICAgICBsID0gbWlkICsgMQogICAgZWxzZToKICAgICAgciA9IG1pZCAtIDEKICBwcmludChyZXMp