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