for i in range(int(input())):
    n, p = map(int, input().split())
if n >= p:
    print(0 % p)
elif n == p - 1:
    print(p - 1)
else:
    n0 = n + 1
n1 = n0 + 1
while n1 <= p - 1:
    pass
Boring Factorials in python