t = int(input())
for _ in range(0, t):
    m, x = map(int, input().split())
    # 对m取余,0……m-1,以下操作可以满足
    x -= 1
    x %= m
    x += 1
    print(x)