q = int(input())
for _ in range(q):
    m, x = map(int,input().split())
    q, r = divmod(x,m)
    if r==0:
        print(m)
    else:
        print(r)