# Python solution to "Seating" from 2025 CS@UCF Summer camp

test_count = int(input())

for _ in range(test_count):
    seats,riders = map(int,input().split())
    if((riders % seats) == 0):
        print(0)
    else:
        print(seats - (riders % seats))
