def solve():
input_string = input()
list = input_string.split()
s = list[0]
n = int(list[1])
MOD = 0
for ch in s:
MOD *= 10
MOD += ord(ch) - ord('0')
MOD %= n
if MOD:
MOD = n - MOD
print(int(s)+MOD)
tc = int(input())
while tc:
tc -= 1
solve()