You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$.

You have to answer $t$ independent test cases.


-----Input-----

The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) — the number of test cases. Then $t$ test cases follow.

The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$).


-----Output-----

For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$.


-----Example-----
Input
5
2 1
1 1
500 4
217871987498122 10
100000000000000001 1

Output
8
0
500
2128012501878
899999999999999999

Difficulty: MEDIUM
Tags: Mathematics

Greedy algorithms
Skill types: Greedy algorithms

Starter code:

Solutions:
def f(n):
	res = 0
	while n > 0:
		res = res + 1
		n = n // 10
	return res

def check(n):
	res = 0
	while n > 0:
		res = res + n % 10
		n = n // 10
	return res
for _ in range(int(input())):
	(n, s) = list(map(int, input().split()))
	len = f(n)
	ans = pow(10, 20)
	if check(n) <= s:
		ans = 0
	for i in range(0, len):
		p = n // pow(10, i + 1)
		p = p * pow(10, i + 1)
		p = p + pow(10, i + 1)
		if check(p) <= s:
			if ans > p - n:
				ans = p - n
	print(ans)


n = int(input())
li = []
lis = []
for i in range(n):
	li = [int(i) for i in input().split()]
	a = li[0]
	b = li[1]
	r = a % b
	if r == 0:
		lis.append(0)
	else:
		s = b - r
		lis.append(s)
for i in lis:
	print(i)


n = int(input())
for i in range(n):
	m = list(map(int, input().split()))
	a = m[0]
	b = m[1]
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


test_cases = int(input())
for z in range(test_cases):
	(a, b) = map(int, input().split())
	if a % b != 0:
		qnt = a // b + 1
		nqnt = b * qnt
		print(nqnt - a)
	else:
		print('0')


from math import ceil as c
n = int(input())
for i in range(n):
	(a, b) = [int(j) for j in input().split()]
	if a % b == 0:
		print(0)
	else:
		print(int(c(a / b)) * b - a)


def qq(a, b):
	if b > a:
		return b - a
	if a % b == 0:
		return '0'
	else:
		k = a // b
		return b * (k + 1) - a
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	print(qq(a, b))


t = int(input())
while t > 0:
	txt = input().split(' ')
	(a, b) = (int(txt[0]), int(txt[1]))
	mov = 0
	if b > a:
		mov = b - a
	else:
		l = a // b
		if a % b != 0:
			mov = b * (l + 1) - a
	print(mov)
	t -= 1


def get_number():
	return int(input())

def get_numbers():
	return list(map(int, input().split()))
t = get_number()
for tt in range(t):
	(a, b) = get_numbers()
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


t = int(input())
while t:
	t -= 1
	(a, b) = map(int, input().strip().split(' '))
	x = int(a / b)
	if a % b == 0:
		print(0)
		continue
	else:
		print((x + 1) * b - a)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print('0')
	elif b > a:
		print(b - a)
	else:
		print(b - a % b)


for i in range(int(input())):
	(a, b) = [int(i) for i in input().split()]
	print((b - a % b) % b)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	moves = 0
	if a % b == 0:
		move = 0
	else:
		rem = a % b
		move = b - rem
	print(move)


import math
n = int(input())
arr = []
for i in range(n):
	(a, b) = map(int, input().split())
	if a <= b:
		arr.append(b - a)
	else:
		steps = math.ceil(a / b)
		while b * steps % b != 0:
			steps += 1
		arr.append(b * steps - a)
for i in arr:
	print(i)


from sys import stdin
inf = stdin
for _ in range(int(inf.readline())):
	(a, b) = map(int, inf.readline().split(' '))
	if a < b:
		print(b - a)
	elif a % b != 0:
		print(b - a % b)
	else:
		print(0)


def getDigit(n, i):
	if i > 1:
		return getDigit(n // 10, i - 1)
	else:
		return n % 10
t = int(input())
while t:
	t -= 1
	line = input().split()
	n = int(line[0])
	s = int(line[1])
	ans = 0
	ns = str(n)
	tot = 0
	for char in ns:
		tot += int(char)
	if tot <= s:
		print(0)
		continue
	for i in range(1, 21):
		dig = getDigit(n, i)
		toAdd = pow(10, i - 1) * (10 - dig)
		if dig == 0:
			toAdd = 0
		ans += toAdd
		if dig > 0:
			n += toAdd
		ns = str(n)
		tot = 0
		for char in ns:
			tot += int(char)
		if tot <= s:
			break
	print(ans)


for case in range(1, int(input()) + 1):
	(a, b) = map(int, input().split())
	print(b - a % b if a % b else 0)


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	elif b > a:
		print(b - a)
	else:
		p = a % b
		print(b - p)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if b >= a:
		print(b - a)
	elif a % b == 0:
		print(0)
	else:
		s = a // b + 1
		print(s * b - a)


n = int(input())
for i in range(0, n):
	(a, b) = map(int, input().split())
	x = a % b
	if x == 0:
		print('0')
	else:
		t = abs(b - x)
		print(t)


rw = int(input())
for wewq in range(rw):
	(n, s) = map(int, input().split())
	p = list(map(int, list(str(n))))
	ps = 0
	for i in p:
		ps += i
	p.reverse()
	if ps <= s:
		print(0)
		continue
	for i in range(len(p)):
		ps -= p[i]
		p[i] = 0
		k9 = 0
		j = i
		while j < len(p) and p[j] == 9:
			j += 1
			k9 += 1
		if ps + 1 <= s or ps + 1 <= s - k9 * 9:
			if i == len(p) - 1:
				p = p + [1]
			else:
				p[i + 1] += 1
			break
	for i in range(len(p)):
		if p[i] == 10:
			p[i] = 0
			if i == len(p) - 1:
				p = p + [1]
			else:
				p[i + 1] += 1
	a = ''
	p.reverse()
	for i in p:
		a += str(i)
	print(int(a) - n)


h = int(input())
l = []
for i in range(h):
	a = []
	(n, s) = list(map(int, input().split()))
	k = str(n)
	sum = 0
	for i in range(len(k)):
		sum += int(k[i])
		if sum == s and i != len(k) - 1 and (n % 10 ** (len(k) - i - 1) != 0):
			l.append((n // 10 ** (len(k) - i) + 1) * 10 ** (len(k) - i) - n)
			break
		elif sum == s and i == len(k) - 1:
			l.append(0)
			break
		elif sum > s:
			l.append((n // 10 ** (len(k) - i) + 1) * 10 ** (len(k) - i) - n)
			break
		elif sum < s and i == len(k) - 1:
			l.append(0)
			break
for i in l:
	print(i)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
		continue
	x = a // b + 1
	print(x * b - a)


n = int(input())
for _ in range(n):
	(a, b) = list(map(int, input().split()))
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


def calc(a, b):
	if a % b == 0:
		return 0
	return (a // b + 1) * b - a
N = int(input())
cases = []
for _ in range(N):
	cases.append(map(int, input().split()))
for (a, b) in cases:
	print(calc(a, b))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	print(-a % b)


n = int(input())
for i in range(n):

	def find(a, b):
		x = a % b
		ans = b - x
		print(ans)
	(a, b) = [int(j) for j in input().split()]
	if a % b == 0:
		print(0)
	elif b > a:
		print(b - a)
	else:
		find(a, b)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	sol = (a // b + 1) * b - a
	print(0 if sol == b else sol)


n_tests = int(input())
for i in range(1, n_tests + 1):
	(a, b) = map(int, input().split(' '))
	cnt = 0
	if a % b == 0:
		print(0)
	elif a < b:
		print(b - a)
	else:
		print(b - a % b)


for i in range(int(input())):
	a = input().split()
	(a, b) = (int(a[0]), int(a[1]))
	print((b - a % b) % b)


def f(a, b):
	if a < b:
		return b - a
	if a % b == 0:
		return 0
	return b - a % b

def main():
	t = int(input())
	for _ in range(t):
		(a, b) = [int(i) for i in input().split()]
		print(f(a, b))
main()


numinput = int(input())

def minmoves(a, b):
	remainder = a % b
	if remainder == 0:
		return 0
	return b - remainder
for i in range(numinput):
	(a, b) = input().split(' ')
	a = int(a)
	b = int(b)
	print(minmoves(a, b))


n = int(input())
while n != 0:
	s = input()
	a = 0
	b = 0
	n -= 1
	for i in range(len(s)):
		if s[i] == ' ':
			a = int(s[0:i])
			b = int(s[i + 1:])
	t = 0
	if a % b != 0:
		t = b - a % b
		print(t)
	else:
		print('0')


from sys import stdin

def iinput():
	return int(stdin.readline())

def minput():
	return map(int, stdin.readline().split())

def linput():
	return list(map(int, stdin.readline().split()))
from collections import defaultdict
from math import factorial

def digitSum(m):
	sm = 0
	for e in str(m):
		sm += int(e)
	return sm
t = iinput()
while t:
	t -= 1
	(n, s) = minput()
	if digitSum(n) <= s:
		print(0)
	else:
		(temp, x) = (0, 0)
		i = 0
		n = str(n)
		while temp <= s and i < len(n):
			temp += int(n[i])
			x = i
			i += 1
		ans = 0
		if temp > s:
			while x >= 0:
				if temp - int(n[x]) + 1 <= s:
					if x == 0:
						ans = int('1' + '0' * len(n))
					else:
						ans = int(str(int(n[:x]) + 1) + '0' * len(n[x:]))
					break
				else:
					temp -= int(n[x])
					x -= 1
			else:
				ans = int('1' + '0' * len(n))
		print(ans - int(n))


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	c = math.ceil(a / b)
	print(c * b - a)


def solve(n, s):
	sums = []
	all_sum = 0
	nn = n
	while nn > 0:
		sums.append(all_sum)
		all_sum += nn % 10
		nn = nn // 10
	if all_sum <= s:
		return 0
	m = 10 ** len(sums)
	for (i, d) in enumerate(sums):
		if all_sum - d < s:
			m = 10 ** i
			break
	return m - n % m
t = int(input())
for _ in range(t):
	(n, s) = (int(x) for x in input().split())
	print(solve(n, s))


tests = int(input())
for i in range(tests):
	(x, y) = map(int, input().split())
	if x % y == 0:
		print(0)
	else:
		gap = x // y + 1
		print(gap * y - x)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	c = a % b
	if c == 0:
		print(c)
	else:
		print(b - c)


z = int(input())
q = []
for i in range(z):
	n = input()
	n = n.split()
	a = int(n[0])
	b = int(n[1])
	s = 0
	if a <= b:
		s = b - a
	elif a % b == 0:
		s = 0
	else:
		s = (a // b + 1) * b - a
	q.append(s)
for i in range(z):
	print(q[i])


t = int(input())
for a in range(t):
	s = input().split(' ')
	a = int(s[0])
	b = int(s[1])
	if a % b:
		print(b - a % b)
	else:
		print(0)


for i in range(int(input())):
	(n, s) = map(int, input().split())
	n = str(n)
	e = []
	for a in range(len(n)):
		e.append(int(n[a]))
	if sum(e) <= s:
		print(0)
	else:
		t = 0
		for b in range(len(e)):
			y = len(e) - b - 1
			if sum(e) <= s:
				l = 0
			elif e[y] != 0:
				j = (10 - e[y]) * 10 ** b
				t += j
				e[y] = 0
				if b + 1 != len(e):
					if e[y - 1] != 9:
						e[y - 1] += 1
					else:
						e[y - 1] = 0
						e[y - 2] += 1
		print(t)


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	print(b - (a - 1) % b - 1)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split(' '))
	c = b - 1
	mod = a % b
	if mod == 0:
		print(0)
	else:
		print(abs(mod - c) + 1)


t = int(input())
for qwerty in range(t):
	(n, s) = input().split()
	s = int(s)
	v = 0
	pos = len(n) - 1
	for i in range(len(n)):
		v += int(n[i])
	if v <= s:
		a = int(n)
	else:
		v = 0
		for i in range(len(n)):
			v += int(n[i])
			if v >= s:
				pos = i
				break
		if pos == 0:
			a = 1
			for i in range(len(n)):
				a *= 10
		else:
			pos -= 1
			a = 0
			for i in range(len(n)):
				a *= 10
				a += int(n[i])
				if i == pos:
					a += 1
					break
			for i in range(len(n) - pos - 1):
				a *= 10
	print(a - int(n))


import sys
input = sys.stdin.readline

def sol(n, s):
	c = 0
	i = 0
	while True:
		if digsum(n) <= s:
			return c
		else:
			c += (10 - n % 10) * 10 ** i
			n //= 10
			n += 1
			i += 1

def digsum(n):
	r = 0
	while n != 0:
		r += n % 10
		n //= 10
	return r
for t in range(int(input())):
	(n, s) = map(int, input().split())
	print(sol(n, s))


tem = int(input())
while tem:
	(n, k) = map(int, input().split())
	rem = n % k
	if rem == 0:
		print(0)
	else:
		print(k - rem)
	tem -= 1


a = int(input())
for _ in range(a):
	(v1, v2) = map(int, input().split())
	if v1 % v2 == 0:
		print('0')
	else:
		z = v2 - v1 % v2
		print(z)


import sys
input = sys.stdin.readline
for i in range(int(input())):
	(a, b) = map(int, input().split())
	n = a
	if a % b != 0:
		n = a // b * b + b
	print(n - a)


t = int(input())
while t > 0:
	t -= 1
	(n, s) = map(int, input().strip().split(' '))

	def calcSum(num):
		st = str(num)
		st = list(st)
		sm = 0
		for i in range(len(st)):
			sm += int(st[i])
		return sm
	diff = calcSum(n) - s
	if diff < 1:
		print(0)
	else:
		done = False
		ind = 1
		newnum = n
		ans = 0
		while not done:
			k = newnum % 10
			adf = 10 - k
			ans += ind * adf
			newnum = newnum // 10
			newnum += 1
			diff = calcSum(newnum) - s
			if diff < 1:
				done = True
				break
			ind = ind * 10
		print(ans)


(a, b) = (int(input('')), [])
for x in range(a):
	b.append(input('').split(' '))
c = []

def totalfunc(num):
	test = [0, []]
	found = False
	for x in range(len(num)):
		temp = int(num[x])
		test[0] += temp
		if temp != 0 or found == True:
			test[1].append(x)
			found = True
	return test
for x in b:
	broke = totalfunc(x[0])
	(total, pos) = (broke[0], broke[1])
	if total <= int(x[1]):
		c.append(0)
	else:
		temp = 0
		possiblefinal = x[0]
		for y in range(len(pos) - 1, -1, -1):
			temp += (10 - int(possiblefinal[pos[y]])) * 10 ** (len(possiblefinal) - pos[y] - 1)
			possiblefinal = int(x[0]) + temp
			if totalfunc(str(possiblefinal))[0] <= int(x[1]):
				c.append(temp)
				break
			else:
				possiblefinal = str(possiblefinal)
for x in c:
	print(x)


x = int(input())
for i in range(x):
	list1 = list(map(int, input().split()))
	if list1[0] % list1[1] == 0:
		print(0)
	else:
		print(list1[1] - list1[0] % list1[1])


answer = []
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	moves = 0
	if a % b != 0:
		if a < b:
			moves = b - a
		if a > b:
			aux = int(a / b)
			moves = b * (aux + 1) - a
	answer.append(moves)
for item in answer:
	print(item)


a = int(input())
for i in range(a):
	(a, b) = [int(i) for i in input().split()]
	if a % b == 0:
		print('0')
	else:
		print(b - a % b)


def solve(a, b):
	if a % b == 0:
		return 0
	else:
		return b - a % b
t = int(input())
for i in range(t):
	(a, b) = [int(x) for x in input().split()]
	print(solve(a, b))


for _ in range(int(input())):
	(s1, s) = input().split()
	s = int(s)
	a = list(map(int, list(s1)))
	cs = sum(a)
	ans = []
	t = 0
	while cs > s:
		if a == []:
			break
		ce = a.pop()
		ce += t
		t = 0
		if ce == 0:
			ans.append(0)
			continue
		cs -= ce - 1
		t = 1
		ans.append(10 - ce)
	ans1 = 0
	n = len(ans) - 1
	for i in reversed(ans):
		ans1 += i * 10 ** n
		n -= 1
	print(ans1)


def solve(n, s):
	sn = str(n)
	ans = ''
	len_sn = len(sn)
	for i in range(len_sn - 1, -1, -1):
		ans = str(int(sn[0:i + 1]) + 1)
		digit_sum = sum((int(d) for d in ans))
		if digit_sum <= s:
			ret = int(ans.ljust(len_sn, '0'))
			if ret < n:
				ret *= 10
			return ret
	return int('1' + '0' * len_sn)
t = int(input())
for _ in range(t):
	(n, s) = map(int, input().split())
	digit_sum = sum((int(d) for d in str(n)))
	if digit_sum <= s:
		print(0)
	else:
		nf = solve(n, s)
		print(nf - n)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	if n % m == 0:
		print(0)
	else:
		print(m - n % m)


def dig(n):
	sum = 0
	for i in str(n):
		sum += int(i)
	return sum
t = int(input())
for z in range(t):
	(n, s) = map(int, input().split())
	p = ''
	l = list(map(int, str(n).rstrip()))
	if dig(n) <= s:
		print(0)
	else:
		for i in range(len(l) - 1, -1, -1):
			if l[i] > 0:
				p += str(10 - l[i])
				l[i - 1] += 1
			else:
				p += '0'
			if dig(int(p[::-1]) + n) <= s:
				break
	print(p[::-1])


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	t = int(input())
	for i in range(t):
		(n, s) = map(int, input().split())
		x = str(n)
		temp = 0
		j = len(x)
		pre = x
		for i in range(len(x)):
			if temp > s:
				j = i
				pre = x[:i]
				break
			temp += int(x[i])
		if temp <= s:
			print(0)
			continue
		for p in pre[::-1]:
			if temp + 1 > s:
				temp = temp - int(p)
				j = j - 1
			else:
				break
		ans = (n // 10 ** (len(x) - j) + 1) * 10 ** (len(x) - j)
		print(ans - n)
main()


from sys import stdin

def main():
	input = lambda : stdin.readline()[:-1]
	T = int(input())
	for _ in [0] * T:
		(A, B) = map(int, input().split())
		if not A % B:
			print(0)
		else:
			print(B - A % B)
main()


import sys
for _ in range(0, int(input())):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		print((a // b + 1) * b - a)


n = int(input())
list = []
for i in range(n):
	(x, y) = [int(j) for j in input().split()]
	if x % y == 0:
		k = 0
	elif x % y != 0:
		k = y - x % y
	list.append(k)
for i in list:
	print(i, end='\n')


test = int(input())
for t in range(test):
	(a, b) = input().split()
	(a, b) = (int(a), int(b))
	ans = a % b
	if ans == 0:
		print(0)
	else:
		print(b - ans)


t = int(input())
for test in range(t):
	(a, b) = map(int, input().split())
	print(((b - a) % b + b) % b)


from collections import defaultdict, deque
from itertools import permutations, product, combinations
from functools import lru_cache
from time import time
import sys
from operator import itemgetter
start = time()

def show_time():
	print(time() - start, file=sys.stderr)
try:
	f = open('test.in')

	def ints():
		return map(int, f.readline().strip().split())

	def one_int():
		return int(f.readline())

	def one_string():
		return f.readline().strip()

	def strings():
		return f.readline().strip().split()
except FileNotFoundError:

	def ints():
		return map(int, input().strip().split())

	def one_int():
		return int(input())

	def one_string():
		return input().strip()

	def strings():
		return input().strip().split()

def debug(s):
	print(s, file=sys.stderr)
sys.stderr.write('\n')
t = one_int()
for _ in range(t):
	(a, b) = ints()
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


import sys
import math

def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return list(map(int, sys.stdin.readline().split()))

def SI():
	return sys.stdin.readline().strip()

def findSum(n, s):
	su = 0
	ind = -1
	for i in range(len(n)):
		su += int(n[i])
		if su > s:
			ind = i
			break
	return ind
t = II()
for q in range(t):
	(n, s) = MI()
	n = str(n)
	ans = 0
	ind = findSum(n, s)
	while ind != -1:
		f = n[:ind]
		if f == '':
			f = '0'
		se = '0' + '0' * (len(n) - ind - 1)
		f = str(int(f) + 1) + se
		ans += int(f) - int(n)
		n = f
		ind = findSum(n, s)
	print(ans)


t = int(input())
while t:
	(a, b) = [int(a) for a in input().split()]
	if a % b == 0:
		diff = 0
	else:
		diff = b - a % b
	print(diff)
	t -= 1


t = int(input())
while t != 0:
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		m = a // b
		mi = m + 1
		n = b * mi - a
		print(n)
	t -= 1


import sys
import os
from io import BytesIO, IOBase
from collections import Counter, deque
import math

def ceil(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def ddd():
	return collections.defaultdict(collections.defaultdict(int))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(ii()):
	(a, b) = mi()
	tmp = (a - 1) // b
	print((tmp + 1) * b - a)


for x in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		k = a // b + 1
		print(k * b - a)


t = int(input())
for i in range(t):
	l1 = [int(j) for j in input().split(' ')]
	if l1[0] % l1[1] == 0:
		print(0)
	else:
		print(l1[1] - l1[0] % l1[1])


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		c = a // b
		c += 1
		k = b * c
		print(k - a)


def main():
	for _ in range(int(input())):
		ans = 0
		(a, b) = map(int, input().split())
		if a % b == 0:
			print('0')
			continue
		else:
			x = a // b
			print(b * (x + 1) - a)
main()


t = int(input())
for i in range(t):
	k = 0
	(a1, b) = map(int, input().split())
	if a1 > b:
		a2 = a1 + -(a1 % b) % b
		print(a2 - a1)
	elif a1 < b:
		print(b - a1)
	else:
		print(0)


n = int(input().strip())
t = []

def numb(m):
	m = m.split()
	a = int(m[0])
	b = int(m[1])
	if a <= b:
		return b - a
	elif a % b == 0:
		return 0
	else:
		count = a // b
		b = b * (count + 1)
		return b - a
for i in range(n):
	m = input().strip()
	t.append(numb(m))
for i in range(len(t)):
	print(t[i])


n = int(input())
for _ in range(n):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
		continue
	if b > a:
		print(b - a)
	else:
		print((a // b + 1) * b - a)


def divisible(a, b):
	s = 0
	if a > b and a % b != 0:
		s = b - (a - b) % b
	elif a <= b:
		s = b - a
	return s
l = []
n = int(input())
for i in range(n):
	m = input().split()
	l.append(m)
for i in l:
	print(divisible(int(i[0]), int(i[1])))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	x = a % b
	if x == 0:
		print(0)
	else:
		print(b - x)


num_of_test = int(input())
lst = []
for i in range(0, num_of_test):
	lst.append(list(map(int, input().split())))
for i in range(0, num_of_test):
	a = lst[i][0]
	b = lst[i][1]
	rem = a % b
	print((b - rem) % b)


t = int(input())
while t:
	(a, b) = map(int, input().split())
	if a % b == 0:
		print('0')
	else:
		rem = a // b + 1
		p = b * rem
		ans = p - a
		print(ans)
	t = t - 1


import math

def list_input():
	return list(map(int, input().split()))
for t in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		print(b * math.ceil(a / b) - a)


T = int(input())
ans = [0] * T
for t in range(T):
	(n, s) = input().split()
	s = int(s)
	cum = [0] * (len(n) + 1)
	for i in range(len(n)):
		cum[i + 1] = cum[i] + int(n[i])
	if cum[-1] <= s:
		ans[t] = 0
		continue
	for i in range(len(n) - 1, -1, -1):
		if n[i] == 9:
			cum[i] -= 10
		if cum[i] + 1 <= s:
			ans[t] = 10 ** (len(n) - i) - int(n[i:])
			break
print(*ans, sep='\n')


def dsum(n):
	sum = 0
	while n > 0:
		r = n % 10
		n = n // 10
		sum += r
	return sum
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	ans = 0
	f = 0
	while dsum(n) > s:
		ans += (10 - n % 10) * 10 ** f
		n = n // 10
		n += 1
		f += 1
	print(ans)


import math
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		nearNum = math.ceil(a / b)
		print(b * nearNum - a)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
for ti in range(t):
	(a, b) = (int(i) for i in input().split(' '))
	if b > a:
		print(b - a)
	elif a % b == 0:
		print(0)
	else:
		print(b - a % b)


import sys

class ADivisibilityProblem:

	def solve(self):
		for _ in range(int(input())):
			(a, b) = [int(_) for _ in input().split()]
			print((b - a) % b)
solver = ADivisibilityProblem()
input = sys.stdin.readline
solver.solve()


def isdiv():
	(a, b) = map(int, input().split())
	val = 0
	if a % b != 0:
		val = b - a % b
	return val
t = int(input())
for i in range(t):
	print(isdiv())


for t in range(int(input())):
	(a, b) = map(int, input().split())
	ans = a % b
	if ans == 0:
		print(0)
		continue
	print(b - a % b)


def program():
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)
for i in range(int(input())):
	program()


T = int(input())
e = []
for i in range(T):
	l = [int(i) for i in input().split()]
	e.append(l)

def output(a, b):
	if a % b == 0:
		return 0
	else:
		return b - a % b
for i in range(T):
	print(output(e[i][0], e[i][1]))


import os
import sys
if os.path.exists('/mnt/c/Users/Square/square/codeforces'):
	f = iter(open('A.txt').readlines())

	def input():
		return next(f)
else:
	input = lambda : sys.stdin.readline().strip()
fprint = lambda *args: print(*args, flush=True)
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	print(-a % b)


PI = 3.141592653589793
INF = 999999999
MOD = 1000000007

def add(x, y):
	return (x + y) % MOD

def sub(x, y):
	return (x - y + MOD) % MOD

def mul(x, y):
	return x * y % MOD

def gcd(x, y):
	if y == 0:
		return x
	return gcd(y, x % y)

def lcm(x, y):
	return x * y // gcd(x, y)

def power(x, y):
	res = 1
	x %= MOD
	while y != 0:
		if y & 1:
			res = mul(res, x)
		y >>= 1
		x = mul(x, x)
	return res

def mod_inv(n):
	return power(n, MOD - 2)

def prob(p, q):
	return mul(p, power(q, MOD - 2))

def ii():
	return int(input())

def li():
	return [int(i) for i in input().split()]

def ls():
	return [i for i in input().split()]
for t in range(ii()):
	t += 1
	(n, s) = li()
	N = str(n)
	total = 0
	for i in N:
		total += int(i)
	if total <= s:
		print(0)
		continue
	temp = s
	index = 0
	while int(N[index]) < temp:
		temp -= int(N[index])
		index += 1
	l = len(N)
	if index < len(N):
		print(10 ** (l - index) - int(N[index:]))
	else:
		print(10 ** len(N) - n)


import math

def printDivisors(n):
	list = []
	ans = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				ans.append(i)
			else:
				ans.append(i)
				list.append(int(n / i))
	for i in list[::-1]:
		ans.append(i)
	return ans

def sumofdigits(n):
	sm = 0
	while n > 0:
		sm += n % 10
		n = n // 10
	return sm

def listofDigits(n):
	l = []
	while n > 0:
		l.append(n % 10)
		n = n // 10
	l.reverse()
	return l
T = int(input())
for t in range(T):
	(n, s) = map(int, input().split())
	sm = sumofdigits(n)
	n_s = listofDigits(n)
	ind = len(n_s) - 1
	cnt = 0
	exp = 1
	while ind >= 0 and sm > s:
		sm += 1
		sm -= n_s[ind]
		cnt += (10 - n_s[ind]) * exp
		exp *= 10
		ind -= 1
		while ind >= 0 and n_s[ind] == 9:
			exp *= 10
			sm -= 9
			ind -= 1
		if ind >= 0:
			n_s[ind] = n_s[ind] + 1
	print(cnt)


w = int(input())
a = []
c = 0
for i in range(0, w):
	p = input().split()
	a.append(p)
for i in range(0, w):
	r = a[i]
	t = 0
	x = int(r[0])
	y = int(r[1])
	z = x % y
	if z == 0:
		w = 0
	elif x > y:
		w = z - y
	elif x <= y:
		w = y - x
	print(abs(w))


import sys
from math import *
from collections import defaultdict as dd
input = sys.stdin.readline
RI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
rw = lambda : input().strip().split()
ls = lambda : list(input().strip())
si = lambda : int(input().strip())
from collections import defaultdict as df
import heapq
infinite = float('inf')
t = si()
for _ in range(t):
	(n, m) = RI()
	print((n + m - 1) // m * m - n)


for f in [*open(0)][1:]:
	(n, s) = map(int, f.split())
	v = n
	d = 1
	while sum(map(int, str(n))) > s:
		n += -(n // d % 10) % 10 * d
		d *= 10
	print(n - v)


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
import random
from queue import PriorityQueue
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
from collections import defaultdict
from heapq import heappop, heappush, heapify
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	z = b * ceil(a / b)
	print(abs(z - a))


import sys
from math import ceil, floor
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda : sys.stdin.readline().rstrip()

def eprint(s):
	sys.stderr.write('DEBUG: {}'.format(s))
	return

def main():
	t = int(input())
	for i in range(t):
		(a, b) = map(int, input().split())
		if a % b == 0:
			print(0)
		else:
			print(b - a % b)
	return
main()


t = int(input())
for _ in range(t):
	ans = 0
	(a, b) = [int(i) for i in input().split()]
	ost = a % b
	if ost:
		ans = b - ost
	print(ans)


for i in range(int(input())):
	(x, y) = map(int, input().split())
	if x % y == 0:
		print(0)
	else:
		print(y - x % y)


n = int(input())
a = list()
b = list()
r = list()
for i in range(n):
	(x, y) = input().split(' ')
	a.append(int(x))
	b.append(int(y))
	if a[i] % b[i] == 0:
		r.append(0)
	else:
		r.append(b[i] - a[i] % b[i])
for i in r:
	print(i)


def numAdd(x, y):
	if x < y:
		return y - x
	elif x % y != 0:
		m = x % y
		return y - m
	else:
		return 0
n = int(input())
for i in range(n):
	a = list(map(int, input().strip().split()))[:2]
	leastNum = numAdd(a[0], a[1])
	print(leastNum)


import math

def main():
	T = int(input().split()[0])
	while T:
		(a, b) = map(int, input().split())
		print(str(math.ceil(a / b) * b - a))
		T -= 1
main()


t = int(input())
for i in range(t):
	(n, m) = [int(i) for i in input().split()]
	if n < m:
		print(m - n)
	elif n % m == 0:
		print(0)
	else:
		print((n // m + 1) * m - n)


t = int(input())
for i in range(t):
	list1 = list(map(int, input().split()))
	a = list1[0]
	b = list1[1]
	temp = a // b
	temp += 1
	if a % b == 0:
		print(0)
	else:
		print(b * temp - a)


t = int(input())
for i in range(t):
	w = list(map(int, input().split()))
	mod = w[0] % w[1]
	if mod == 0:
		print(0)
	else:
		print(w[1] - mod)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	c = a // b
	if c == a / b:
		d = c * b
	else:
		d = (c + 1) * b
	print(d - a)


n = int(input())
for a in range(n):
	x = [int(i) for i in input().split()]
	if x[0] % x[1] == 0:
		print(0)
		continue
	res = int(x[0] / x[1])
	print((res + 1) * x[1] - x[0])


t = int(input())
while t:
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)
	t = t - 1


T = int(input())
for _ in range(T):
	(a, b) = [int(i) for i in input().split()]
	print((b - a % b) % b)


t = int(input())
for test in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
		continue
	x = (a // b + 1) * b - a
	print(x)


for _ in range(int(input())):
	(s, k) = map(str, input().split())
	k = int(k)
	su = 0
	for i in range(len(s)):
		su += int(s[i])
		if su >= k:
			ans = int(s[i:])
			ans = int('1' + (len(s) - i) * '0') - ans
			break
	su = 0
	for i in range(len(s)):
		su += int(s[i])
	if su <= k:
		print(0)
	else:
		print(ans)


t = int(input())
for _ in range(t):
	(n, s) = input().split()
	n = [int(i) for i in list(n)]
	s = int(s)
	cursum = sum(n)
	if cursum <= s:
		print(0)
	else:
		n = n[::-1]
		p = 1
		cur = 0
		gone = 0
		for i in range(len(n)):
			if n[i] == 0:
				p *= 10
				continue
			cur += n[i] * p
			gone += n[i]
			p *= 10
			if cursum - gone + 1 <= s:
				print(p - cur)
				break


t = int(input())
for _ in range(t):
	(n, s) = input().split()
	(*n,) = map(int, n)
	n = [0] + n
	s = int(s)
	n_sum = sum(n)
	ans = []
	ind = 0
	while n_sum > s:
		if n[-1 - ind] > 0:
			ans.append(10 - n[-1 - ind])
			n[-1 - ind] = 0
			for i in range(len(n)):
				n[-2 - i - ind] += 1
				if n[-2 - i - ind] == 10:
					n[-2 - i - ind] = 0
				else:
					break
		else:
			ans.append(0)
		n_sum = sum(n)
		ind += 1
	if ans != []:
		print(''.join(map(str, ans[::-1])))
	else:
		print(0)


def solve(a, b):
	if a % b == 0:
		return 0
	if a < b:
		return b - a
	start = int(a / b) * b
	end = start + b
	while not start <= a <= end:
		start = end
		end = start + b
	return end - a
numCases = int(input().strip())
for i in range(0, numCases):
	(a, b) = [int(x) for x in input().strip().split()]
	print(solve(a, b))


x = int(input())
for y in range(x):
	d = 0
	(u, i) = input().split()
	u = int(u)
	i = int(i)
	if u % i == 0:
		print(0)
	else:
		print(i - u % i)


t = int(input())
li = []
for _ in range(t):
	(a, b) = input().split(' ')
	a = int(a)
	b = int(b)
	rem = a % b
	if rem == 0:
		moves = 0
	else:
		moves = b - rem
	li.append(moves)
n = len(li)
for i in range(n):
	print(li[i])


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0 or a == b:
		print(0)
	elif a < b:
		print(b - a)
	else:
		c = a / b
		c1 = int(c)
		d = (c1 + 1) * b
		print(d - a)


n = int(input())
for i in range(0, n):
	l = [int(x) for x in input().split()]
	if l[0] % l[1] != 0:
		print(l[1] - l[0] % l[1])
	else:
		print(0)


def main():
	for _ in range(int(input())):
		(a, b) = list(map(int, input().split()))
		print((b - a % b) % b)
main()


for i in range(int(input())):
	(a, b) = list(map(int, input().split()))
	if a % b == 0:
		print(0)
	else:
		d = a // b
		rem = (d + 1) * b - a
		print(rem)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if b == 0:
		print(0)
	elif a == 0:
		print(b)
	elif b > a:
		print(b - a)
		continue
	elif a // b == a / b:
		print('0')
	else:
		k = a // b + 1
		print(k * b - a)


import math
t = int(input())
for _ in range(t):
	(a, b) = input().split()
	(a, b) = (int(a), int(b))
	cc = 0
	if a < b:
		cc = b - a
	elif a % b == 0:
		cc = 0
	else:
		hehe = a // b
		cc = b * (hehe + 1) - a
	print(int(cc))


t = int(input())
for i in range(t):
	ab = tuple(map(int, input().split()))
	if ab[0] % ab[1] == 0:
		print(0)
	elif ab[0] < ab[1]:
		print(ab[1] - ab[0])
	else:
		print(ab[1] * (int(ab[0] / ab[1]) + 1) - ab[0])


from sys import stdin

class Problem:

	def __init__(self, n, s):
		self.n = n
		self.s = s
		self.stack = []

	def solve(self):
		number = '0' + str(self.n)
		current_sum = 0
		for digit in number:
			d = int(digit)
			self.stack.append(d)
			current_sum += d
		adds = 0
		ten = 1
		while current_sum > self.s:
			d = self.stack.pop()
			if d == 0:
				ten = ten * 10
				continue
			if d == 10:
				current_sum = current_sum - 9
				self.stack[-1] += 1
			else:
				current_sum = current_sum - d
				adds = adds + ten * (10 - d)
				current_sum = current_sum + 1
				self.stack[-1] += 1
			ten = ten * 10
		return adds
cases = int(stdin.readline())
for test in range(cases):
	(n, s) = map(int, stdin.readline().split())
	ans = Problem(n, s).solve()
	print(ans)


t = int(input())
ab = [list(map(int, input().split())) for _ in range(t)]
ans = [b - a % b if a % b != 0 else 0 for (a, b) in ab]
print(*ans, sep='\n')


from sys import stdin, stdout
from os import path
if path.exists('input.txt'):
	stdin = open('input.txt', 'r')
for _ in range(int(stdin.readline())):
	(x, y) = map(int, stdin.readline().strip().split())
	f = 1
	w = q = x
	sum = 0
	while w != 0:
		sum += w % 10
		w //= 10
	if sum <= y:
		print(0)
	else:
		while sum + 1 > y:
			f *= 10
			sum -= q % 10
			q //= 10
		stdout.write(str(q * f + f - x) + '\n')


def to_digits(n):
	return list(map(int, str(n)))

def digits_to_int(digits):
	return int(''.join(map(str, digits)))
t = int(input())
for _ in range(t):
	(n, s) = map(int, input().split())
	digits = [0] + to_digits(n)
	if sum(digits) <= s:
		print(0)
		continue
	i = 1
	while sum(digits[:i]) < s:
		i += 1
	new_n = digits_to_int(digits[:i - 1] + [0] * (len(digits) - i + 1))
	new_n += 10 ** (len(digits) - i + 1)
	print(new_n - n)


def sum_of_digit(n):
	ans = 0
	while n > 0:
		ans += n % 10
		n = n // 10
	return ans
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	if sum_of_digit(n) <= s:
		print(0)
	else:
		ans = 1
		start = n
		while 1:
			n += 10 ** ans - n % 10 ** ans
			ans += 1
			if sum_of_digit(n) <= s:
				break
		print(n - start)


num_lines = int(input())
for i in range(num_lines):
	(a, b) = list(map(int, input().split()))
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	moves = 0
	if a < b:
		moves = b - a
		print(moves)
		continue
	else:
		if a % b == 0:
			print(moves)
			continue
		moves = a // b * b + b - a
	print(moves)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	print((b - a) % b)


n = int(input())
while n != 0:
	(a, b) = map(int, input().split())
	if int(a % b) == 0:
		print('0')
	else:
		c = int(a / b) + 1
		print(b * c - a)
	n -= 1


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	if x < y:
		print(y - x)
	elif x == y or x % y == 0:
		print(0)
	else:
		w = x // y
		if x % y != 0:
			w += 1
		print(w * y - x)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	(move, power) = (0, 1)
	while sum(map(int, str(n))) > x:
		digit = n // power % 10
		add = power * ((10 - digit) % 10)
		n += add
		move += add
		power *= 10
	print(move)


t = int(input())
for i in range(t):
	li = [int(x) for x in input().split()]
	n = li[0]
	m = li[1]
	if n > m:
		if n % m == 0:
			print(n % m)
		else:
			print(m - n % m)
	else:
		print(m - n)


import sys, io, os, time
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
input = sys.stdin.readline

def sod(num):
	temp = 0
	while num:
		temp += num % 10
		num = num // 10
	return temp
for ii in range(int(input())):
	(n, s) = map(int, input().split())
	kk = n

	def f(dig, ind):
		if sod(dig) <= s:
			return 0
		else:
			temp = 10 - dig % 10 if dig % 10 != 0 else 0
			ans = temp * 10 ** ind
			ans += f(dig // 10 + (1 if temp > 0 else 0), ind + 1)
			return ans
	print(f(n, 0))


for tin in range(int(input())):
	(a, b) = map(int, input().split())
	if a <= b:
		print(b - a)
	elif a % b == 0:
		print(0)
	else:
		print(b - a % b)


t = int(input())
for _ in range(t):
	(n, s) = tuple([int(i) for i in input().split()])
	cs = sum([int(i) for i in str(n)])
	if cs <= s:
		print(0)
		continue
	digs = 0
	for i in str(n)[::-1]:
		cs -= int(i)
		digs += 1
		if cs + 1 <= s:
			break
	val = 10 ** digs - n % 10 ** digs
	print(val)


for wadk in range(int(input())):
	(a, b) = [*map(int, input().split())]
	print((b - a % b) % b)


for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	t = n
	a = []
	while t:
		a.append(t % 10)
		t //= 10
	a = a[::-1]
	ss = sum(a)
	if k >= ss:
		print(0)
	elif a[0] > k:
		print(10 ** len(a) - n)
	else:
		i = 0
		b = 0
		while b + a[i] < k:
			b += a[i]
			i += 1
		t = i
		i -= 1
		while i >= 0:
			if a[i] != 9:
				a[i] += 1
				break
			i -= 1
		if i == -1:
			print(10 ** len(a) - n)
		else:
			ss = 0
			for j in range(i + 1, len(a)):
				a[j] = 0
			for i in a:
				ss = ss * 10 + i
			print(ss - n)


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	n = d * (n // d + 1) - n
	if n == d:
		print(0)
	else:
		print(n)


from collections import Counter
import math
import sys
from bisect import bisect, bisect_left, bisect_right

def input():
	return sys.stdin.readline().strip()

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def mod():
	return 10 ** 9 + 7

def find_sum(n):
	s = 0
	while n:
		s += n % 10
		n //= 10
	return s
for i in range(INT()):
	(n, s) = MAP()
	n2 = n
	diff = find_sum(n) - s
	mult = 10
	while diff > 0:
		n = n - n % mult
		n += mult
		mult *= 10
		diff = find_sum(n) - s
	print(n - n2)


T = int(input())
for t in range(T):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		x = (a // b + 1) * b
		print(x - a)


def r(t=int):
	return list(map(t, input().split()))

def ri(t=int):
	return t(input())

def cd(it):
	ret_val = dict()
	for v in it:
		ret_val[v] = ret_val.get(v, 0) + 1
	return ret_val
for _ in range(ri()):
	(a, b) = r()
	s = 0
	if a % b:
		s = b - a % b
	else:
		s = 0
	print(s)


for i in range(int(input())):
	(n, d) = map(int, input().split())
	r = n % d
	if r == 0:
		print(0)
	else:
		print(d - r)


import sys
cnt = 1
num_inputs = 0
for line in sys.stdin:
	if cnt == 1:
		cnt += 1
		continue
	(a, b) = line.split(' ')
	(a, b) = (int(a), int(b))
	print((b - a % b) % b)


f = int(input())
for i in range(1, f + 1):
	mass = input().split(' ')
	b = int(mass[1])
	a = int(mass[0])
	if a % b == 0:
		print(0)
	else:
		print(str(b - a % b))


def s(n):
	c = 0
	for i in str(n):
		c += int(i)
	return c

def solve(a, b):
	temp = str(a)
	suma = 0
	text = '0'
	for i in range(len(temp)):
		if suma + int(temp[i]) < b:
			suma += int(temp[i])
			text += temp[i]
		else:
			sol = int(f"{int(text) + 1}{(len(temp) - i) * '0'}")
			print(sol - a)
			break
t = int(input())
for i in range(t):
	(a, b) = [int(j) for j in input().split()]
	if s(a) <= b:
		print(0)
	else:
		solve(a, b)


R = lambda : map(int, input().split())
t = int(input())
for _ in range(t):
	(a, b) = R()
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


n = int(input())
for i in range(n):
	[t, y] = [int(x) for x in input().split()]
	z = t % y
	if z == 0:
		print(0)
	else:
		print(y - z)


import bisect
import copy
import fractions
import functools
import heapq
import math
import random
import sys

def __starting_point():
	T = int(input())
	for t in range(T):
		(N, S) = tuple(map(int, input().split()))
		if sum((int(dig) for dig in str(N))) <= S:
			print('0')
			continue
		str_N = '0' + str(N)
		total = 0
		i = 0
		while total < S:
			total += int(str_N[i])
			i += 1
		target = (int(str_N[:i - 1]) + 1) * 10 ** (len(str_N) - i + 1)
		print(str(target - N))
__starting_point()


t = int(input())
l = []
for i in range(t):
	(a, b) = map(int, input().split())
	l.append((a + b - 1) // b * b - a)
for i in l:
	print(i)


for ii in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		d = a // b + 1
		if a < b:
			print(b - a)
		else:
			print(b * d - a)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	if n < m:
		print(m - n)
	else:
		print(((n // m + 1) * m - n) % m)


import math
for _ in range(int(input())):
	(n, s) = input().split()
	k = int(n)
	s = int(s)
	n = [int(i) for i in list(n)][::-1]
	moves = 0
	maxmoves = 10 ** len(n) - k
	csum = sum(n)
	if csum <= s:
		print(moves)
		continue
	if s == 1:
		print(maxmoves)
		continue
	carry = 0
	n += [0]
	for (pos, char) in enumerate(n):
		dig = char
		if carry == 1:
			csum += 1
			dig += 1
			carry = dig // 10
			dig = dig % 10
			if carry == 1:
				csum -= 10
		if dig == 0:
			continue
		if csum <= s:
			break
		while dig != 0 and csum > s:
			dig += 1
			moves += 10 ** pos
			if dig == 10:
				carry = True
				dig = 0
				csum -= 9
			else:
				csum += 1
	if csum <= s:
		print(moves)
		continue


t = int(input())
for you in range(t):
	l = input().split()
	a = int(l[0])
	b = int(l[1])
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


n = int(input())
for i in range(n):
	(a, b) = map(int, input().strip().split())
	c = a % b
	if a % b == 0:
		print(0)
	else:
		print(b - c)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a / b == a // b:
		print('0')
	else:
		n = a % b
		z = b - n
		print(z)


x = int(input())
ans = []
for i in range(x):
	(a, b) = list(map(int, input().split()))
	ans.append(str((b - a % b) % b))
print('\n'.join(ans))


for _ in range(0, int(input())):
	(n, s) = list(map(int, input().split(' ')))
	r = str(n)
	ans = 0
	actu = 0
	for i in range(0, len(r)):
		actu += int(r[i])
	i = len(r) - 1
	while actu > s:
		actu = 0
		n += (10 - int(r[i])) * 10 ** (len(r) - 1 - i)
		ans += (10 - int(r[i])) * 10 ** (len(r) - 1 - i)
		r = str(n)
		for j in range(0, len(r) - 1):
			actu += int(r[j])
		i -= 1
	print(ans)


repetition = int(input())
for times in range(repetition):
	(dividend, divisor) = map(int, input().split())
	multiple = 1
	if dividend % divisor == 0:
		print('0')
	elif dividend < divisor:
		print(divisor - dividend)
	else:
		starting_point = dividend // divisor + 1
		remainder = divisor * starting_point - dividend
		print(remainder)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(100000000)
	threading.stack_size(10240000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(n - r))

def ceil(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def main():
	for _ in range(ii()):
		(n, s) = msi()
		s = int(s)
		tot = 0
		for i in n:
			tot += int(i)
		if tot <= s:
			print(0)
			continue
		if tot < s:
			pass
		else:
			le = len(n)
			new = 0
			car = 0
			for i in range(le - 1, -1, -1):
				cur = int(n[i])
				f = 0
				if car:
					tot -= cur
					cur += 1
					if cur == 10:
						cur = 0
						f = 1
						car = 1
					else:
						car = 0
					tot += cur
				if tot + car <= s:
					new += cur * 10 ** (le - i - 1)
					continue
				if cur == 0:
					if tot + 9 >= s and tot <= s:
						tot -= cur
						if f == 0:
							car = 0
					else:
						tot -= cur
						if f == 0:
							car = 0
						pass
				elif tot - cur + 1 == s:
					car = 1
					tot -= cur
				elif tot - cur + 1 < s:
					tot -= cur
					car = 1
				else:
					tot -= cur
					car = 1
			if car:
				new += 10 ** le
			print(new - int(n))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from math import *
for i in range(int(input())):
	l = list(map(int, input().split()))
	z = ceil(l[0] / l[1])
	k = l[1] * z
	if k > l[0]:
		print(k - l[0])
	else:
		print(0)


q = int(input())
ans = []
for _ in range(q):
	(S, n) = map(int, input().split())
	st = str(S)
	length = len(st)
	trigger = 0
	flg = True
	for (i, s) in enumerate(st, 1):
		n -= int(s)
		if n > 0:
			trigger = i
		elif n < 0:
			flg = False
	if flg:
		res = 0
	else:
		res = pow(10, length - trigger) - int(st[trigger:])
	ans.append(res)
print('\n'.join(map(str, ans)))


from pprint import pprint
import sys
input = sys.stdin.readline
q = int(input())
for _ in range(q):
	(a, b) = map(int, input().split())
	c = b - a % b
	print(0 if c == b else c)


t = int(input())
a = []
for i in range(t):
	b = list(map(int, input().split()))
	if b[0] % b[1] != 0:
		f = b[0] // b[1] + 1
		a.append(f * b[1] - b[0])
	else:
		a.append(0)
for i in a:
	print(i)


for _ in range(int(input())):
	(a, b) = [int(s) for s in input().split()]
	x = a // b
	if a % b == 0:
		print(0)
	else:
		print(abs(a - (x + 1) * b))


for _ in range(int(input())):
	(n, s) = input().split()
	(su, la) = (0, len(n))
	n = n.rstrip()
	s = int(s)
	for i in n:
		su += int(i)
	n = int(n)
	if su <= s:
		print(0)
	else:
		ans = 0
		flag = 0
		for i in range(la):
			if n % 10 != 0:
				z = pow(10, i)
				ans += (10 - n % 10) * z
				su = su - n % 10 + 1
				n = n + (10 - n % 10)
				flag = 1
			elif flag == 1:
				su -= 9
			if su <= s:
				break
			n = n // 10
		print(ans)


t = range(int(input('')))
for i in t:
	ab = input('').split(' ')
	a = int(ab[0])
	b = int(ab[1])
	d = a % b != 0
	print(b - a % b if d else 0)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	N = str(n)
	t = len(N)
	ans = int('1' + '0' * t) - n
	if sum([int(N[i]) for i in range(t)]) <= s:
		print(0)
		continue
	for i in range(t):
		if sum([int(N[j]) for j in range(i + 1)]) + 1 <= s:
			ans = min(ans, int(N[:i] + str(int(N[i]) + 1) + '0' * (t - i - 1)) - n)
	print(ans)


import sys
import os
import time
import collections
from collections import Counter, deque
import itertools
import math
import timeit
import random
import string

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def flin(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)

def ceil(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)
for _ in range(ii()):
	(a, b) = mi()
	t = ceil(a, b)
	print(b * t - a)


t = int(input())
for i in range(t):
	(n, s) = input().split()
	c = []
	n = [int(u) for u in n]
	s = int(s)
	j = len(n) - 1
	sm = 0
	for x in n:
		sm += x
	if sm <= s:
		print(0)
	else:
		while sm > s and j >= 0:
			if n[j] != 0 and j != 0:
				sm -= n[j] - 1
				c.append(10 - n[j])
				n[j] = 0
				n[j - 1] += 1
			elif n[j] == 0 and j != 0:
				c.append(0)
			elif n[j] != 0 and j == 0:
				sm -= n[j] - 1
				c.append(10 - n[j])
				n[j] = 0
			j -= 1
		d = c[-1::-1]
		k = ''
		for x in d:
			k += str(x)
		print(int(k))


import math
n = input()
for i in range(int(n)):
	(a, b) = [int(x) for x in input().split()]
	if a % b == 0:
		print(0)
		continue
	below = math.floor(a / b)
	print(b * (below + 1) - a)


a = int(input())
for i in range(a):
	b = list((int(x) for x in input().split()))
	if b[0] % b[1] != 0:
		print(b[1] - b[0] % b[1])
	else:
		print(0)


import sys
from collections import deque
input = sys.stdin.readline
tc = int(input())
for _ in range(tc):
	(a, b) = list(map(int, input().split()))
	if a % b == 0:
		count = 0
	elif a > b:
		count = b - a % b
	if a < b:
		count = b - a
	print(count)


t = int(input())
for i in range(t):
	(x, y) = map(int, input().split())
	y = (y - x) % y
	print(y)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	t = a
	x = list(map(int, list(str(a))))
	s = sum(x)
	if s <= b:
		print(0)
	else:
		i = 10
		while s > b:
			if a % i != 0:
				a = a + (i - a % i)
			i *= 10
			x = list(map(int, list(str(a))))
			s = sum(x)
		print(a - t)


def solve():
	(s, n) = [i for i in input().split()]
	n = int(n)
	i = 0
	ok = True
	while i < len(s):
		if n > int(s[i]):
			n -= int(s[i])
		else:
			ok = False
			break
		i += 1
	if ok:
		print(0)
		return
	if int(s[i]) == n:
		tmp = 0
		for char in s[i + 1:]:
			tmp += int(char)
			if tmp > 0:
				break
		if tmp == 0:
			print(0)
			return
	total = 10 ** (len(s) - i)
	cur = s[i:]
	print(int(total - int(cur)))
t = int(input())
for _ in range(t):
	solve()


import math
import decimal

def sumDigit(x):
	sum = 0
	for i in x:
		sum += int(i)
	return sum
t = input()
t = int(t)
list = []
for i in range(t):
	(n, s) = input().split()
	n = int(n)
	s = int(s)
	thDigit = 0
	sum = 0
	strn = str(n)
	leng = len(strn)
	while sum < s and leng - 1 >= thDigit:
		sum = sum + int(strn[thDigit])
		thDigit = thDigit + 1
	if sumDigit(strn) <= s:
		list.append(0)
		print(0)
	else:
		sum = sum - int(strn[thDigit - 1])
		d1 = decimal.Decimal(n)
		d2 = decimal.Decimal(10 ** (leng - thDigit + 1))
		d = decimal.Decimal(d1 / d2)
		rounded = d.quantize(1, decimal.ROUND_CEILING)
		rounded = rounded * 10 ** (leng - thDigit + 1)
		print(rounded - n)
		list.append(rounded - n)


t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	if a % b == 0:
		print(0)
	else:
		print((a // b + 1) * b - a)


for z in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		n = a // b
		n = n + 1
		print(b * n - a)


n = int(input())
l = [0] * n
for i in range(n):
	l[i] = list(map(int, input().split()))
	if l[i][0] % l[i][1] == 0:
		print(0)
	else:
		print(l[i][1] - l[i][0] % l[i][1])


t = int(input())
for q in range(t):
	(n, s) = map(int, input().split())
	sm = 0
	n = str(n)
	for i in range(len(n)):
		sm += int(n[i])
	if sm <= s:
		print(0)
	else:
		n = '0' + str(n)
		p = 0
		i = -1
		while i < len(n) - 1 and p < s:
			p += int(n[i + 1])
			i += 1
		print(int(str(int(n[:i]) + 1) + '0' * (len(n) - i)) - int(n))


def su(n):
	out = 0
	for i in str(n):
		out += int(i)
	return out
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	op = 0
	if su(n) <= s:
		print(op)
	else:
		while su(n) > s:
			x = list(str(n))
			x.reverse()
			i = 0
			while x[i] == '0':
				i += 1
			op += 10 ** i * (10 - int(x[i]))
			n += 10 ** i * (10 - int(x[i]))
		print(op)


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)

def in_int():
	return int(input())

def in_list():
	return list(map(int, input().split()))

def in_str():
	s = input()
	return list(s[:len(s) - 1])

def in_ints():
	return map(int, input().split())
q = in_int()
for qq in range(q):
	(a, b) = in_ints()
	if a % b == 0:
		print(0)
	else:
		print(b * (a // b + 1) - a)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		mul = a // b + 1
		before = mul * b
		print(before - a)


import collections
from functools import lru_cache
import bisect
INF = float('inf')
NEG_INF = float('inf')
ZERO = 0
ONE = 1

def read():
	return input().strip()

def readInt():
	return int(input().strip())

def readList():
	return list(map(int, input().strip().split()))

def solve(n, s):
	sNum = list(map(int, str(n)))
	nSum = sum(sNum)
	ans = 0
	N = len(sNum)
	for (i, ch) in enumerate(reversed(sNum)):
		if ch == 0:
			continue
		if nSum > s:
			ans += 10 ** i * ((10 - ch) % 10)
			sNum[N - i - 1 - 1] += 1
			nSum -= ch
			nSum += 1
	return ans
t = readInt()
for i in range(t):
	(n, s) = readList()
	print(solve(n, s))


t = int(input())

def id(x):
	return x
for i in range(t):
	(n, s) = map(int, input().split())
	s = int(s)
	ans = 0
	cancer = sum([int(x) for x in list(str(n))])
	i = 0
	m = n
	while cancer > s:
		if int(str(n)[-1 - i]) == 0:
			pass
		elif cancer - s > int(str(n)[-1 - i]):
			n -= int(str(n)[-1 - i]) * 10 ** i
			n = n + 10 ** (i + 1)
		else:
			n -= int(str(n)[-1 - i]) * 10 ** i
			n = n + 10 ** (i + 1)
		cancer = sum([int(x) for x in list(str(n))])
		i += 1
	print(n - m)


t = int(input())
for i in range(t):
	(a1, b1) = input().split()
	a = int(a1)
	b = int(b1)
	z = 0
	if a % b != 0:
		z = b - a % b
	print(z)


for _ in range(int(input())):
	(a, b) = input().split()
	(b, s, tu, ts) = (int(b), 0, '', 0)
	same = False
	for m in a:
		ts += int(m)
		if s < b:
			s += int(m)
			if s == b and m != '9':
				same = True
			if s >= b:
				tu += m
		else:
			tu += m
	if tu and ts != b:
		td = int(10 ** len(tu)) - int(tu)
		print(td)
	else:
		print(int([s - b, 0][s <= b]))


for t in range(int(input())):
	(a, b) = map(int, input().split())
	count = 0
	if a % b != 0:
		print(b - a % b)
	else:
		print(0)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def digitSum(x):
	c = 0
	while x:
		c += x % 10
		x //= 10
	return c

def solve(x, y):
	if digitSum(x) <= y:
		return 0
	xStr = str(x)
	attempt = 10 ** len(xStr) - x
	for i in range(len(xStr)):
		newNumber = int(xStr[:i + 1]) + 1
		newNumber *= 10 ** (len(xStr) - i - 1)
		if digitSum(newNumber) <= y:
			attempt = newNumber - x
	return attempt
lines = inp()
for i in range(lines):
	v = inlt()
	print(solve(*v))


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	(a, b) = map(int, sys.stdin.readline().split())
	if a == b or a % b == 0:
		move = 0
	elif a < b:
		move = b - a
	else:
		move = b * (int(a // b) + 1) - a
	print(move)


from sys import stdin
for _ in range(int(stdin.readline())):
	(s_str, t) = stdin.readline().split()
	ogs = int(s_str)
	s = list(map(int, list(s_str)))
	t = int(t)
	d = sum(s)
	if d <= t:
		print(0)
	else:
		diff = d - t + 1
		i = len(s) - 1
		while diff > 0:
			diff -= s[i]
			i -= 1
		if i >= 0:
			ceil = (int(s_str[:i + 1]) + 1) * 10 ** (len(s_str) - i - 1)
		else:
			ceil = 10 ** len(s_str)
		print(int(ceil) - ogs)


def ts(n):
	ans = 0
	while n != 0:
		ans += n % 10
		n = n // 10
	return ans
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	temp = 1
	ans = 0
	while ts(n) > s:
		t = n % 10
		if t > 0:
			ans += (10 - t) * temp
			n += 10 - t
		n = n // 10
		temp *= 10
	print(ans)


from collections import Counter
import string
import math
import sys

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(arrber_of_variables):
	if arrber_of_variables == 1:
		return int(sys.stdin.readline())
	if arrber_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))

def printDivisors(n):
	divisors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				divisors.append(i)
			else:
				divisors.extend((i, n // i))
		i = i + 1
	return divisors

def sumt(n):
	return sum([int(i) for i in str(n)])
for _ in range(vary(1)):
	(n, s) = vary(2)
	if sumt(n) <= s:
		print(0)
		continue
	num = [int(i) for i in str(n)]
	sumt2 = 0
	ind = 0
	for i in range(len(num)):
		if sumt2 + num[i] < s:
			sumt2 += num[i]
			continue
		else:
			ind = i
			break
	j = 0
	ans = ''
	for i in range(len(num) - 1, ind - 1, -1):
		if j == 0:
			if num[i] == 0:
				ans += str(0)
				continue
			ans += str(10 - num[i])
			j = 1
			continue
		ans += str(9 - num[i])
	print(str(int(ans[::-1])))


t = int(input())
while t > 0:
	number = input()
	numberlist = number.split(' ')
	a = int(numberlist[0])
	b = int(numberlist[1])
	count = 0
	if a % b == 0:
		print(count)
	elif a > b:
		numberdivide = int(a / b)
		count = (numberdivide + 1) * b - a
		print(count)
	elif a < b:
		count = b - a
		print(count)
	else:
		print(count)
	t -= 1


T = int(input())

def digsum(N):
	return sum(list(map(int, list(str(N)))))
for _ in range(T):
	(n, s) = [int(x) for x in input().split()]
	sm = digsum(n)
	if sm <= s:
		print(0)
	else:
		i = 0
		cnt = 0
		while True:
			cnt += (10 - n % 10) * 10 ** i
			i += 1
			n = n // 10 + 1
			sm = digsum(n)
			if sm <= s:
				print(cnt)
				break


import sys
from math import ceil
input = sys.stdin.readline
t = int(input())

def f(n):
	r = 0
	while n:
		r += n % 10
		n //= 10
	return r
for tc in range(t):
	(n, s) = map(int, input().strip().split())
	if f(n) <= s:
		print(0)
		continue
	b = 1
	ans = int(1e+20)
	while b <= n * 10:
		rn = n // b * b + b
		if f(rn) <= s:
			ans = min(ans, rn - n)
		b *= 10
	print(ans)


t = int(input())
while t > 0:
	(m, n) = map(int, input().split())
	if m < n:
		print(n - m)
	elif m == n:
		print(0)
	elif m % n == 0:
		print(0)
	else:
		x = m // n
		ans = n * (x + 1) - m
		print(ans)
	t = t - 1


from math import ceil
N = int(input())
for i in range(N):
	(a, b) = map(int, input().split())
	print(ceil(a / b) * b - a)


import math
from collections import *
import sys
from functools import reduce
import time
from itertools import groupby

def input():
	return sys.stdin.readline()

def get_ints():
	return map(int, input().strip().split())

def get_list():
	return list(get_ints())

def get_string():
	return list(input().strip().split())

def printxsp(*args):
	return print(*args, end='')

def printsp(*args):
	return print(*args, end=' ')
DIRECTIONS = [(+0, +1), (+0, -1), (+1, +0), (+1, -1)]
NEIGHBOURS = [(-1, -1), (-1, +0), (-1, +1), (+0, -1), (+1, +1), (+1, +0), (+1, -1), (+0, +1)]
CAPS_ALPHABETS = {chr(i + ord('A')): i for i in range(26)}
SMOL_ALPHABETS = {chr(i + ord('a')): i for i in range(26)}
INF = float('inf')
S34t = time.time()
for _testcases_ in range(int(input())):
	(n, k) = get_ints()
	if n % k == 0:
		print(0)
	else:
		print((n // k + 1) * k - n)
S34p = time.time()


t = int(input())
rem = 0
res = 0
a = []
b = []
for i in range(t):
	(x, y) = list(map(int, input().split()))
	a.append(x)
	b.append(y)
for i in range(t):
	if a[i] % b[i] == 0:
		print('0')
	elif a[i] > b[i]:
		rem = a[i] % b[i]
		res = b[i] - rem
		print(res)
	elif a[i] < b[i]:
		res = b[i] - a[i]
		print(res)


l = []
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	new = n
	d = []
	sum = 0
	while 1:
		sum = sum + new % 10
		d.append(new % 10)
		new = new // 10
		if new == 0:
			break
	d = d[::-1]
	if sum <= s:
		l.append(0)
		continue
	if d[0] >= s and sum > s:
		l.append(10 ** len(d) - n)
		continue
	sum = 0
	for i in range(len(d)):
		sum = sum + d[i]
		if sum >= s:
			index = i
			break
	new = n % 10 ** (len(d) - index)
	l.append(10 ** (len(d) - index) - new)
for i in l:
	print(i)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	elif a < b:
		print(b - a)
	else:
		q = a // b
		print(b * (q + 1) - a)


def mod(a, b):
	if a % b == 0:
		return b
	else:
		return a % b
for t in range(int(input())):
	(a, b) = map(int, input().split())
	print(b - mod(a, b))


from math import ceil
for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	print(b * ceil(a / b) - a)


T = int(input())

def f_sum(n):
	s = last = pw = ctr = 0
	fg = False
	while n != 0:
		k = n % 10
		n = n // 10
		if not fg and k != 0:
			last = k
			fg = True
			pw = ctr
		ctr += 1
		s += k
	return [s, last, pw]
arr = []
for _ in range(T):
	(n, s) = list(map(int, input().split()))
	ans = 0
	while True:
		(su, last, pw) = f_sum(n)
		if su <= s:
			break
		number = 10 - last
		number = number * 10 ** pw
		ans = ans + number
		n = n + number
	arr.append(ans)
for i in arr:
	print(i)


t = int(input())
for i in range(t):
	(n, s) = map(int, input().split())
	total = sum(list(map(int, str(n))))
	c = 0
	moves = 0
	while total > s:
		dec = 10 - n % 10
		moves += 10 ** c * dec
		n += dec
		n //= 10
		total = sum(list(map(int, str(n))))
		c += 1
	print(moves)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	n = 0
	if a % b == 0:
		print('0')
	else:
		rem = a % b
		print(b - rem)


import sys
t = int(sys.stdin.readline().split()[0])
for line in sys.stdin:
	a = int(line.split()[0])
	b = int(line.split()[1])
	steps = 0
	if a % b == 0:
		print('0')
	else:
		print(b - a % b)


import os, sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		(n, s) = map(int, input().split())
		xx = n
		n = list(map(int, str(n)))
		n = [0] + n
		x = sum(n)
		if x <= s:
			print(0)
		else:
			i = len(n) - 1
			while i:
				n[i] = 0
				n[i - 1] += 1
				while n[i - 1] == 10:
					n[i - 1] = 0
					n[i - 2] += 1
					i -= 1
				if sum(n) <= s:
					print(int(''.join(map(str, n))) - xx)
					break
				i -= 1
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac
from itertools import permutations as permu

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
num = 1
num = int(z())

def su(n):
	lst = list(map(int, str(n)))
	return sum(lst)
for _ in range(num):
	(n, s) = zz()
	lst = list(map(int, str(n)))
	if sum(lst) <= s:
		print(0)
		continue
	pw = 1
	ans = 0
	for i in range(19):
		digit = n // pw % 10
		add = pw * ((10 - digit) % 10)
		n += add
		ans += add
		if su(n) <= s:
			break
		pw *= 10
	print(ans)


def ans(n, s):
	n = str(n)
	if sum(map(int, n)) <= s:
		return 0
	candidates = set()
	for i in range(1, len(n)):
		(na, nb) = (n[:i], n[i:])
		na = str(int(na) + 1)
		nb = '0' * len(nb)
		if sum(map(int, na)) + sum(map(int, nb)) <= s:
			candidates.add(int(na + nb) - int(n))
	big = '1' + '0' * len(n)
	candidates.add(int(big) - int(n))
	small = '1' + '0' * (len(n) - 1)
	if int(small) - int(n) >= 0:
		candidates.add(int(small) - int(n))
	return min(candidates)

def ans_slow(n, s):
	for i in range(0, 10 ** 200):
		big = n + i
		big = str(big)
		if sum(map(int, big)) <= s:
			return i
import sys
T = int(input())
for t in range(T):
	(n, s) = input().split()
	n = int(n)
	s = int(s)
	print(ans(n, s))


from sys import stdin, stdout

def input():
	a = stdin.readline()
	if a[-1] == '\n':
		a = a[:-1]
	return a

def print(*argv, end='\n', sep=' '):
	n = len(argv)
	for i in range(n):
		if i == n - 1:
			stdout.write(str(argv[i]))
		else:
			stdout.write(str(argv[i]) + sep)
	stdout.write(end)
mod = 10 ** 9 + 7

def lcm(x, y):
	from math import gcd
	return x * y / gcd(x, y)

def comb(lst, x):
	from itertools import combination as c
	return list(comb(lst, x))

def fact(x, mod=mod):
	ans = 1
	for i in range(1, x + 1):
		ans = ans * i % mod
	return ans

def arr2D(n, m, default=0):
	lst = []
	for i in range(n):
		temp = [default] * m
		lst.append(temp)
	return lst

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

def solve(n, x):
	n = str(n)[::-1]
	summ = 0
	for i in n:
		summ += int(i)
	if summ <= x:
		return 0
	else:
		summ1 = 0
		for i in range(len(n)):
			summ1 += int(n[i])
			if summ - summ1 + 1 <= x:
				return int(n[::-1][:len(n) - i - 1] + '9' * (i + 1)) + 1 - int(n[::-1])
	return 'NO'
for _ in range(int(input())):
	(n, x) = list(map(int, input().split()))
	print(solve(n, x))


import math
n = int(input())
for i in range(n):
	(a, b) = [int(x) for x in input().split()]
	a = math.ceil(a / b) * b - a
	print(a)


for _ in range(int(input())):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	rem = a % b
	if rem == 0:
		min_moves = 0
	else:
		min_moves = b - rem
	print(min_moves)


a = int(input())
for x in range(a):
	b = input()
	c = b.split()
	data1 = int(c[0])
	data2 = int(c[1])
	remender = data1 % data2
	if remender == 0:
		print('0')
	else:
		print(data2 - remender)


for _ in range(int(input())):
	l = list(map(int, input().split()))
	(a, b) = (l[0], l[1])
	if a % b == 0:
		print(0)
		continue
	print(b - a % b)


t = int(input())
ans = 0
for i in range(t):
	(a, b) = map(int, input().split())
	ans = a % b
	ans = ans if a + ans % b == 0 or ans == 0 else b - ans
	print(ans)


import sys
from collections import Counter

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
for _ in range(INT()):
	(a, b) = MAP()
	ans = b - a % b if a % b != 0 else 0
	print(ans)


def find(n, s):
	if sum(map(int, list(n))) <= s:
		return 0
	for i in range(len(n)):
		try:
			if 1 + sum(map(int, list(n[i + 1:]))) <= s:
				w = '0' * (i + 1) + str(1 + int(''.join(n[i + 1:][::-1])))[::-1]
				return min(int(w[::-1]) - int(''.join(n[::-1])), int('1' + '0' * len(n)) - int(''.join(n[::-1])))
		except:
			return int('1' + '0' * len(n)) - int(''.join(n[::-1]))
	return int('1' + '0' * len(n)) - int(''.join(n[::-1]))

def main():
	for _ in range(int(input())):
		(n, s) = list(map(int, input().split()))
		n = str(n)[::-1]
		print(find(list(n), s))
main()


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	ans = b - a % b
	if a % b == 0:
		ans = 0
	print(ans)


t = int(input())
for _ in range(t):
	(a, b) = [int(x) for x in input().split()]
	num = a / b
	if num - int(num):
		print((int(num) + 1) * b - a)
	else:
		print(0)


t = int(input())
for i in range(0, t):
	(a, b) = map(int, input().split())
	v = True
	if a % b == 0:
		rs = 0
	else:
		c = a % b
		rs = b - c
		a = a + c
	print(rs)


t = int(input())
for i in range(0, t):
	a = input().split()
	if int(a[0]) % int(a[1]) == 0:
		print(0)
	else:
		answer = int(a[1]) - int(a[0]) % int(a[1])
		print(answer)


def check(n, s):
	sum = 0
	while n:
		sum += n % 10
		n //= 10
	if sum <= s:
		return True
	else:
		return False
t = int(input())
while t:
	(n, s) = input().split(' ')
	n = int(n)
	s = int(s)
	t -= 1
	p = 0
	cnt = 0
	while True:
		if check(n, s):
			break
		num = n % 10
		if num != 0:
			cnt += (10 - num) * 10 ** p
		n //= 10
		if num != 0:
			n += 1
		p += 1
	print(cnt)


for _ in range(int(input())):
	(n, s) = map(int, input().split(' '))
	digits = [int(x) for x in str(n)]
	if sum(digits) <= s:
		print(0)
		continue
	i = 1
	while i < len(digits) and sum(digits[:i]) < s:
		i += 1
	p = 10 ** (len(digits) - i + 1)
	print(p - n % p)


def is_prime(n):
	if n <= 1:
		return False
	for i in range(2, n):
		if n % i == 0:
			return False
	return True

def check_div(a, b):
	if a % b == 0:
		return 0
	if a < b:
		return b - a
	else:
		rest = a // b + 1
		return b * rest - a
cases = int(input())
for _ in range(cases):
	(a, b) = list(map(int, input().split()))
	print(check_div(a, b))


import sys
for t in range(int(sys.stdin.readline().strip())):
	(n, m) = [int(j) for j in sys.stdin.readline().split()]
	ans = (n // m + 1) * m - n
	if ans == m:
		sys.stdout.write('0')
	else:
		sys.stdout.write(str((n // m + 1) * m - n))
	sys.stdout.write('\n')


import math

def solve(a, b):
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)
t = int(input())
for i in range(t):
	data = input().split()
	solve(int(data[0]), int(data[1]))


t = int(input())
for _ in range(t):
	(a, b) = [int(x) for x in input().split()]
	ans = a % b
	if (a + ans) % b == 0:
		print(ans)
	else:
		print(b - ans)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
while t:
	x = inlt()
	a = x[0]
	b = x[1]
	if a % b == 0:
		print(0)
	else:
		c = (a // b + 1) * b - a
		print(c)
	t -= 1


t = int(input())
for i in range(0, t, 1):
	L = list(map(int, input().split()))
	if L[0] % L[1] == 0:
		print(0)
	else:
		print(L[1] - L[0] % L[1])


from collections import *
from sys import *
input = stdin.readline
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	a = []
	while n > 0:
		a.append(n % 10)
		n = n // 10
	cn = 0
	sn = sum(a)
	index = 0
	while sn > s and index < len(a):
		d = (10 - a[index]) % 10
		opn = d * 10 ** index
		a[index] = 0
		c = 0
		if opn > 0:
			c = 1
		itr = index + 1
		while c == 1 and itr < len(a):
			if a[itr] == 9:
				a[itr] = 0
				itr += 1
			else:
				a[itr] += 1
				c = 0
		sn = sum(a)
		cn += opn
		index += 1
	print(cn)


for t in range(int(input())):
	(a, b) = list(map(int, input().split()))
	print((b - a % b) % b)


def divisiblity_check(num1, num2):
	if num1 % num2 == 0:
		print('0')
	else:
		rem = num1 // num2
		ans = (rem + 1) * num2 - num1
		print(ans)

def main():
	test_case = int(input())
	while test_case != 0:
		(a, b) = map(int, input().split(' '))
		divisiblity_check(a, b)
		test_case = test_case - 1
main()


gi = lambda : list(map(int, input().split()))
for _ in range(gi()[0]):
	(a, b) = gi()
	print(b - a % b if a % b else 0)


def turn(a, b):
	if a % b == 0:
		return 0
	else:
		c = a % b
		return b - c
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	print(turn(a, b))


def solve(a, b):
	k = a // b
	if a % b == 0:
		return 0
	return (k + 1) * b - a
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	print(solve(a, b))


from math import modf
for _ in range(int(input())):
	(a, b) = [int(a) for a in input().split()]
	c = 0
	if a % b != 0:
		(f, _) = modf(a / b)
		c = round(b * (1 - f))
	print(c)


t = int(input())
w = []

def func(n):
	n = str(n)
	sum = 0
	for i in range(len(n)):
		sum = sum + int(n[i])
	return sum
for i in range(t):
	(n, s) = input().split()
	n = int(n)
	s = int(s)
	r = str(n)
	k = n
	j = s
	if func(n) <= s:
		w.append(0)
	else:
		i = 0
		while j > 0:
			j = j - int(r[i])
			i = i + 1
		if i == 1:
			w.append(10 ** len(r) - n)
		else:
			g = n - n % 10 ** (len(r) - i + 1)
			g = g + 10 ** (len(r) - i + 1)
			w.append(g - k)
for i in w:
	print(i)


def getSod(n):
	s = 0
	while n > 0:
		s += n % 10
		n = n // 10
	return s
T = int(input())
while T > 0:
	A = [int(x) for x in input().split()]
	(n, s) = (A[0], A[1])
	org_num = n
	ans = -1
	num = 1
	for dig in range(1, 20):
		sod = getSod(n)
		if sod <= s:
			ans = n - org_num
			break
		num = num * 10
		cn = n % num
		diff = num - cn
		n += diff
	print(ans)
	T -= 1


n = int(input())
s = [tuple(map(int, input().split())) for i in range(n)]
for v in s:
	if v[0] % v[1] == 0:
		ans = 0
	else:
		ans = (v[0] // v[1] + 1) * v[1] - v[0]
	print(ans)


def digit_sum_count(n):
	sum_of_digits = 0
	for symbol in n:
		sum_of_digits += int(symbol)
	return sum_of_digits
t = int(input())
for _ in range(t):
	(n, s) = map(int, input().split())
	n = str(n)
	n = '0' + n
	digit_sum = 0
	next_num = ''
	ds = digit_sum_count(n)
	if ds > s:
		for symbol in n:
			if digit_sum + int(symbol) > s - 1:
				digit_sum_bad = True
				break
			else:
				digit_sum += int(symbol)
				next_num += symbol
		next_num_len = len(next_num)
		next_num = str(int(next_num) + 1)
		next_num += '0' * (len(n) - next_num_len)
		print(int(next_num) - int(n))
	else:
		print(0)


def main():
	for _ in range(int(input())):
		(a, b) = list(map(int, input().split()))
		if a % b == 0:
			print('0')
		else:
			s = int(a // b)
			s = s + 1
			b = b * s
			a = b - a
			print(a)
main()


def main():
	for _ in range(int(input())):
		(a, b) = map(int, input().rstrip().split(' '))
		c = 0
		k = a // b
		if a % b == 0:
			print('0')
		else:
			s = b * (k + 1) - a
			print(s)
main()


n = int(input())
for i in range(0, n):
	(a, b) = (int(i) for i in input().split())
	m = a % b
	print((b - m) % b)


t = int(input())
i = 1
count = 0
while i <= t:
	(a, b) = map(int, input().split())
	if a % b == 0:
		print('0\n')
	else:
		print(b - a % b)
	i = i + 1


n = int(input())
s = 0
for i in range(n):
	s = 0
	(m, z) = map(int, input().split())
	if m % z == 0:
		print(0)
	else:
		print((m // z + 1) * z - m)


def run(a, b):
	if a % b == 0:
		return 0
	else:
		return b - a % b
t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	print(run(a, b))


t = int(input())
for i in range(t):
	(a, b) = input().split(' ')
	x = int(a)
	y = int(b)
	if x % y != 0:
		c = x // y
		d = y * (c + 1) - x
		print(d)
	else:
		print(0)


def calc(n, s):
	total = 0
	for i in range(len(n)):
		total += int(n[i])
		if total >= s:
			rem = n[i:len(n)]
			break
	main = '1' + '0' * len(rem)
	return int(main) - int(rem)
for ii in range(int(input())):
	(n, s) = map(int, input().split())
	n = str(n)
	total = 0
	for i in range(len(n)):
		total += int(n[i])
	if total <= s:
		print(0)
	else:
		print(calc(n, s))


import math
from collections import defaultdict, Counter, deque

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def main():
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
		return
	right_side = a + b - (a + b) % b
	print(right_side - a)
	return
t = int(input())
for _ in range(t):
	main()


n = int(input())
for i in range(0, n):
	(n, m) = map(int, input().split())
	if n % m == 0:
		print(0)
	else:
		x = n % m
		ans = m - x
		print(ans)


t = int(input())
for i in range(t):
	result = 0
	line = input().split()
	a = int(line[0])
	b = int(line[1])
	if a % b == 0:
		print(result)
		continue
	elif a < b:
		print(b - a)
		continue
	elif a == b:
		print(0)
		continue
	else:
		k = a
		x = 2 * b - a
		if x > 0:
			print(x)
		else:
			print(f'{b - a % b}')


def check(n):
	cur = 0
	for c in str(n):
		cur += int(c)
	return cur

def main():
	(n, s) = map(int, input().split())
	(a, exp) = (0, 1)
	while check(n) > s:
		d = n % 10
		n += (10 - d) % 10
		a += (10 - d) % 10 * exp
		exp *= 10
		n //= 10
	print(a)
for _ in range(int(input())):
	main()


from sys import stdin
a = int(stdin.readline())
for b in range(0, a):
	c = stdin.readline().split()
	d = int(c[0])
	e = int(c[1])
	count = 0
	print((e - d % e) % e)


ssi = lambda : map(int, input().split())

def sm(n):
	n = str(n)
	res = 0
	for i in range(len(n)):
		res += int(n[i])
	return res
for _ in range(int(input())):
	(n, s) = ssi()
	if sm(n) <= s:
		print(0)
	else:
		res = 0
		i = len(str(n)) - 1
		pw = 1
		while sm(n) > s and i >= 0:
			d = n // pw % 10
			tmp = pw * ((10 - d) % 10)
			n += tmp
			res += tmp
			pw *= 10
			i -= 1
		print(res)


import sys
I = sys.stdin.readline
pr = sys.stdout.write

def main():
	for _ in range(int(I())):
		(a, b) = map(int, I().split())
		pr(f'{(b * (a // b + 1) - a) * bool(a % b)}\n')
main()


a = int(input())
w = list()
for i in range(a):
	b = input().split()
	b1 = int(b[0])
	b2 = int(b[1])
	val = 0
	d = 0
	if b1 % b2 != 0:
		d = int(b1 / b2) + 1
		val = b2 * d - b1
	else:
		val = 0
	w.append(val)
for i in w:
	print(i)


T = int(input())
for t in range(T):
	(n, s) = map(int, input().split())
	str_n = str(n)[::-1]
	tot_sum = 0
	for i in str_n:
		tot_sum += int(i)
	moves = 0
	carry = 0
	if tot_sum <= s:
		print(moves)
	else:
		for i in range(len(str_n)):
			moves += (10 - int(str_n[i]) - carry) * 10 ** i
			carry = 1
			if i == 0:
				tot_sum = tot_sum - int(str_n[i]) + carry
			else:
				tot_sum = tot_sum - int(str_n[i])
			if tot_sum <= s:
				break
		print(moves)


t = int(input())
for kkk in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print('0')
	else:
		k = a // b + 1
		print(b * k - a)


t = int(input())
while t != 0:
	(a, b) = map(int, input().split())
	if a > b:
		if a % b == 0:
			count = 0
		else:
			c = a // b
			d = b * (c + 1)
			count = d - a
	elif a < b:
		count = b - a
	else:
		count = 0
	print(count)
	t = t - 1


def f(a, b):
	if a % b == 0:
		return 0
	t = a // b
	return (t + 1) * b - a
t = int(input())
for i in range(t):
	[a, b] = list(map(int, input().split()))
	print(f(a, b))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(a, b) = [x for x in input().split()]
	b = int(b)
	temp = [int(i) for i in a]
	n = len(a)
	i = n - 1
	curr = sum(temp)
	while curr > b:
		now = temp[i]
		if now == 0 and i != 0:
			i -= 1
		elif curr - now + 1 > b and i != 0:
			curr -= now - 1
			temp[i] = 0
			temp[i - 1] += 1
			i -= 1
		elif i == 0:
			temp[i] = 0
			temp = [1] + temp
			break
		else:
			curr -= now - 1
			temp[i] = 0
			temp[i - 1] += 1
			break
	ans = 0
	for i in temp:
		ans = 10 * ans + i
	print(ans - int(a))


for _ in range(int(input())):
	x = input()
	y = [int(q) for q in x.split()]
	a = y[0]
	b = y[1]
	if a < b:
		print(b - a)
	elif a == b:
		print(0)
	else:
		k = (b - a % b) % b
		print(k)


for i in range(int(input())):
	(n, s) = map(int, input().split())
	(move, power) = (0, 1)
	while sum(map(int, str(n))) > s:
		d = n // power % 10
		add = power * (10 - d)
		n += add
		move += add
		power *= 10
	print(move)


def mai(a, b):
	a = int(a)
	b = int(b)
	temp = 0
	i = int(a / b)
	while temp < a and a % b != 0:
		temp = b
		temp = temp * i
		i = i + 1
	if i == int(a / b):
		print(temp)
	else:
		print(temp - a)
for i in range(int(input())):
	mai(*input().split())


def main():
	for _ in range(int(input())):
		(n, t) = map(int, input().split())
		s = sum(map(int, str(n)))
		ans = 0
		mod = 10
		value = n
		if s <= t:
			print(0)
			continue
		while s > t:
			if n == n // mod:
				ans = 1 * mod
				break
			n = (n // mod + 1) * mod
			s = sum(map(int, str(n)))
			mod *= 10
		if not ans:
			ans = n
		print(ans - value)
main()


def solve():
	(a, b) = map(int, input().split())
	print((b - a % b) % b)
T = int(input())
for t in range(T):
	solve()


def ssum(n):
	csum = 0
	lst = []
	while n != 0:
		(n, r) = divmod(n, 10)
		csum += r
		lst.append(r)
	return (lst, csum)

def solve(n, s, csum, start, steps):
	if csum <= s:
		return steps
	if n[start] == 0:
		return solve(n, s, csum, start + 1, steps)
	steps += (10 - n[start]) * 10 ** start
	csum -= n[start] - 1
	n[start] = 0
	n[start + 1] += 1
	return solve(n, s, csum, start + 1, steps)
t = int(input())
for _ in range(t):
	(n, s) = (int(x) for x in input().split())
	(lst, csum) = ssum(n)
	lst.append(0)
	print(solve(lst, s, csum, 0, 0))


def ans(n, s):
	a = str(n)
	x = len(a)
	summ = 0
	w = x
	for i in range(x):
		j = int(a[i])
		if summ + j < s:
			summ = summ + j
			continue
		else:
			w = i
			break
	if w == x:
		return 0
	b = a[w:]
	for i in range(s - summ + 1):
		if b == str(i) + '0' * (len(b) - 1):
			return 0
	z = len(b)
	ori = 10 ** z
	return ori - int(b)
m = int(input())
for j in range(m):
	arr = input().split()
	n = int(arr[0])
	s = int(arr[1])
	print(ans(n, s))


t = int(input())
while t:
	(n, m) = input().split()
	(n, m) = (int(n), int(m))
	c = 0
	if n % m == 0:
		pass
	else:
		c = m - n % m
	print(c)
	t -= 1


import fileinput
T = input()
T = int(T)
for case in range(0, T):
	(n, s) = map(int, input().split())
	initTot = 0
	for num in str(n):
		initTot += int(num)
	curSeen = 0
	if n != s and initTot > s:
		for (i, digit) in enumerate(str(n)[::-1]):
			if initTot + 1 - (int(digit) + curSeen) <= s:
				res = 10 ** (i + 1) - int(str(n)[-i - 1:])
				print(res)
				break
			curSeen += int(digit)
	else:
		print(0)


n = int(input())
moves = []
for i in range(n):
	(a, b) = map(int, input().split(' '))
	if a % b == 0:
		moves.append(0)
	else:
		moves.append(b - a % b)
for i in moves:
	print(i)


def getSum(n):
	m = str(n)
	summ = 0
	for i in m[::-1]:
		summ += int(i)
	return summ
t = int(input())
for i in range(0, t):
	(n, s) = map(int, input().split())
	i = 0
	ans = 0
	while getSum(n) > s:
		dg = n % 10
		n = n // 10 + 1
		ans += 10 ** i * (10 - dg)
		i += 1
	print(ans)


for i in range(0, int(input())):
	(p, z) = input().split()
	if int(p) % int(z) == 0:
		print(0)
	else:
		print(int(z) - int(p) % int(z))


for i in range(int(input())):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	c = 0
	if a % b != 0:
		c = abs(b - a % b)
	print(c)


def sums(n):
	res = 0
	while n > 0:
		res += n % 10
		n = n // 10
	return res
t = int(input())
while t:
	t -= 1
	(n, s) = map(int, input().split())
	if sums(n) <= s:
		print(0)
		continue
	pw = 1
	ans = 0
	for i in range(18):
		dig = n // pw % 10
		add = pw * ((10 - dig) % 10)
		ans += add
		n += add
		if sums(n) <= s:
			break
		pw *= 10
	print(ans)


import sys
input = sys.stdin.readline

def ch(n):
	su = 0
	for i in str(n):
		su += int(i)
	return su
RES = []
for q in range(int(input())):
	(n, s) = map(int, input().split())
	res = 0
	while 1:
		r = ch(n)
		if r <= s:
			break
		N = str(n)
		c = 0
		for i in range(len(N) - 1, -1, -1):
			if N[i] != '0':
				p = 10 ** c
				req = 10 - int(N[i])
				res += req * p
				n += req * p
				break
			c += 1
	RES.append(res)
print(*RES)


t = int(input())
for hh in range(0, t):
	(a, b) = [int(x) for x in input().split()]
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


t = int(input())
while t > 0:
	s = input().split()
	a = int(s[0])
	b = int(s[1])
	result = 0
	rem = a % b
	if rem != 0:
		result = b - rem
	print(result)
	t = t - 1


n = int(input())
a = []
for i in range(0, n):
	(l, m) = input().split()
	l = int(l)
	m = int(m)
	p = l % m
	if p == 0:
		a.append(0)
	else:
		a.append(m - p)
for i in range(0, n):
	print(a[i])


def makeDiv(a, b):
	if a % b == 0:
		return 0
	if b > a:
		return b - a
	b = a - b + (a - b) % b
	return a - b
tests = []
for _ in range(int(input())):
	tests.append(tuple(map(int, input().split())))
for test in tests:
	print(makeDiv(test[0], test[1]))


import math
from decimal import *
import random

def sm(s):
	ans = 0
	for i in range(len(s)):
		ans += s[i]
	return ans

def fix(arr, pnt):
	if pnt < 0:
		arr = [1] + arr
		return arr
	arr[pnt] += 1
	if arr[pnt] == 10:
		narr = list(arr)
		narr[pnt] = 0
		return fix(narr, pnt - 1)
	else:
		return arr
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = []
	for i in range(len(str(n))):
		arr.append(int(str(n)[i]))
	mult = 0
	ans = 0
	pnt = len(arr) - 1
	while sm(arr) > k:
		if arr[pnt] == 9:
			arr = fix(arr, pnt)
			ans += 10 ** mult
			pnt -= 1
			mult += 1
		else:
			arr[pnt] += 1
			ans += 10 ** mult
	print(ans)


from sys import stdin, stdout
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		c = 0
	else:
		c = b - a % b
	print(c)


from sys import stdin

def get_user_input(n):
	input_list = []
	for i in range(n):
		input_list.append(tuple(map(int, stdin.readline().rstrip().split())))
	return input_list
n = int(input())
input_list = get_user_input(n)
for i in range(n):
	remainder = input_list[i][0] % input_list[i][1]
	if remainder == 0:
		print(0)
	else:
		print(input_list[i][1] - remainder)


def add_list(p):
	total = sum(n1[0:p + 1], 1)
	return total
t = int(input())
for i in range(t):
	(n, s) = map(int, input().split())
	n1 = list(map(int, str(n)))
	count = 0
	n1.insert(0, 0)
	for i2 in range(len(n1)):
		count += n1[i2]
		if count > s:
			break
	if count <= s:
		print(0)
	else:
		for i3 in range(i2 - 1, -1, -1):
			if s >= add_list(i3):
				print((int(str(n1[0:i3 + 1])[1:-1:3]) + 1) * 10 ** (len(n1) - i3 - 1) - n)
				break


l = []
for i in range(int(input())):
	(a, b) = map(int, input().split())
	count = 0
	if a % b == 0:
		l.append(0)
	else:
		x = a % b
		l.append(b - x)
for i in range(len(l)):
	print(l[i])


import math
for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	print((math.floor(a / b + 1) * b - a, 0)[a % b == 0])


t = int(input())
for _ in range(t):
	(n, s) = map(int, input().split())
	st = str(n)
	if sum(map(int, st)) <= s:
		print(0)
	else:
		su = 0
		t = 0
		options = []
		st = '0' + st
		for (i, c) in enumerate(st):
			su += int(c)
			if su >= s:
				break
			else:
				options.append((t * 10 + int(c) + 1) * 10 ** (len(st) - 1 - i))
			t *= 10
			t += int(c)
		print(min(options) - n)


import sys, math
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	mas = []
	while n != 0:
		mas.append(n % 10)
		n //= 10
	if sum(mas) <= s:
		print(0)
	else:
		ans = 0
		c = 0
		while sum(mas) > s:
			if mas[c] != 0:
				if mas[c] == 10:
					mas[c] = 0
					c += 1
					if c == len(mas):
						mas.append(1)
					else:
						mas[c] += 1
				else:
					ans += (10 - mas[c]) * 10 ** c
					mas[c] = 0
					c += 1
					if c == len(mas):
						mas.append(1)
					else:
						mas[c] += 1
			else:
				c += 1
		print(ans)


t = int(input())
for _ in range(t):
	s1 = list(map(int, input().split()))
	temp = s1[0] % s1[1]
	if temp == 0:
		print(temp)
	else:
		print(s1[1] - temp)


n = int(input())
for _ in range(n):
	(a, b) = list(map(int, input().split()))
	result = ((b - a) % b + b) % b
	print(result)


import math
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	print(int(math.ceil(n / k)) * k - n if n > k else k - n)


import math

def div(a, b):
	dv = a / b
	mult = math.ceil(dv)
	obj = mult * b
	return obj - a
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	print(div(a, b))


T = int(input())
for z in range(T):
	(a, b) = map(int, input().split())
	if a % b != 0:
		ans = b * (a // b + 1) - a
		print(ans)
	else:
		print(0)


import sys
readLine = lambda : sys.stdin.readline()
readInt = lambda : int(sys.stdin.readline())
readInts = lambda : [int(x) for x in sys.stdin.readline().split(' ')]

def main():
	t = readInt()
	for _ in range(t):
		(a, b) = readInts()
		if a % b == 0:
			print(0)
		else:
			print(b - a % b)
main()


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	l = []
	while n > 0:
		l.append(n % 10)
		n = n // 10
	ts = sum(l)
	ans = 0
	l1 = []
	c = 0
	f = 0
	if ts <= s:
		print(0)
	else:
		j = 0
		for i in range(len(l)):
			if l[i] == 0:
				l1.append(0)
			else:
				j = i
				break
		for i in range(j, len(l)):
			if l[i] == 0:
				l1.append(9)
				l[i] = 0
				c = 1
			elif l[i] == 9 and c == 1:
				l1.append(0)
				l[i] = 0
				c = 1
			elif l[i] == 9 and c == 0:
				l1.append(1)
				l[i] = 0
				c = 1
			else:
				l1.append(10 - l[i] - c)
				l[i] = 0
				c = 1
			if c + sum(l) <= s:
				break
		i = len(l1) - 1
		while l1[i] == 0:
			l1.pop()
			i -= 1
		for i in range(len(l1) - 1, -1, -1):
			print(l1[i], end='')
		print()


n1 = int(input())
while n1 > 0:
	(x, y) = map(int, input().split())
	count = 0
	pls = 0
	if x % y == 0:
		print(count)
	else:
		z = x // y
		ans = (z + 1) * y
		print(ans - x)
	n1 -= 1


import math
import string
a = int(input())
for i in range(a):
	counter = 0
	b = input().split(' ')
	if int(b[0]) > int(b[1]):
		if int(b[0]) % int(b[1]) == 0:
			c = 0
			print(c)
		else:
			c = int(b[1]) - int(b[0]) % int(b[1])
			print(c)
	else:
		c = int(b[1]) - int(b[0])
		print(c)


t = int(input())
for t in range(t):
	(a, b) = map(int, input().split())
	if a <= b:
		moves = b - a
	else:
		if a % b != 0:
			div = a // b + 1
		else:
			div = a // b
		mult = b * div
		moves = mult - a
	print(moves)


n = int(input())
count = 0
e = []
for i in range(n):
	(k, m) = map(int, input().split())
	if k % m == 0:
		count = 0
	else:
		r = k // m
		count = m * (r + 1) - k
	e.append(count)
for i in range(len(e)):
	print(e[i])


for _ in range(int(input())):
	(n, s) = map(str, input().split())
	s = int(s)
	n = list(n)
	q = 0
	for i in range(len(n)):
		q += int(n[i])
	if q <= s:
		print(0)
	elif int(n[0]) < s:
		a = [n[0]]
		r = int(n[0])
		m = 0
		for i in range(1, len(n)):
			r += int(n[i])
			if r <= s - 1:
				a.append(n[i])
			else:
				a[-1] = str(int(a[-1]) + 1)
				m = i
				break
		for i in range(len(a) - 1, 0, -1):
			if len(a[i]) == 2:
				a[i - 1] = str(int(a[i - 1]) + 1)
				a[i] = '0'
			else:
				break
		for i in range(m, len(n)):
			a.append('0')
		b = ''.join(a)
		c = ''.join(n)
		print(int(b) - int(c))
	else:
		a = ['1']
		for i in range(len(n)):
			a.append('0')
		b = ''.join(a)
		c = ''.join(n)
		print(int(b) - int(c))


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


n = int(input())
while n > 0:
	(a, b) = list(map(int, input().split(' ')))
	if a <= b:
		print(b - a)
	else:
		r = a % b
		if r == 0:
			print(0)
		else:
			print(b - r)
	n = n - 1


def div(a, b):
	if a % b == 0:
		return 0
	else:
		p = a // b
		return b * (p + 1) - a
n = int(input())
for i in range(0, n):
	xy = input().split()
	x = xy[0]
	y = xy[1]
	ans = div(int(x), int(y))
	print(ans)


t = int(input())
for i in range(t):
	l = input()
	l2 = l.split(' ')
	a = int(l2[0])
	b = int(l2[1])
	if a % b == 0:
		print(0)
	else:
		r = a % b
		print(b - r)


q = int(input())
for i in range(q):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
		continue
	t = (a + b - 1) // b
	ans = t * b - a
	print(ans)


import math
n = 0
n = int(input())
index = 0
while index < n:
	a = 0
	b = 0
	(a, b) = input().split(' ')
	a = int(a)
	b = int(b)
	index += 1
	if a <= b:
		print(0)
		continue
	l_a = list(str(a))
	tmp_sum = 0
	for val in l_a:
		tmp_sum += int(val)
	if tmp_sum <= b:
		print(0)
		continue
	start = 0
	sum = 0
	if int(l_a[0]) < int(b):
		while start < len(l_a) and sum + int(l_a[start]) < int(b):
			sum += int(l_a[start])
			start += 1
		if sum > int(b):
			start -= 1
			sum -= int(l_a[start])
	x = int(math.pow(10, len(l_a[start:])))
	if len(l_a[start:]) == 0:
		print(0)
		continue
	y = int(''.join(l_a[start:]))
	print(x - y)


mod = 10 ** 9 + 7
import math
from bisect import bisect_left as bl
from collections import Counter
from itertools import combinations

def ain():
	return map(int, input().split())

def fain():
	return map(float, input().split())

def mc2(s):
	return s * (s - 1) // 2
for _ in range(int(input())):
	(a, b) = ain()
	a = a % b
	if a == 0:
		print(0)
	else:
		print(b - a % b)


import os
import sys
from io import BytesIO, IOBase
import math
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
for _ in range(t):
	(inp, b) = map(int, input().split())
	actual = inp
	a = []
	res = 0
	while inp > 0:
		a.append(inp % 10)
		res += inp % 10
		inp = inp // 10
	a = a[::-1]
	n = len(a)
	a = [0] + a
	yyy = 0
	t = 0
	ll = list()
	for i in range(n):
		ll.append(inp % 10)
	bbb = b
	if res <= b:
		print(0)
	else:
		while yyy < bbb:
			yyy += a[t]
			t += 1
		t -= 2
		a[t] += 1
		newno = 0
		for i in range(t - 1, -1, -1):
			a[i] += a[i + 1] // 10
		i = 0
		n += 1
		while i < n:
			a[i] %= 10
			i += 1
		j = t + 1
		while j < n:
			a[j] = 0
			j += 1
		for _ in a:
			newno = newno * 10 + _
		kiu = 90
		print(newno - actual + 98 - 8 - kiu)


l = []
for i in range(int(input())):
	(a, b) = list(map(int, input().split()))
	if a % b == 0:
		l.append(0)
	else:
		c = abs(a - b * (a // b + 1))
		l.append(c)
for i in l:
	print(i)


n = int(input())
for i in range(n):
	x = [int(y) for y in input().split()]
	y = x[0] // x[1]
	x1 = x[0] % x[1]
	print(x[1] * (y + 1) - x[0] if x1 != 0 else 0)


t = int(input())
from math import *
for i in range(t):
	(a, b) = map(int, input().split(' '))
	k = a
	s = ceil(a / b)
	ans = b * s - a
	print(ans)


n = int(input())
lista = []
for i in range(n):
	(a, b) = [int(q) for q in input().split()]
	x = a % b
	if x == 0:
		lista.append(0)
	else:
		lista.append(b - a % b)
for i in lista:
	print(i)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	l = [x for x in str(n)]
	su = sum([int(x) for x in str(n)])
	ans = 0
	c = 0
	for i in range(len(l)):
		c += int(l[i])
		if c >= s and su > s:
			p = 10 ** (len(l) - i)
			ans = p - int(''.join(l[i:]))
			break
	print(ans)


t = int(input())
while t:
	(n, s) = input().split()
	s = int(s)
	li = list(n)
	(to, p, total) = (0, 0, 0)
	for i in range(len(li)):
		total = total + int(li[i])
	for i in range(len(li)):
		to = to + int(li[i])
		if to >= s:
			p = i + 1
			break
	if total <= int(s):
		t -= 1
		print(0)
		continue
	st = '0' * (len(n) - p + 1)
	st = '1' + st
	n = n[p - 1:]
	print(int(st) - int(n))
	t -= 1


import sys
t = int(sys.stdin.readline())
for i in range(t):
	(a, b) = map(int, sys.stdin.readline().split())
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


t = int(input())
for _ in range(t):
	(n, s) = map(int, input().split())
	n = list(map(int, list(str(n))))
	if sum(n) > s:
		for i in range(1, len(n) + 1):
			if sum(n[:i]) >= s:
				d = i
				break
		if sum(n[:d]) == s and sum(n[d:]) == 0:
			print(0)
		elif sum(n[:d]) == s and sum(n[d:]) != 0:
			print(10 ** len(n[d - 1:]) - int(''.join(list(map(str, n[d - 1:])))))
		elif sum(n[:d]) > s and sum(n[:d - 1]) < s:
			print(10 ** len(n[d - 1:]) - int(''.join(map(str, n[d - 1:]))))
	else:
		print(0)


t = int(input())
solve = 0
for i in range(t):
	(a, b) = input().split()
	if int(a) % int(b) != 0:
		print((int(a) // int(b) + 1) * int(b) - int(a))
	else:
		print(0)


for tc in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	if n % k == 0:
		print(0)
	else:
		print(k - n % k)


t = int(input())
while t > 0:
	t = t - 1
	(a, b) = input().split()
	c = 0
	a = int(a)
	b = int(b)
	if a % b == 0:
		c = 0
	else:
		d = int(a / b)
		c = b * (d + 1) - a
	print(c)


import math
t = int(input())
for tt in range(0, t):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if a % b == 0:
		print(0)
	elif a > b:
		d = math.floor(a / b)
		k = (d + 1) * b
		s = k - a
		print(s)
	elif a < b:
		print(b - a)


def main():
	n = int(input().strip())
	for _ in range(n):
		(a, b) = [int(i) for i in input().strip().split()]
		mod = a % b
		if mod == 0:
			print(0)
		else:
			print(b - mod)
main()


def main():
	t = int(input())
	while t:
		(a, b) = map(int, input().split())
		if a % b == 0:
			print(0)
		else:
			rem = a // b
			print((rem + 1) * b - a)
		t -= 1
main()


def main():
	n = int(input())
	for i in range(n):
		(a, b) = tuple(map(int, input().split()))
		if a % b == 0:
			print(0)
		else:
			print(b - a if b > a else b * (a // b + 1) - a)
main()


for qq in range(int(input())):
	(a, b) = map(int, input().split())
	print((a + b - 1) // b * b - a)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	ncopy = n
	total = 0
	strn = str(n)
	strn = strn[::-1]
	strn = list(map(int, strn))
	strn.append(0)
	for i in range(0, len(strn)):
		total = sum(map(int, str(n)))
		if total <= s:
			break
		else:
			p = 10 - strn[i]
			if p == 10:
				p = 0
			else:
				if i > 0:
					n = n + p * 10 ** i
				else:
					n = n + p
				strn[i + 1] += 1
	print(n - ncopy)


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi
from collections import deque, defaultdict
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7

def dig(x):
	return sum([int(i) for i in str(x)])
for _ in range(I()):
	(n, s) = R()
	sm = 0
	x = 1
	ind = -1
	while dig(n) > s:
		j = (10 - int(str(n)[ind])) * x
		x *= 10
		n += j
		sm += j
		ind -= 1
	print(sm)


import sys
import math
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write

def input():
	return fast_reader().strip()
for T in range(int(input())):
	(n, s) = map(int, input().split())
	sum = 0
	big = 0
	num = str(n)
	same = False
	ind = 0
	for i in range(len(num)):
		sum += int(num[i])
		if sum == s and same == False:
			ind = i
			big = num[i:]
			same = True
		elif sum > s:
			if same == False:
				big = num[i:]
				ind = i
			break
	big = int(big)
	if sum <= s:
		print(0)
	else:
		l = len(num)
		l -= ind
		diffFrom = 10 ** l
		print(diffFrom - big)


t = int(input())
for _ in range(t):
	(a, b, *c) = input().split()
	a = int(a)
	b = int(b)
	j = 0
	if a % b != 0:
		print(b - a % b)
	else:
		print(0)


def addition(x, y):
	print([0, y - x % y][x % y != 0])
t = int(input())
for i in range(t):
	(a, b) = [int(x) for x in input().split()]
	addition(a, b)


n = int(input())
closest_num = []
for i in range(n):
	a = list(map(int, input().split()))
	if a[0] % a[1] != 0:
		q = int(a[0] / a[1])
		closest_num.append(a[1] * (q + 1) - a[0])
	else:
		closest_num.append(0)
print(*closest_num, sep='\n')


T = int(input())
n = [0] * T
m = [0] * T
ns = [0] * T
for t in range(T):
	(n[t], m[t]) = [int(i) for i in input().split(' ')]

def ans(n, m):
	if n < m:
		return m - n
	elif n % m == 0:
		return 0
	else:
		return m - n % m
for t in range(T):
	print(ans(n[t], m[t]))


from math import sqrt
t = int(input())
for case in range(t):
	(a, b) = list(map(int, input().split()))
	ans = b - a % b
	if a % b == 0:
		ans = 0
	print(ans)


import math
n = int(input())
for e in range(n):
	(a, b) = map(int, input().split())
	if a < b:
		print(b - a)
	if a >= b:
		print(b * math.ceil(a / b) - a)


for s in [*open(0)][1:]:
	(n, s) = s.split()
	s = int(s)
	m = '0' + n
	l = len(m)
	i = j = t = 0
	if sum(map(int, n)) > s:
		while i < l and t + int(m[i]) < s:
			j = (j, i)[m[i] < '9']
			t += int(m[i])
			i += 1
		if i < l:
			m = m[:j] + chr(ord(m[j]) + 1) + '0' * (l - j - 1)
	print(int(m) - int(n))


t = int(input())
a = []
b = []
for i in range(t):
	div = input().split()
	div = [int(i) for i in div]
	a.append(div[0])
	b.append(div[1])
i = 0
while i < t:
	print((b[i] - a[i] % b[i]) % b[i])
	i += 1


import math

def getAnswer(a, b):
	if a % b != 0:
		return math.ceil(a / b) * b - a
	else:
		return 0
t = int(input())
while t:
	(x, y) = [int(x) for x in input().split()]
	print(getAnswer(x, y))
	t = t - 1


n = int(input())
a = 0
for _ in range(n):
	(x, y) = map(int, input().split())
	if x % y == 0:
		a = 0
	else:
		a = x % y
		a = y - a
	print(a)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	l = list(map(int, str(n)))[::-1]
	x = sum(l)
	if x <= s:
		print(0)
		continue
	for i in range(1, len(l)):
		if l[i] == 9:
			continue
		t = l.copy()
		t[:i] = [0] * i
		t[i] += 1
		if sum(t) <= s:
			print(int(''.join((str(x) for x in t))[::-1]) - n)
			break
	else:
		print(int('1' + '0' * len(str(n))) - n)


n = int(input())
a = 0
i = 0
b = 0
while i < n:
	(x, y) = map(int, input().split())
	if x % y == 0:
		a = 0
	else:
		b = x % y
		a = y - b
	print(a)
	i = i + 1


t = int(input())

def sm(v):
	return sum([int(i) for i in str(v)])
for it in range(t):
	(n, s) = [int(i) for i in input().split()]
	start = n
	cur = 1
	for i in range(20):
		d = n % cur
		if d != 0:
			n += cur - d
		if sm(n) <= s:
			print(n - start)
			break
		cur *= 10


tc = int(input())
while tc:
	(num_str, n) = input().split()
	n = int(n)
	digSum = sum(map(int, num_str))
	if digSum <= n:
		print(0)
	else:
		tempSum = 0
		for (i, d) in enumerate(num_str):
			if tempSum + int(d) < n:
				tempSum += int(d)
			else:
				break
		print(10 ** len(num_str[i:]) - int(num_str[i:]))
	tc -= 1


t = int(input())
for tt in range(0, t):
	(n, m) = map(int, input().split())
	gv = n // m + 1
	if n % m != 0:
		print(gv * m - n)
	else:
		print(0)


for t in range(int(input())):
	(n, s) = input().split()
	s = int(s)
	nn = ['0', '0', '0'] + list(n)
	su = 0
	for i in n:
		su += int(i)
	ptr = 1
	while su > s:
		su -= int(nn[-ptr])
		su += 1
		nn[-ptr] = '0'
		nn[-ptr - 1] = str(1 + int(nn[-ptr - 1]))
		itr = 1
		while int(nn[-ptr - itr]) >= 10:
			su -= 10
			su += int(nn[-ptr - itr]) // 10
			nn[-ptr - itr - 1] = str(int(nn[-ptr - itr - 1]) + int(nn[-ptr - itr]) // 10)
			nn[-ptr - itr] = str(int(nn[-ptr - 1]) % 10)
			itr += 1
		ptr += 1
	print(int(''.join(nn)) - int(n))


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
tests = inp()
testcount = 0
while testcount < tests:
	arr = inlt()
	a = arr[0]
	b = arr[1]
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)
	testcount += 1


N = int(input())
data = []
for i in range(N):
	data.append(input().split())
	for j in range(2):
		data[i][j] = int(data[i][j])

def res(a):
	x = a[0]
	y = a[1]
	cnt = 0
	if x % y != 0:
		cnt = y - x % y
	else:
		cnt = x % y
	return str(cnt)
for i in range(N):
	print(res(data[i]) + '\n')


n = int(input())
for i in range(n):
	x = list(map(int, input().split()))
	if x[0] % x[1] == 0:
		print('0')
	if x[0] % x[1] != 0:
		k = x[0] // x[1]
		c = x[1] * (k + 1)
		z = c - x[0]
		print(z)


t = int(input())
for _ipj_ in range(t):
	(n, s) = map(int, input().split())
	n = str(n)
	n = [0] + [int(x) for x in list(n)]
	ans = 0
	pow = 1
	if sum(n) <= s:
		print(0)
		continue
	while sum(n) > s:
		if n[-1] == 0:
			n.pop()
			pow = pow * 10
			continue
		ans += (10 - n[-1]) * pow
		n.pop()
		pow *= 10
		for i in range(18):
			if n[-1] != 9:
				n[-1] += 1
				break
			else:
				n.pop()
				pow *= 10
	print(ans)


test = int(input())
for _ in range(test):
	(a, b) = input().split()
	if int(a) % int(b) != 0:
		print(int(b) - int(a) % int(b))
	else:
		print(0)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	st = '0' * (19 - len(str(n))) + str(n)
	sm = 0
	for i in st:
		sm += int(i)
	moves = 0
	if sm <= s:
		print(moves)
		continue
	else:
		diff = sm - s
		st = st[::-1]
		pw = 1
		prof = int(st[0]) - 1
		st_t = st[0]
		moves = 10 - int(st_t)
		pw += 1
		for i in range(1, len(st)):
			if prof >= diff:
				break
			st_t += st[i]
			prof += int(st[i])
			moves = 10 ** pw - int(st_t[::-1])
			pw += 1
		print(moves)


n = int(input())
for _ in range(n):
	(a, b) = map(int, input().split())
	div = a // b + 1
	print((b * div - a) % b)


t = int(input())
for i in range(t):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	moves = (b - a % b) % b
	print('%d' % moves)


t = int(input())
r = []
for i in range(t):
	(a, b) = [int(x) for x in input().split()]
	k = a % b
	e = b - k
	if k == 0:
		r.append(0)
	else:
		r.append(e)
for i in r:
	print(i)


import sys
input = sys.stdin.readline
tot = 0
ops = 0

def safe_add(digits, i):
	global tot, ops
	if not i < len(digits):
		digits.append(i)
		tot += 1
	elif digits[i] == 9:
		digits[i] = 0
		tot -= 9
		safe_add(digits, i + 1)
	else:
		digits[i] += 1
		tot += 1

def nullify(digits, i):
	global tot, ops
	if digits[i] == 0:
		return
	ops += (10 - digits[i]) * 10 ** i
	tot -= digits[i]
	digits[i] = 0
	safe_add(digits, i + 1)
	return

def solve(digits, s):
	global tot, ops
	if tot <= s:
		return
	i = 0
	while tot > s:
		nullify(digits, i)
		i += 1
	return
t = int(input())
for _ in range(t):
	(n, s) = input().rstrip().split()
	digits = [int(d) for d in n[::-1]]
	tot = sum(digits)
	ops = 0
	solve(digits, int(s))
	print(ops)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	if n % m == 0:
		print(0)
	else:
		print(abs(n - (n // m + 1) * m))


n = int(input())
for i in range(n):
	times = 0
	nums = tuple(map(int, input().split()))
	num1 = nums[0]
	num2 = nums[1]
	if num1 % num2 == 0:
		print(0)
	else:
		print(num2 - num1 % num2)


t = int(input())
for i in range(t):
	(n, m) = list(map(int, input().rstrip().split()))
	k = n // m
	if n % m:
		print((k + 1) * m - n)
	else:
		print(0)


t = int(input())
while t:
	(a, b) = [int(i) for i in input().split()]
	t -= 1
	if a % b != 0:
		m = a // b
		print((m + 1) * b - a)
	else:
		print(0)


import math

def divisibilityProblem():
	n = int(input())
	l = []
	for i in range(n):
		values = input().split()
		value1 = int(values[0])
		value2 = int(values[1])
		ans = math.ceil(value1 / value2)
		ans = ans * value2 - value1
		l.append(ans)
	for i in l:
		print(i)
divisibilityProblem()


n = int(input())
a = []
b = []
c = 0
d = 0
for i in range(n):
	a.append([int(j) for j in input().split()])
for i in range(0, n):
	if a[i][0] % a[i][1] == 0:
		b.append(0)
	elif a[i][0] > a[i][1]:
		b.append((a[i][0] // a[i][1] + 1) * a[i][1] - a[i][0])
	else:
		b.append(a[i][1] - a[i][0])
for i in range(len(b)):
	print(b[i])


num = int(input())
i = 0
while i < num:
	(a, b) = map(int, input().split())
	if a < b:
		ans = b - a
	elif a % b == 0:
		ans = 0
	else:
		re = a % b
		ans = b - re
	print(ans)
	i = i + 1


for t in range(int(input())):
	inp = list(map(int, input().split()))
	if inp[0] % inp[1] == 0:
		print(inp[0] % inp[1])
	else:
		print(inp[1] - inp[0] % inp[1])


import math
T = int(input())
for _ in range(T):
	(a, b) = map(int, input().split())
	temp = math.ceil(a / b)
	print(b * temp - a)


def sumofdigits(n):
	n = str(n)
	sum1 = 0
	for i in n:
		sum1 += int(i)
	return sum1

def satisfy(p2, s, n1):
	if sumofdigits(int(p2) + n1) <= s:
		return 1
	else:
		return 0
for i in range(int(input())):
	(n, s) = list(map(int, input().split()))
	n1 = n
	sum1 = sumofdigits(n)
	if sum1 <= s:
		print(0)
	elif s == 1:
		size = len(str(n))
		d = pow(10, size)
		print(d - n1)
	else:
		n1 = str(n)
		sum1 = 1
		for i in range(0, len(n1)):
			sum1 += int(n1[i])
			if sum1 > s:
				f = i
				break
		length = len(n1) - f
		power = pow(10, length)
		lst = n1[f:]
		print(power - int(lst))


from math import ceil
t = int(input())
for x in range(t):
	(a, b) = map(int, input().split())
	c = ceil(a / b) * b
	print(c - a)


def res(a, b):
	temp = a / b
	if int(temp) == temp:
		print(0)
	else:
		x = int(temp) + 1
		y = b * x
		print(y - a)
t = int(input())
for _ in range(t):
	(a, b) = [int(x) for x in input().split()]
	res(a, b)


a = int(input())
for x in range(a):
	(n, k) = map(int, input().split())
	if n % k != 0:
		print(k - n % k)
	else:
		print('0')


for i in range(int(input())):
	(a, b) = map(int, input().split())
	if a < b:
		c = b - a
	elif a == b or a % b == 0:
		c = 0
	elif a > b:
		c = (a // b + 1) * b - a
	print(c)


tests = int(input())
while tests > 0:
	tests -= 1
	(a, b) = list(map(int, input().split()))
	rem = (b - a % b) % b
	print(rem)


from math import ceil
t = int(input())
for _ in range(t):
	(n, s) = map(int, input().split())
	digits = [0] * 20
	n1 = n
	i = 0
	sums = 0
	while n1:
		digits[i] = n1 % 10
		sums += digits[i]
		n1 = n1 // 10
		i += 1
	i = 0
	while sums > s:
		if digits[i]:
			sums = sums - digits[i] + 1
			digits[i] = 0
			digits[i + 1] += 1
		i += 1
	res = 0
	m = 1
	for i in digits:
		res += i * m
		m = m * 10
	print(res - n)


from sys import stdin, stdout
input = stdin.readline
print = lambda x: stdout.write(str(x) + '\n')

def findsum(d):
	sums = 0
	while d:
		sums += d % 10
		d //= 10
	return sums
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	upd = n
	i = len(str(upd)) - 1
	while findsum(upd) > s:
		t = str(upd)
		while i != -1 and t[i] == '0':
			i -= 1
		if i == -1:
			upd = 10 ** len(t)
			break
		upd -= int(t[i]) * 10 ** (len(t) - i - 1)
		upd += 10 ** (len(t) - i)
	print(upd - n)


from math import ceil
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	r = b * ceil(a / b) - a
	print(r)


t = int(input())
for i in range(t):
	ch = input()
	L = [int(i) for i in ch.split()]
	a = L[0]
	b = L[1]
	if b - a % b != b:
		print(b - a % b)
	else:
		print(0)


import sys
t = int(input())
while t > 0:
	t -= 1
	input = sys.stdin.readline()
	(n, s) = map(int, input.split())
	a = []
	x = n
	while x > 0:
		a.append(x % 10)
		x = x // 10
	a.reverse()
	(add, flag) = (0, 0)
	for i in range(len(a)):
		add += a[i]
		if add > s:
			flag = 1
			break
	if flag == 0:
		print(0)
	elif a[0] >= s:
		print(10 ** len(a) - n)
	elif add - a[i] == s:
		while a[i - 1] == 0:
			i -= 1
		num = 0
		for x in range(i - 1):
			num = num * 10 + a[x]
		print((num + 1) * 10 ** (len(a) - i + 1) - n)
	else:
		num = 0
		for x in range(i):
			num = num * 10 + a[x]
		print((num + 1) * 10 ** (len(a) - i) - n)


def f(x, y):
	a = x % y
	if a == 0:
		return 0
	else:
		return y - a
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(f(n, k))


from math import sqrt
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	rem = b - a % b
	if rem == b:
		print(0)
	else:
		print(rem)


def function(a, b):
	total = sum([int(x) for x in list(str(a))])
	counter = 0
	powerof10 = 10
	if total <= b:
		return counter
	else:
		while 1:
			total = sum([int(x) for x in list(str(a))])
			if total <= b:
				return counter
			else:
				tobeadded = powerof10 - a % powerof10
				counter += tobeadded
				a += tobeadded
				powerof10 *= 10
for _ in range(int(input())):
	(N, s) = [int(x) for x in input().split()]
	print(function(N, s))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	k = a // b
	if a % b != 0:
		k += 1
	print(b * k - a)


import sys

def read_int():
	return int(sys.stdin.readline())

def read_ints():
	return map(int, sys.stdin.readline().split(' '))
t = read_int()
for case_num in range(t):
	(n, s) = read_ints()
	a = [0] + [int(i) for i in str(n)]
	ds = sum(a)
	cost = 0
	idx = len(a) - 1
	radix = 1
	while ds > s:
		if a[idx] > 0:
			cost += (10 - a[idx]) * radix
			ds -= a[idx]
			a[idx] = 0
			ds += 1
			a[idx - 1] += 1
			i = idx - 1
			while a[i] >= 10:
				a[i - 1] += 1
				a[i] -= 10
				ds -= 9
				i -= 1
		radix *= 10
		idx -= 1
	print(cost)


t = int(input())
for i in range(t):
	(a, b) = input().split()
	(a, b) = (int(a), int(b))
	if a % b == 0:
		print(0)
	elif a % b == a:
		print(b - a)
	elif a % b < b:
		print(b - a % b)


t = int(input())
rl = []
for i in range(t):
	(a, b) = list(map(int, input().split()))
	rl.append((b - a % b) % b)
[print(r) for r in rl]


for t in range(int(input())):
	(n, s) = map(int, input().split())
	m = n
	ans = n
	d = 0
	while True:
		a = m
		c = 0
		while a > 0:
			c += a % 10
			a //= 10
		if c <= s:
			ans = m * 10 ** d - n
			break
		if m % 10 == 0:
			m //= 10
			d += 1
		else:
			m += 10 - m % 10
	print(ans)


import math
x = int(input(''))
list = []
z = 0
for c in range(x):
	(m, n) = map(int, input().split())
	if m / n == int(m / n):
		list.append(z)
	elif m < n:
		z = n - m
		list.append(z)
	elif m > n:
		k = m / n
		z = math.ceil(k) * n - m
		list.append(z)
	z = 0
print(*list, sep='\n')


t = int(input())
for i in range(t):
	(a, b) = [int(j) for j in input().split()]
	if a % b == 0:
		print('0')
	else:
		print(str((a // b + 1) * b - a))


t = int(input())
for i in range(0, t):
	(a, b) = [int(x) for x in input().split()]
	if a % b == 0:
		n = 0
	else:
		r = a % b
		n = b - r
	print(n)


for s in [*open(0)][1:]:
	(n, s) = s.split()
	s = int(s)
	m = '0' + n
	l = len(m)
	i = j = t = 0
	if sum(map(int, n)) > s:
		for x in m:
			t += int(x)
			if t >= s:
				m = m[:j] + chr(ord(m[j]) + 1) + '0' * (l - j - 1)
				break
			j = (j, i)[m[i] < '9']
			i += 1
	print(int(m) - int(n))


import sys

def set_debug(debug_mode=False):
	if debug_mode:
		fin = open('input.txt', 'r')
		fout = open('output.txt', 'w')
		sys.stdin = fin
		sys.stdout = fout
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	mod = a % b
	if mod == 0:
		print(mod)
	else:
		print(b - mod)


for t in range(int(input())):
	(n, m) = map(int, input().split())
	k = n
	j = n % m
	if j == 0:
		print(0)
	else:
		print(m - j)


t = int(input())
for i in range(t):
	(a, b) = list(map(int, input().split(' ')))
	integer = a // b
	left = a % b
	if left == 0:
		print(0)
	else:
		result = b - left
		print(result)


t = int(input())
ans = []
for i in range(t):
	arr = input().split()
	(a, b) = (int(arr[0]), int(arr[1]))
	if a > b:
		if not a % b:
			ans.append(0)
		else:
			ans.append(b * (a // b + 1) - a)
	else:
		ans.append(b - a)
for i in ans:
	print(i)


def func(a, b):
	if a % b == 0:
		return 0
	else:
		y = a % b
		x = b - y
		return x
n = int(input())
for i in range(n):
	l = [int(i) for i in input().split()]
	print(func(l[0], l[1]))


def digit_sum(st):
	ans = 0
	for i in st:
		ans += int(i)
	return ans
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	o = n
	plus = 10
	while digit_sum(str(n)) > s:
		n = n - n % plus
		n += plus
		plus = plus * 10
	print(n - o)


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())
for _ in range(int(input())):
	(a, b) = get_ints()
	if a % b == 0:
		print(0)
	else:
		print((int(a / b) + 1) * b - a)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	string = str(n)
	l = len(string)
	tot = 0
	for j in string:
		tot += int(j)
	if tot <= s:
		print(0)
		continue
	cnt = 0
	tens = ''
	summ = 0
	i = 0
	while i < l and summ + int(string[i]) < s:
		tens += string[i]
		summ += int(string[i])
		cnt += 1
		i += 1
	if tens == '':
		tens = '0'
	tens = str(int(tens) + 1)
	tens += (l - cnt) * '0'
	print(int(tens) - n)


def sumOf(N):
	s = 0
	while N > 0:
		dig = N % 10
		s += dig
		N = N // 10
	return s
T = int(input())
for t in range(T):
	(N, S) = list(map(int, input().split()))
	if sumOf(N) <= S:
		print('0')
	else:
		(ans, pos) = (0, 1)
		for i in range(18):
			dig = N // pos % 10
			add = pos * (10 - dig)
			N = N + add
			ans += add
			if sumOf(N) <= S:
				break
			pos *= 10
		print(ans)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	ans = 0
	while a % b != 0:
		if b > a:
			diff = b - a
			a += diff
			ans += diff
		else:
			mul = a // b + 1
			c = b * mul
			diff = c - a
			a += diff
			ans += diff
	print(ans)


def func(x):
	y = list(str(x))
	s = 0
	for i in y:
		s += int(i)
	return s
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	n = str(n)
	if func(int(n)) <= s:
		print(0)
	elif int(n[0]) > s:
		ans = '1' + '0' * len(n)
		print(int(ans) - int(n))
	else:
		i = 0
		sum = 0
		while i < len(n):
			sum += int(n[i])
			if sum >= s:
				break
			else:
				i += 1
		s1 = '0' * (len(n) - (i + 1))
		k = int(n[:i + 1])
		k += 1
		i = 0
		while func(k) > s:
			k += 1
		k = str(k)
		ans = int(k + s1)
		print(ans - int(n))


def sumChar(n):
	s = 0
	while n:
		s += n % 10
		n //= 10
	return s
n = int(input())
for i in range(n):
	(a, b) = [int(k) for k in input().split()]
	if sumChar(a) <= b:
		print(0)
		continue
	resp = 0
	casaDec = 1
	for j in range(18):
		cortaDigito = a // casaDec % 10
		adicionar = (10 - cortaDigito) % 10 * casaDec
		a += adicionar
		resp += adicionar
		if sumChar(a) <= b:
			break
		casaDec *= 10
	print(resp)


def main():
	answers = []
	for i in range(int(input())):
		(a, b) = map(int, input().split())
		c = a % b
		if c != 0:
			c = abs(c - b)
		answers.append(c)
	for i in range(len(answers)):
		print(answers[i])
main()


def sum(n):
	d = 0
	for i in list(str(n)):
		d += int(i)
	return d
for i in range(int(input())):
	(n, s) = map(int, input().split())
	ans = []
	while sum(n) > s:
		ans.insert(0, str((10 - n % 10) % 10))
		n = n // 10 + (1 if n % 10 else 0)
	if len(ans) == 0:
		print(0)
		continue
	print(''.join(ans))


def f(n):
	r = 0
	while n:
		r += n % 10
		n //= 10
	return r

def solve():
	(n, s) = (int(x) for x in input().split())
	orig = n
	mod = 10
	while f(n) > s:
		while n % mod == 0:
			mod *= 10
		n += mod - n % mod
	print(n - orig)
t = int(input())
for _ in range(t):
	solve()


from collections import deque

def get_digits(n):
	digits = deque()
	while n > 0:
		digits.append(n % 10)
		n //= 10
	return digits
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	digits = get_digits(n)
	s1 = sum(digits)
	if s1 <= s:
		print(0)
		continue
	count = 0
	c = 0
	mult = 1
	while len(digits) > 0 and s1 > s:
		digit = digits[0] + c
		digits.popleft()
		c = 0
		if digit == 10:
			s1 -= 9
			c = 1
		elif digit != 0:
			count += mult * (10 - digit)
			s1 -= digit
			s1 += 1
			c = 1
		mult *= 10
	print(count)


import math
for i in range(int(input())):
	(a, b) = map(int, input().split())
	X = math.ceil(a / b)
	A = a / b
	if X == A:
		print(0)
	else:
		print(b * X - a)


n = int(input())
for i in range(n):
	x = input().split()
	c = 0
	a = int(x[0])
	b = int(x[1])
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


for _ in range(int(input())):
	(n, su) = map(int, input().split())
	s = str(n)
	summ = 0
	ss = []
	for i in range(len(s)):
		summ += int(s[i])
	if summ <= su:
		print(0)
	else:
		summ = 0
		for i in range(len(s)):
			if int(s[i]) + summ < su:
				summ += int(s[i])
				ss.append(s[i])
			else:
				for j in range(i, len(s)):
					ss += ['0']
				ch = i - 1
				while ch > -1 and ss[ch] == '9':
					ss[ch] = '0'
					ch -= 1
				if ch == -1:
					ss = ['1'] + ss
				else:
					ss[ch] = str(int(ss[ch]) + 1)
				ans = ''
				for q in range(len(ss)):
					ans += ss[q]
				print(int(ans) - n)
				break


import math
inputt = int(input())
chuoi1 = []
chuoi2 = []
dem = []
for i in range(0, inputt):
	(a, b) = input().split()
	chuoi1.append(a)
	chuoi2.append(b)
	c = int(chuoi1[i])
	d = int(chuoi2[i])
	e = math.ceil(c / d)
	f = e * d - c
	dem.append(f)
for v in dem:
	print(int(v), end='\n')


def operation(pairNum):
	(n, s) = pairNum
	s = int(s)
	k = 0
	allDigits = list(n)
	revDigits = allDigits[::-1]
	revDigits = list(map(int, revDigits))
	revDigits.append(0)
	i = 0
	while i <= len(revDigits) - 2 and sum(revDigits) > s:
		if revDigits[i] == 10:
			revDigits[i] = 0
			revDigits[i + 1] += 1
		else:
			k += (10 - revDigits[i]) * 10 ** i
			revDigits[i] = 0
			revDigits[i + 1] += 1
		i += 1
	return k
t = int(input())
listResults = []
for i in range(t):
	pairNum = input().split()
	result = operation(pairNum)
	listResults.append(result)
for i in listResults:
	print(i)


num_tests = input()
num_tests = int(num_tests)

def divisible_move(var1, var2):
	cnt = 1
	mod = var1 % var2
	if mod == 0:
		return 0
	else:
		return var2 - mod
for i in range(num_tests):
	(var1, var2) = input().split(' ')
	var1 = int(var1)
	var2 = int(var2)
	answer = divisible_move(var1, var2)
	print(answer)


import sys
import string
input = sys.stdin.readline
tc = int(input())
for _ in range(tc):
	(a, b) = map(int, input().split())
	c = (a // b + (1 if a % b != 0 else 0)) * b
	print(c - a)


def sol(x, y):
	c = 0
	if x % y == 0:
		return c
	elif x > y:
		c = y * (x // y + 1) - x
		return c
	else:
		c = y - x
		return c
for i in range(int(input())):
	(a, b) = [int(x) for x in input().split(' ')]
	print(sol(a, b))


import math
t = int(input())
for i in range(t):
	(a, b) = input().split(' ')
	a = int(a)
	b = int(b)
	if a % b == 0:
		print(0)
	else:
		print(b * math.ceil(a / b) - a)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	print(((a - 1) // b + 1) * b - a)


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print('0')
	else:
		s = a // b
		res = (s + 1) * b
		diff = res - a
		print(diff)


def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())

def solve():
	(A, B) = getInts()
	return -A % B
T = getInt()
for t in range(T):
	ans = solve()
	print(ans)


import math
n = int(input())
c = []
a = []
b = []
for i in range(n):
	(x, y) = map(int, input().split())
	a.append(x)
	b.append(y)
for i in range(n):
	x = a[i] % b[i]
	if x == 0:
		c.append(x)
	else:
		z = math.ceil(a[i] / b[i]) * b[i] - a[i]
		c.append(z)
for i in c:
	print(i)


def sumOfDigit(n):
	list_of_number = list(map(int, str(n).strip()))
	return sum(list_of_number)
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	temp = n
	modulo = 10
	while sumOfDigit(temp) > s:
		temp = n // modulo * modulo
		temp += modulo
		modulo *= 10
	print(temp - n)


def solve(a, b):
	check = b
	if check == a:
		return 0
	if a > check:
		div = int(a / b)
		while a > check:
			check = b * div
			div += 1
		return check - a
	if a < check:
		return check - a
Q = int(input())
for _ in range(Q):
	(a, b) = map(int, input().split())
	ans = solve(a, b)
	print(ans)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a <= b:
		x = b - a
	elif a % b == 0:
		x = 0
	else:
		x = b - a % b
	print(int(x))


from sys import stdin
input()
results = []
for line in stdin:
	(a, b) = map(int, line.split())
	if a % b:
		results.append(f'{-a % b}')
	else:
		results.append('0')
print('\n'.join(results))


t = int(input())
for i in range(t):
	a = list(map(int, input().strip().split()))
	if a[0] % a[1] == 0:
		print(0)
	else:
		print(a[1] - a[0] % a[1])


t = int(input())
for i in range(t):
	T = 0
	(n, b) = [str(x) for x in input().split()]
	s = int(b)
	if len(n) == 1:
		if int(n) > s:
			print(10 - int(n))
		else:
			print(0)
		continue
	sm = 0
	f = 0
	k = 0
	for j in range(len(n)):
		sm += int(n[j])
		k = j
		if sm >= s:
			break
	for j in range(len(n)):
		f += int(n[j])
	if f <= s:
		print(0)
		continue
	moves = 0
	stri = ''
	if k == 0:
		moves = 1
		for j in range(len(n)):
			moves *= 10
		print(moves - int(n))
	else:
		for j in range(len(n)):
			if j == k - 1:
				stri += str(1)
			elif j >= k:
				stri += str(0)
		print(int(stri) - int(n[k:]))


t = int(input())
for i in range(t):
	(a, b) = [int(x) for x in input().split()]
	mod = a % b
	if mod == 0:
		print(0)
	else:
		ans = (a // b + 1) * b - a
		print(ans)


t = int(input())
counter = 0
for k in range(t):
	(a, b) = map(int, input().split())
	print((b - a % b) % b)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	l = list(str(n))
	p = len(l)
	su = 0
	for ele in l:
		su += int(ele)
	if su <= s:
		print(0)
	else:
		i = 0
		q = 0
		while i < p and q < s:
			q += int(l[i])
			i += 1
		ne = 10 ** (p - i + 1)
		b = str(n)[i - 1:]
		b = int(b)
		print(ne - b)


from sys import stdin

def sum_digits(n):
	return sum([int(i) for i in str(n)])
for _ in range(int(input())):
	(n, k) = map(int, stdin.readline().rstrip().split(' '))
	c_n = n
	if sum_digits(n) <= k:
		print(0)
	else:
		i = 1
		while True:
			c_n = c_n // 10 ** i * 10 ** i + 10 ** i
			i += 1
			if sum_digits(c_n) <= k:
				break
		print(c_n - n)


def main():
	answer = ''
	for _ in range(int(input())):
		(a, b) = list(map(int, input().split(' ')))
		if a % b == 0:
			answer += '0 \n'
		else:
			a = a % b
			answer += str(b - a) + '\n'
	print(answer)
main()


import os
import io
import sys
from collections import Counter, defaultdict
import math
import random
import heapq as hq
from functools import reduce, cmp_to_key
from collections import deque
import threading
import bisect

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
for _ in range(iinput()):
	(a, b) = rinput()
	print(int(math.ceil(a / b)) * b - a)


def cnt(x):
	ret = 0
	while x > 0:
		ret += x % 10
		x //= 10
	return ret
t = int(input())
for _ in range(t):
	(s, a) = map(int, input().split())
	if cnt(s) <= a:
		print(0)
		continue
	for i in range(19):
		cur = (s // 10 ** i + 1) * 10 ** i
		if cnt(cur) <= a:
			print(cur - s)
			break


def main():
	import sys
	input = sys.stdin.readline
	t = int(input())
	for _ in range(t):
		(a, b) = map(int, input().split())
		print(((a - 1) // b + 1) * b - a)
main()


for i in range(int(input())):
	(a, b) = list(map(int, input().split()))
	if a % b != 0:
		next = a // b + 1
		print(next * b - a)
	else:
		print(0)


def iin():
	return int(input())

def lin():
	return list(map(int, input().split()))

def main():
	t = iin()
	while t:
		t -= 1
		(n, s) = input().split()
		s = int(s)
		n = list(map(int, n))
		sm = sum(n)
		ans = 0
		n = n[::-1]
		ch = 0
		pv = 0
		ln = len(n)
		pw = 0
		while sm > s:
			if pw >= ln:
				break
			val = n[pw]
			if val == 0:
				pw += 1
				continue
			ans += (10 - val if val else 0) * pow(10, pw)
			n[pw] = 0
			pv = 1
			for j in range(pw + 1, ln):
				if n[j] == 9:
					n[j] = 0
				else:
					n[j] += 1
					break
			else:
				n.append(1)
				ln += 1
			sm = sum(n)
			pw += 1
		print(ans)
main()


t = int(input())
for _ in range(t):
	(s, n) = map(str, input().split())
	n = int(n)
	m = len(s)
	pos = -1
	temp = 0
	tt = 0
	for i in range(0, m):
		tt += ord(s[i]) - ord('0')
	if tt <= n:
		print(0)
		continue
	for i in range(0, m):
		ch = ord(s[i]) - ord('0')
		if temp + ch < n:
			temp += ch
		else:
			pos = i
			break
	ans = ''
	flag = True
	for i in range(m - 1, pos - 1, -1):
		if flag:
			ans += chr((ord('9') - ord(s[i]) + 1) % 10 + ord('0'))
		else:
			ans += chr(ord('9') - ord(s[i]) + ord('0'))
		if s[i] != '0':
			flag = False
	finans = ''
	flag = False
	for i in range(len(ans) - 1, -1, -1):
		if ans[i] != '0':
			flag = True
		if flag:
			finans += ans[i]
	print(finans)


t = input()
for i in range(int(t)):
	n = input()
	listn = n.split()
	a = int(listn[0])
	b = int(listn[1])
	mod1 = a % b
	if mod1 == 0:
		c = 0
	else:
		c = b - a % b
	print(c)


import math
t = int(input())
for _i in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


n = int(input())
while n > 0:
	n -= 1
	r = list(map(int, input().split()))
	res = r[1] - r[0] % r[1] if r[0] % r[1] != 0 else 0
	print(res)


def main():
	t = int(input())
	for __ in range(t):
		(a, b) = map(int, input().split())
		if a % b == 0:
			print(0)
		elif a <= b:
			print(b - a)
		else:
			c = a // b + 1
			print(c * b - a)
main()


t = int(input())
ans = []

def solve():
	cnt = 0
	(a, b) = map(int, input().split())
	if a % b != 0:
		return (a // b + 1) * b - a
	else:
		return 0
for i in range(t):
	ans.append(solve())
for i in range(t):
	print(ans[i])


n = int(input())
while n:
	(a, b) = map(int, input().split(' '))
	print((b - a % b) % b)
	n -= 1


for _ in range(int(input())):
	(m, n) = map(int, input().split())
	k = m % n
	p = abs(n - k)
	if k:
		print(n - k)
	else:
		print(0)


def dsum(k):
	s = 0
	while k > 0:
		s += k % 10
		k //= 10
	return s
t = int(input())
for _ in range(t):
	(n, s) = [int(i) for i in input().split()]
	if dsum(n) <= s:
		print(0)
		continue
	moves = 0
	d = 0
	while dsum(n) > s:
		d += 1
		e = 10 ** d
		if n % e:
			new_n = n + e - n % e
			moves += new_n - n
			n = new_n
	print(moves)


def su(n):
	s = 0
	while n:
		rem = n % 10
		n = n // 10
		s += rem
	return s
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	pow = 1
	move = 0
	add = 0
	while su(n) > s:
		last = n // pow % 10
		add = pow * (10 - last)
		move += add
		n += add
		pow *= 10
	print(move)


from math import ceil
from collections import deque

def sm(n):
	ret = 0
	while n > 0:
		ret += n % 10
		n //= 10
	return ret
for _ in range(int(input())):
	(n, s) = [int(i) for i in input().split()]
	temp = n
	while sm(n) > s:
		j = 10
		while n % j == 0:
			j *= 10
		n += j - n % j
	print(n - temp)


import math
import sys
Z = sys.stdin.readline

def check(n):
	s1 = str(n)
	sm = 0
	for i in s1:
		sm += int(i)
	return sm
for _ in range(int(Z())):
	(n, s) = map(int, input().split())
	n1 = n
	i = 0
	while check(n) > s:
		i += 1
		k = int(math.pow(10, i)) - n % int(math.pow(10, i))
		n += k
	print(n - n1)


def get_result(a, b):
	c = a % b
	if c == 0:
		print(0)
	else:
		print(b - c)
t = int(input())
for i in range(t):
	(a, b) = input().split()
	(a, b) = (int(a), int(b))
	get_result(a, b)


def divisble(a, b):
	if a % b == 0:
		result = 0
	else:
		result = b - a % b
	return result
testcase = int(input())
for i in range(testcase):
	(a, b) = map(int, input().rstrip().split())
	print(divisble(a, b))


tests = int(input())
for i in range(tests):
	(a, b) = map(int, input().split())
	ans = b - a % b
	if ans == b:
		print(0)
	else:
		print(ans)


t = int(input())
while t > 0:
	t -= 1
	(n, x) = map(int, input().split())
	c = 0
	if n % x == 0:
		print(0)
	elif n < x:
		print(x - n)
	else:
		k = x - n % x
		print(k)


t = int(input())
for _ in range(t):
	(n, max_sum) = map(int, input().split())
	s = str(n)
	if sum(map(int, s)) <= max_sum:
		print(0)
	else:
		sm = 0
		i = 0
		while i < len(s) and sm + int(s[i]) < max_sum:
			sm += int(s[i])
			i += 1
		next = 0
		for j in range(i):
			next = 10 * next + int(s[j])
		next += 1
		next *= 10 ** (len(s) - i)
		print(next - n)


q = int(input())
for i in range(q):
	c = list(map(int, input().split(' ')))
	a = c[0]
	b = c[1]
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


T = int(input())
ans = []
while T:
	(n, d) = input().split()
	n = int(n)
	d = int(d)
	if n % d == 0:
		ans.append(0)
	else:
		k = d - n % d
		ans.append(k)
	T -= 1
for i in ans:
	print(i)


import sys, os
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
from io import BytesIO, IOBase

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var) + '\n')

def su(n):
	out = 0
	for i in str(n):
		out += int(i)
	return out
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	op = 0
	if su(n) <= s:
		print(op)
	else:
		while su(n) > s:
			x = list(str(n))
			x.reverse()
			i = 0
			while x[i] == '0':
				i += 1
			op += 10 ** i * (10 - int(x[i]))
			n += 10 ** i * (10 - int(x[i]))
		out(op)


for i in range(int(input())):
	(n, s) = map(int, input().split())
	l1 = list(str(n))
	sum = 0
	j = 0
	final = []
	if n == s:
		print(0)
		continue
	current_sum = 0
	for k in range(len(l1)):
		current_sum = current_sum + int(l1[k])
	if current_sum <= s:
		print(0)
		continue
	while sum < s:
		sum = sum + int(l1[j])
		if sum >= s:
			final = l1[j:len(l1)]
		j += 1
	a = '1' + '0' * len(final)
	a = int(a)
	final = ''.join(final)
	print(a - int(final))


import sys
import math
input = sys.stdin.readline
from collections import deque
from queue import LifoQueue
for _ in range(int(input())):
	(n, s) = input().split()
	s = int(s)
	su = 0
	sco = []
	sco1 = []
	for i in n:
		su += int(i)
	if su <= s:
		print(0)
	else:
		a = 0
		for i in range(len(n)):
			sco.append((10 - int(n[-i - 1])) * 10 ** i)
			sco1.append(10 ** (i + 1) - int(n[-i - 1:]))
		for i in range(len(sco)):
			pp = str(int(n) + sco[i])
			pps = str(int(n) + sco1[i])
			suma = 0
			for j in pp:
				suma += int(j)
			cum = 0
			for j in pps:
				cum += int(j)
			if min(suma, cum) <= s:
				if suma <= cum:
					print(sco[i])
					break
				else:
					print(sco1[i])
					break


t = int(input())
for i in range(t):
	(a, b) = [int(item) for item in input().strip().split()]
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


for t in range(int(input())):
	(n, s) = map(int, input().split())
	dif = sum(map(int, str(n))) - s
	if dif <= 0:
		print(0)
		continue
	n2 = n
	sm = 0
	k = 0
	while sm - 1 < dif:
		sm += n % 10
		n //= 10
		k += 1
	k = 10 ** k
	print(k - n2 % k)


n = int(input())
r = 0
for i in range(n):
	(a, b) = list(map(int, input().split()))
	if a % b == 0:
		print(0)
	else:
		r = a % b
		print(b - r)


exec(int(input()) * 'a,b=map(int,input().split());print((b-a%b)%b);')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for j in range(int(input())):
	(n, s) = map(int, input().split())
	arr = [int(k) for k in str(n)]
	length = len(arr)
	cursum = sum(arr)
	cur = 0
	found = False
	ans = []
	if cursum <= s:
		print(0)
	else:
		for i in range(length - 1, -1, -1):
			if arr[i] != 9:
				temp = cursum + 1 - cur
				if temp <= s:
					found = True
					for b in range(length):
						if b < i:
							ans.append(arr[b])
						elif b == i:
							ans.append(arr[b] + 1)
						else:
							ans.append(0)
					break
			cur += arr[i]
		if found == True:
			num2 = ''.join([str(k) for k in ans])
			print(int(num2) - n)
		else:
			print(10 ** length - n)


k = int(input())
j = []
for i in range(k):
	n = list(map(int, input().split()))
	x = n[0] % n[1]
	j.append(n[1] - x if x != 0 else x)
print('\n'.join((str(q) for q in j)))


numbers_of_test_cases = int(input())
numbers = list()
for i in range(numbers_of_test_cases):
	(a, b) = map(int, input().split())
	if a > b:
		if a % b != 0:
			numbers.append(b - a % b)
		else:
			numbers.append(0)
	else:
		numbers.append(b - a)
for move in numbers:
	print(move)


tc = int(input())
for ii in range(tc):
	(a, b) = map(int, input().split())
	x = a // b
	if a % b == 0:
		ans = 0
	else:
		x += 1
		ans = x * b - a
	print(ans)


from math import ceil
for i in range(int(input())):
	(a, b) = map(int, input().split())
	n = ceil(a / (b * 1.0))
	print(n * b - a)


for x in range(int(input())):
	(a, b) = map(int, input().split())
	t = a % b
	if t:
		k = a // b
		m = (k + 1) * b
		f = m - a
		print(f)
	else:
		print(0)


n = int(input())
langs = {'po': 'FILIPINO', 'desu': 'JAPANESE', 'masu': 'JAPANESE', 'mnida': 'KOREAN'}
res = []
for i in range(n):
	(a, b) = list(map(lambda x: int(x), input().split()))
	dif = a / b
	if dif > int(dif):
		dif = int(dif) + 1
	res.append(b * int(dif) - a)
for w in res:
	print(w)


import math
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	c = n
	cus = 0
	f = n
	while c > 0:
		cus += c % 10
		c = c // 10
	if cus <= s:
		print(0)
	else:
		ans = 0
		cu = cus
		i = 0
		while f > 0:
			ans += (10 - n) % 10 * 10 ** i
			n += (10 - n) % 10
			cu = 0
			n = n // 10
			mm = n
			while mm > 0:
				cu += mm % 10
				mm //= 10
			f = f // 10
			i += 1
			if cu <= s:
				print(ans)
				break


from sys import stdin
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def lsi():
	x = list(stdin.readline())
	x.pop()
	return x

def si():
	return stdin.readline()
res = ['YES', 'NO']
for _ in range(ii()):
	(a, b) = mi()
	print(b - a % b if a % b else a % b)


import sys
T = int(input())
for _ in range(T):
	(n, s) = map(int, input().split())
	v = str(n)
	A = []
	cs = 0
	for i in range(len(v)):
		cs = cs + int(v[i])
		A.append(cs + 1)
	ans = int('1' + '0' * len(v)) - n
	for i in range(len(v)):
		if A[i] > s:
			if i > 0:
				st = v[:i - 1] + str(int(v[i - 1])) + '0' * (len(v) - i)
				vv = int(st)
				val = pow(10, len(v) - i)
				rv = val - vv % val
				st = vv + rv
				ans = st - n
			break
	sv = 0
	for i in range(len(v)):
		sv = sv + int(v[i])
	if sv <= s:
		ans = 0
	print(ans)


for i in range(int(input())):
	p = tuple(map(int, input().split(' ')))
	a = p[0]
	b = p[1]
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


s = int(input())
for i in range(s):
	(i, j) = map(int, input().split())
	if i < j:
		k = j - i
		print(k)
	else:
		m = i % j
		if m == 0:
			print(0)
		else:
			h = j - m
			print(h)


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	inp = stdin.readline().split()
	(a, b) = (int(inp[0]), int(inp[1]))
	cnt = 0
	if not a % b:
		print(cnt)
		continue
	print(abs(a % b - b))


def main():
	t = int(input())
	for tc in range(t):
		(a, b) = map(int, input().split())
		if a % b == 0:
			print(0)
		else:
			print((int(a / b) + 1) * b - a)
main()


ar = []
for i in range(int(input())):
	(a, b) = map(int, input().split())
	q = 0
	if a % b == 0:
		ar.append(0)
		continue
	a = a % b
	q = b - a
	ar.append(q)
for i in ar:
	print(i)


n = int(input())
for i in range(n):
	m = input().split()
	a = int(m[0])
	b = int(m[1])
	if a % b != 0:
		r = b - a % b
		print(r)
	else:
		print(0)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	rem = a % b
	print((b - rem) % b)


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


t = int(input())
for i in range(t):
	(n, k) = map(str, input().split())
	k = int(k)
	j = 0
	s = 0
	l = len(n)
	while j < l and s + int(n[j]) < k:
		s = s + int(n[j])
		j = j + 1
	if j == l:
		print(0)
	else:
		q = 0
		for v in n:
			q = q + int(v)
		if q == k:
			print(0)
		else:
			p = 10 ** (l - j)
			q = int(n[j:])
			print(p - q)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	n_str = str(n)
	total = 0
	k = -1
	for (i, d) in enumerate(n_str):
		total += int(d)
		if k == -1 and total >= s:
			k = i
	if total <= s:
		print(0)
	else:
		if k == 0:
			new_n = int('1' + '0' * len(n_str))
		else:
			new_n = int(n_str[:k] + '0' * (len(n_str) - k)) + int('1' + '0' * (len(n_str) - k))
		print(new_n - n)


import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda : sys.stdin.buffer.readline().rstrip()
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	k = []
	while n >= 10:
		k.append(n % 10)
		n //= 10
	k.append(n)
	k += [0, 0, 0]
	l = [0] * len(k)
	q = sum(k)
	if q <= s:
		print(0)
	else:
		i = 0
		while q > s and i < len(k):
			if k[i] < 1:
				i += 1
				continue
			l[i] += 10 - k[i]
			k[i + 1] += 1
			k[i] = 0
			if k[i + 1] > 9:
				k[i + 1] -= 10
				k[i + 2] += 1
			q = sum(k)
			i += 1
		r = 0
		for i in range(len(l)):
			r += l[i] * 10 ** i
		print(r)


t = int(input())
for _ in range(t):
	(n, s) = list(map(int, input().split()))
	original = n
	n = '0' + str(n)
	n = list(map(int, n))
	su = 0
	for i in range(0, len(n)):
		su += int(n[i])
	i = len(n) - 1
	while i >= 0 and su > s:
		if n[i] == 0:
			i -= 1
			continue
		su -= n[i]
		n[i] = 0
		i -= 1
		while i >= 0 and n[i] == 9:
			su -= n[i]
			n[i] = 0
			i -= 1
		n[i] += 1
		su += 1
	n = int(''.join([str(x) for x in n]))
	print(n - original)


n = int(input())
b = []
for i in range(n):
	(a, c) = map(int, input().split())
	if a % c != 0:
		b.append(c - a % c)
	else:
		b.append(0)
for i in range(len(b)):
	print(b[i])


def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = mpos(sum_so_far, current_sum)
	return sum_so_far

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum

def graph(n, m):
	adj = dict()
	for i in range(1, n + 1):
		adj.setdefault(i, 0)
	for i in range(m):
		(a, b) = map(int, input().split())
		adj[a] += 1
		adj[b] += 1
	return adj
import sys
import threading
from math import *
sys.setrecursionlimit(300000)
threading.stack_size(10 ** 8)
po = int(log(10 ** 18)) + 2
li = []
for i in range(po):
	li.append(3 ** i)
li = li[::-1]
s = sum(li)
for _ in range(int(input())):
	(n, s) = input().split()
	s = int(s)
	a = list(n)
	a = [int(x) for x in a]
	a.insert(0, 0)

	def check(li, s):
		currsum = 0
		for i in range(len(li)):
			currsum += li[i]
			if currsum > s:
				return i
		return -1
	if check(a, s) == -1:
		print(0)
	else:
		while check(a, s) != -1:
			ind = check(a, s)
			a[ind - 1] += 1
			a = a[:ind] + [0] * (len(a) - ind)
		num = 0
		for i in a:
			num = num * 10 + i
		print(num - int(n))


t = int(input())
for i in range(t):
	(a, b) = [int(x) for x in input().split()]
	if a % b == 0:
		print(0)
		continue
	print((a // b + 1) * b - a)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	if n % m == 0:
		print(0)
	else:
		q = n // m
		rem = m * (q + 1) - n
		print(int(rem))


for _ in range(int(input())):
	(n, s) = input().split()
	s = int(s)
	c = 0
	for i in n:
		c += int(i)
	if c <= s:
		print(0)
	else:
		t = len(n)
		temp = 0
		for i in range(t):
			temp += int(n[i])
			if temp < s:
				continue
			else:
				new = n[i:]
				print(10 ** len(new) - int(new))
				break


import math
t = int(input())
for _ in range(t):
	[x, y] = [int(i) for i in input().split(' ')]
	if x % y == 0:
		print(0)
	else:
		print(y - x % y)


t = int(input())
for _ in range(t):
	(n, s) = map(int, input().split())
	n = '{0:019d}'.format(n)
	if sum([int(x) for x in n]) <= s:
		print(0)
		continue
	cnt = 0
	for (i, x) in enumerate(n):
		if cnt + int(x) + 1 <= s:
			cnt += int(x)
		else:
			break
	print((int(n[i - 1]) + 1) * 10 ** (19 - i) - int(n[i - 1:]))


l = []
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	if n % m == 0:
		print(0)
	else:
		a = (n // m + 1) * m
		print(a - n)


t = int(input())
for _ in range(t):
	moves = 0
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		c = (a // b + 1) * b
		print(c - a)


def digits(n):
	r = []
	while n > 0:
		r.append(n % 10)
		n = n // 10
	return r

def sumArray(d):
	r = 0
	for i in range(len(d)):
		r += d[i]
	return r
T = int(input())
for t in range(T):
	st = input().split()
	n = int(st[0])
	s = int(st[1])
	d = digits(n)
	i = 0
	m = 1
	op = 0
	sA = sumArray(d)
	while sA > s:
		if d[i] == 10:
			d[i] = 0
			sA -= 10
			if i + 1 < len(d):
				d[i + 1] += 1
			else:
				d.append(1)
			sA += 1
		elif d[i] > 0:
			d[i] += 1
			sA += 1
			op += 1 * m
		else:
			i += 1
			m *= 10
	print(op)


def ssum(s):
	return sum(map(int, list(s)))
for _ in range(int(input())):
	(n, s) = list(map(int, input().split()))
	ns = str(n)
	if ssum(ns) <= s:
		print(0)
		continue
	ans = float('inf')
	for i in range(0, len(ns)):
		x = 1
		if i > 0:
			x = int(ns[:i]) + 1
		acc = 0
		while x > 0:
			acc += x % 10
			x //= 10
		if acc > s:
			continue
		y = 10 ** (len(ns) - i) - int(ns[i:])
		ans = min(ans, y)
	print(ans)


n = int(input())
testCases = []
for x in range(n):
	testCases.append([int(x) for x in input().split()])
for x in testCases:
	moves = 0
	if x[0] % x[1] != 0:
		moves = x[1] - x[0] % x[1]
	print(moves)


import math
T = int(input())
for test in range(T):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print('0')
	else:
		(i, r) = divmod(a, b)
		if r > 0:
			i += 1
		print(abs(b * i - a))


t = int(input())
for i in range(t):
	(a, b) = list(map(int, input().split()))
	ans = b - a % b
	if ans == b:
		ans = 0
	print(ans)


from sys import stdin, stdout

def INPUT():
	return list((int(i) for i in stdin.readline().split()))

def inp():
	return stdin.readline()

def out(x):
	return stdout.write(x)
import math
import random
J = int(1000000000.0) + 7
P = 200003

def sum(n):
	a = 0
	while n:
		a += n % 10
		n //= 10
	return a

def calc(n, s):
	if sum(n) <= s:
		return 0
	t = n
	p = 1
	while sum(n) > s:
		d = n // p % 10
		add = (10 - d) * p
		n += add
		p *= 10
	return n - t
for _ in range(int(input())):
	(n, s) = INPUT()
	print(calc(n, s))


n = int(input())
l = []
for i in range(n):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if a % b == 0:
		l.append(0)
	else:
		k = a // b
		k = k + 1
		c = b * k
		d = c - a
		l.append(d)
for i in l:
	print(i)


import sys, bisect, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
rep = range
R = range

def Golf():
	(n, *t) = map(int, open(0).read().split())

def I():
	return int(input())

def S_():
	return input()

def IS():
	return input().split()

def LS():
	return [i for i in input().split()]

def MI():
	return map(int, input().split())

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def NLI(n):
	return [[int(i) for i in input().split()] for i in range(n)]

def NLI_(n):
	return [[int(i) - 1 for i in input().split()] for i in range(n)]

def StoLI():
	return [ord(i) - 97 for i in input()]

def ItoS(n):
	return chr(n + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def RA():
	return map(int, open(0).read().split())

def RLI(n=8, a=1, b=10):
	return [random.randint(a, b) for i in range(n)]

def RI(a=1, b=10):
	return random.randint(a, b)

def Rtest(T):
	(case, err) = (0, 0)
	for i in range(T):
		inp = INP()
		(a1, ls) = naive(*inp)
		a2 = solve(*inp)
		if a1 != a2:
			print((a1, a2), inp)
			err += 1
		case += 1
	print('Tested', case, 'case with', err, 'errors')

def GI(V, E, ls=None, Directed=False, index=1):
	org_inp = []
	g = [[] for i in range(V)]
	FromStdin = True if ls == None else False
	for i in range(E):
		if FromStdin:
			inp = LI()
			org_inp.append(inp)
		else:
			inp = ls[i]
		if len(inp) == 2:
			(a, b) = inp
			c = 1
		else:
			(a, b, c) = inp
		if index == 1:
			a -= 1
			b -= 1
		aa = (a, c)
		bb = (b, c)
		g[a].append(bb)
		if not Directed:
			g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}, boundary=1):
	mp = [boundary] * (w + 2)
	found = {}
	for i in R(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [boundary] + [mp_def[j] for j in s] + [boundary]
	mp += [boundary] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def accum(ls):
	rt = [0]
	for i in ls:
		rt += [rt[-1] + i]
	return rt

def bit_combination(n, base=2):
	rt = []
	for tb in R(base ** n):
		s = [tb // base ** bt % base for bt in R(n)]
		rt += [s]
	return rt

def gcd(x, y):
	if y == 0:
		return x
	if x % y == 0:
		return y
	while x % y != 0:
		(x, y) = (y, x % y)
	return y

def YN(x):
	print(['NO', 'YES'][x])

def Yn(x):
	print(['No', 'Yes'][x])

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
mo = 10 ** 9 + 7
inf = float('inf')
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('WENS', FourNb))
cursol = dict(zip('LRUD', FourNb))
l_alp = string.ascii_lowercase
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda : sys.stdin.readline().rstrip()
show_flg = False
show_flg = True
ans = 0

def keta(x):
	return sum([int(i) for i in str(x)])

def solve(x, s):
	y = str(x)
	d = len(str(x))
	if keta(x) <= s:
		return 0
	D = 1
	for i in range(1, d + 1):
		D *= 10
		if y[-i] == '0':
			continue
		a = x + D - int(y[-i:])
		if keta(a) <= s:
			return D - int(y[-i:])
for _ in range(I()):
	print(solve(*LI()))


mod = 10 ** 9 + 7

def readInt():
	return int(input())

def readIntList():
	return list(map(int, input().split()))

def readStringList():
	return list(input())

def readStringListWithSpace():
	return list(input().split())

def readString():
	return input()

def getNumSum(n):
	res = 0
	while n > 0:
		res += n % 10
		n //= 10
	return res
t = readInt()
for _ in range(t):
	(n, s) = readIntList()
	if getNumSum(n) <= s:
		print(0)
		continue
	(ans, pw) = (0, 1)
	for i in range(19):
		dig = n // pw % 10
		temp = pw * ((10 - dig) % 10)
		n += temp
		ans += temp
		if getNumSum(n) <= s:
			print(int(ans))
			break
		pw *= 10


t = int(input())
tab = []
for x in range(t):
	moves = 0
	(a, b) = map(int, input().split())
	if a % b == 0:
		tab.append(0)
	elif a < b:
		tab.append(b - a)
	elif a > b:
		tab.append(b - a % b)
for each in tab:
	print(each)


t = int(input())
for i in range(t):
	(a, b) = [int(i) for i in input().split()]
	ans = max(0, b - a)
	a += ans
	if a % b == 0:
		print(ans)
		continue
	ans += b - a % b
	print(ans)


for i in range(int(input())):
	(n, s) = map(int, input().split())
	n = str(n)
	sum = 0
	for j in range(len(n)):
		sum += int(n[j])
	if sum <= s:
		print(0)
		continue
	result = ''
	for j in range(len(n))[::-1]:
		sum -= int(n[j])
		result += str(9 - int(n[j]))
		if sum < s:
			break
	print(int(result[::-1]) + 1)


import math
for t in range(int(input())):
	(a, b) = tuple(map(int, input().split()))
	print(math.ceil(a / b) * b - a)


def correct(arr, t):
	while arr[t] > 9 and t >= 0:
		arr[t - 1] += 1
		arr[t] = 0
		t -= 1
	return t

def calc(arr, t, ts, s):
	for i in range(t, len(arr)):
		arr[i] = 0
	arr[t - 1] += 1
	arr[t] = 0
	t -= 1
	t = correct(arr, t)
	ts = sum(arr)
	while ts > s:
		arr[t - 1] += 1
		arr[t] = 0
		t -= 1
		t = correct(arr, t)
		ts = sum(arr)
for _ in range(int(input())):
	(n, s) = input().split()
	n1 = int(n)
	s = int(s)
	l = 0
	ts = 0
	arr = [0] * 18 + [int(n[i]) for i in range(len(n))]
	while l != 18 + len(n):
		ts += arr[l]
		if ts > s:
			calc(arr, l, ts, s)
			break
		l += 1
	start = 0
	for i in range(len(arr)):
		if arr[i] > 0:
			start = i
			break
	t = 0
	ans = 0
	for j in range(len(arr) - 1, start - 1, -1):
		ans += arr[j] * pow(10, t)
		t += 1
	print(ans - n1)


t = int(input())
ans = []
for Num in range(t):
	ab = input()
	a = int(ab.split(' ')[0])
	b = int(ab.split(' ')[1])
	if a % b == 0:
		ans.append(0)
	else:
		ans.append(b - a % b)
for Num in range(t):
	print(ans[Num])


def func(n, k):
	if n % k != 0:
		return k - n % k
	return 0
q = int(input())
for i in range(q):
	(x, y) = list(map(int, input().split()))
	print(func(x, y))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	count = 0
	if a % b != 0:
		r = int(a / b)
		x = r + 1
		c = b * x
		c = c - a
		print(c)
	else:
		print('0')


for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	k = a // b
	r = a % b
	if r != 0:
		print((k + 1) * b - a)
	else:
		print(0)


test_case = int(input())
while test_case:
	(a, b) = map(int, input().split())
	print(0 if not a % b else b - a % b)
	test_case -= 1


T = int(input())
for _ in range(T):
	(n, m) = map(int, input().split())
	p = n % m
	if p == 0:
		print(0)
	else:
		print(m - p)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		c = a // b
		ans = b * (c + 1) - a
		print(ans)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	a1 = a
	d = 10
	while sum(map(int, str(a))) > b:
		a = (a // d + 1) * d
		d = d * 10
	print(a - a1)


from sys import stdin, stdout
import math as m
rl = lambda : stdin.readline()
rll = lambda : stdin.readline().split()

def main():
	t = int(rl())
	for _ in range(t):
		moves = 0
		(a, b) = (int(x) for x in rll())
		if a <= b:
			stdout.write(str(b - a))
			stdout.write('\n')
		else:
			x = a // b * b
			if x < a:
				moves = b + a // b * b - a
			stdout.write(str(moves))
			stdout.write('\n')
	stdout.close()
main()


n = int(input())
for i in range(0, n):
	(a, b) = [int(x) for x in input().split()]
	if a < b:
		print(b - a)
	elif a % b != 0:
		print(b - a % b)
	else:
		print(0)


n = int(input())
while n:
	(x, y) = input().split()
	x = int(x)
	y = int(y)
	if x % y == 0:
		print('0')
	else:
		print(y - x % y)
	n -= 1


import math as m
t = int(input())
while t:
	t = t - 1
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if a < b:
		print(b - a)
	else:
		x = a / b
		print(m.ceil(x) * b - a)


import math
t = int(input())
for i in range(t):
	nums = [int(x) for x in input().split()]
	q = math.ceil(nums[0] / nums[1])
	print(q * nums[1] - nums[0])


def go():
	(a, b) = map(int, input().split())
	if a % b == 0:
		return 0
	else:
		return b - a % b
t = int(input())
ans = []
for _ in range(t):
	ans.append(str(go()))
print('\n'.join(ans))


try:
	t = int(input())
	for _ in range(t):
		(a, b) = map(int, input().split())
		if a % b == 0:
			ans = 0
		else:
			ans = b - a % b
		print(ans)
except:
	pass


n = int(input())
while n:
	n -= 1
	(a, b) = input().split()
	(a, b) = (int(a), int(b))
	k = a // b
	if a % b == 0:
		print(0)
	else:
		print(b * (k + 1) - a)


t = int(input())
for i in range(t):
	(a, b) = [int(x) for x in input().split()]
	if a % b == 0:
		print(0)
	else:
		d = a % b
		print(b - d)


def div(l):
	a = 0
	b = l[0]
	if l[0] % l[1] == 0:
		a = 0
	else:
		a = l[1] - l[0] % l[1]
	print(a)
t = int(input())
while t > 0:
	l = list(map(int, input().split()))
	div(l)
	t = t - 1


t = int(input())
l = list()
while t > 0:
	t = t - 1
	(a, b) = map(int, input().split())
	if a > b:
		if a % b != 0:
			c = a // b
			c += 1
			d = c * b - a
			l.append(d)
		else:
			d = 0
			l.append(d)
	else:
		c = b - a
		l.append(c)
for x in range(len(l)):
	print(l[x])


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	(a, b) = map(int, input().split())
	ans = b - a % b
	if a % b == 0:
		ans = 0
	stdout.write(str(ans) + '\n')


T = int(input())
for i in range(T):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		num = b - a
		print(num % b)


def divisibility(a, b):
	if a % b == 0:
		return 0
	else:
		return b * (a // b + 1) - a

def test():
	number_of_tests = int(input())
	for i in range(number_of_tests):
		ab = input().split(' ')
		a = int(ab[0])
		b = int(ab[1])
		output = str(divisibility(a, b))
		print(output)
	return ()
test()


for _ in range(int(input())):
	cost = 0
	p = 0
	(num, s) = list(map(int, input().split()))
	num1 = num
	nummap = [int(x) for x in str(num)]
	while True:
		if sum(nummap) < s + 1:
			break
		else:
			p += 1
			k = nummap[-p]
			cost += 10 ** p - k * 10 ** (p - 1)
			num1 = num + cost
			nummap = [int(x) for x in str(num1)]
	print(cost)


from math import log10
t = int(input())
for _ in range(t):
	(n, s) = map(int, input().split())
	d = int(log10(n) // 1 + 1)
	arr = []
	val = 0
	for i in range(d):
		arr.append(n % 10)
		val += n % 10
		n //= 10
	moves = 0
	arr.append(0)
	for i in range(d):
		if val <= s:
			break
		if arr[i] > 0:
			moves += (10 - arr[i]) % 10 * 10 ** i
			val -= arr[i] - 1
			arr[i] = 0
			arr[i + 1] += 1
	print(moves)


tc = int(input())
for i in range(tc):
	(a, b) = map(int, input().split())
	if a > b and a % b != 0:
		c = a % b
		print(b - c)
	elif b >= a:
		print(b - a)
	else:
		print(a % b)


import sys
t = int(input())
Counter = 0
while Counter < t:
	word = input().split()
	a = int(word[0])
	b = int(word[1])
	diff = a % b
	if diff == 0:
		print(0)
	else:
		print(b - diff)
	Counter += 1


t = int(input())
for i in range(t):
	(n, s) = map(int, input().strip().split(' '))
	n = str(n)
	n1 = int(n)
	l = len(n)
	c = 0
	s1 = 0
	for j in range(l):
		s1 += int(n[j])
		if s1 < s:
			c += 1
	if s1 <= s:
		print('0')
	else:
		l -= c
		k = 10 ** l - n1 % 10 ** l
		print(k)


t = int(input())
while t > 0:
	t -= 1
	(a, b) = [int(i) for i in input().split(' ')]
	print((b - (a - b) % b) % b)


n = int(input())
for _ in range(n):
	a = input().split(' ')
	aa = 0
	x = int(a[0])
	y = int(a[1])
	if x % y == 0:
		print(aa)
	elif x < y:
		print(y - x)
	elif x > y:
		print(y - x % y)


t = int(input())
res = [0 for i in range(t)]
for i in range(t):
	(a, b) = map(int, input().split())
	if a % b != 0:
		c = a % b
		res[i] += b - c
print(*res, sep='\n')


t = int(input())
bl = []
for i in range(t):
	tempo = input()
	bl.append(tempo)

def sdigits(n):
	sum = 0
	for i in n:
		sum += int(i)
	return sum
for i in range(t):
	s1 = bl[i]
	s1 = s1.split()
	n = s1[0]
	s = int(s1[1])
	if sdigits(n) <= s:
		print(0)
	else:
		temp = 0
		ix = 0
		for i in range(len(n)):
			temp += int(n[i])
			if temp >= s:
				ix = i
				break
		if ix > 0:
			fin = str(int(n[:ix]) + 1)
		else:
			fin = '1'
		rem = len(n) - ix
		fin += '0' * rem
		fin = int(fin)
		fin = fin - int(n)
		print(fin)


def solve():
	(A, B) = [int(s) for s in input().split()]
	return -A % B
T = int(input())
for t in range(T):
	ans = solve()
	print(ans)


def digits_sum(n):
	s = 0
	while n > 0:
		s += n % 10
		n //= 10
	return s

def main():
	t = int(input())
	for _ in range(t):
		(n, s) = map(int, input().split())
		sm = digits_sum(n)
		ops = 0
		mul = 1
		while sm > s:
			last = n % 10
			if last != 0:
				n += 10 - last
				sm = digits_sum(n)
				ops += (10 - last) * mul
			n //= 10
			mul *= 10
		print(ops)
main()


def ssum(n):
	res = 0
	while n > 0:
		res += n % 10
		n = n // 10
	return res
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	pw = 1
	ans = 0
	if ssum(n) <= s:
		print(0)
		continue
	for i in range(18):
		r = n // pw % 10
		digit = (10 - r) % 10 * pw
		n += digit
		ans += digit
		if ssum(n) <= s:
			break
		pw *= 10
	print(ans)


import sys, math, heapq, collections, itertools, bisect
sys.setrecursionlimit(101000)

def solve(n, s):
	(nn, n, s) = (int(n), list(map(int, n)), int(s))
	steps = 0
	while True:
		cs = 0
		i = 0
		while i < len(n):
			if cs + n[i] <= s:
				cs += n[i]
			else:
				break
			i += 1
		if i == len(n):
			break
		for j in range(i, len(n)):
			n[j] = 0
		carry = 1
		for j in range(i - 1, -1, -1):
			n[j] += carry
			if n[j] == 10:
				n[j] = 0
				carry = 1
			else:
				carry = 0
		if carry == 1:
			n = [1] + n
	return int(''.join(map(str, n))) - nn
t = int(input())
for _ in range(t):
	(n, s) = input().split()
	print(solve(n, s))


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	print((y - x % y) % y)


def solve():
	(n, s) = [int(x) for x in input().split(' ')]
	(t, c) = (list(str(n)), 0)
	lt = len(t)
	for (k, v) in enumerate(t):
		c += int(v)
		if c >= s:
			if (k == lt - 1 or int(''.join(t[k + 1:])) == 0) and c == s:
				return 0
			else:
				return int('1' + '0' * (lt - k)) - int(''.join(t[k:]))
	return 0
t = int(input())
for i in range(t):
	print(solve())


from math import ceil
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	k = ceil(a / b)
	print(b * k - a)


t = int(input())
numbers = []
count = []
for i in range(t):
	numbers.append(list(map(int, input().split())))
	count.append(0)
for i in range(len(numbers)):
	a = numbers[i][0]
	b = numbers[i][1]
	if a % b != 0:
		count[i] = (a // b + 1) * b - a
	else:
		count[i] = 0
for c in count:
	print(c)


for i in range(int(input())):
	(x, y) = [int(z) for z in input().split()]
	print(-x % y)


tests = int(input())
for t in range(tests):
	(a, b) = list(map(int, input().split()))
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


def sumOfDigits(n):
	ans = 0
	while n:
		ans += n % 10
		n = n // 10
	return ans
for i in range(int(input())):
	(n, s) = map(int, input().split())
	steps = 0
	p = 10
	while sumOfDigits(n) > s:
		steps += p - n % p
		n += p - n % p
		p *= 10
	print(steps)


q = int(input())
for rwer in range(q):
	(a, b) = map(int, input().split())
	print((b - a % b) * (a % b != 0))


import math
t = int(input())
for _ in range(t):
	(n, s) = [int(i) for i in input().split()]
	n1 = str(n)
	ans = math.inf
	count = 0
	a1 = 0
	for i in range(len(n1)):
		a1 += int(n1[i])
	if a1 <= s:
		print(0)
	else:
		for i in range(len(n1)):
			if count + int(n1[i]) >= s:
				if count + int(n1[i]) > s:
					if i == 0:
						temp = int(str(10) + '0' * len(n1[i + 1:]))
						ans = min(ans, temp - n)
						count += int(n1[i])
					else:
						break
				if count + int(n1[i]) == s:
					t1 = 0
					for j in range(i + 1, len(n1)):
						t1 += int(n1[j])
					if t1 == 0:
						if i == 0:
							ans = 0
						break
					else:
						if i == 0:
							temp = int(str(10) + '0' * len(n1[i + 1:]))
							ans = min(ans, temp - n)
							count += int(n1[i])
						break
			elif count + int(n1[i]) < s:
				temp = int(n1[:i] + str(int(n1[i]) + 1) + '0' * len(n1[i + 1:]))
				ans = min(ans, temp - n)
				count += int(n1[i])
		print(ans)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions
from collections import deque, defaultdict, OrderedDict
from fractions import Fraction
from decimal import Decimal

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')

	def sod(n):
		r = 0
		while n > 0:
			r += n % 10
			n //= 10
		return r
	for _ in range(ri()):
		(n, s) = ria()
		ans = 0
		if sod(n) <= s:
			print(0)
		else:
			for i in range(18):
				digit = n // 10 ** i % 10
				add = 10 ** i * (10 - digit)
				n += add
				ans += add
				if sod(n) <= s:
					break
			print(ans)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


for case in range(int(input())):
	(n, s) = [int(x) for x in input().split()]
	cur = [int(x) for x in str(n)]
	cur.insert(0, 0)
	ans = int(1e+19)
	temp = [x for x in cur]
	if sum(temp) <= s:
		print(0)
		continue
	for i in range(len(cur) - 1, 0, -1):
		if temp[i] == 0:
			continue
		temp[i] = 0
		j = i - 1
		while temp[j] == 9:
			temp[j] = 0
			j -= 1
		temp[j] += 1
		if sum(temp) <= s:
			temp2 = [str(x) for x in temp]
			print(int(''.join(temp2)) - n)
			break


t = int(input())
for i in range(t):
	a = list(map(int, input().split()))
	b = a[0]
	c = a[1]
	r = 0
	if b < c:
		print(c - b)
		continue
	if b == c:
		print(0)
		continue
	if b % c == 0:
		print(0)
		continue
	r = b % c
	r = c - r
	print(r)


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	print((x - n % x) % x)


def digit_sum(x):
	ref = x
	total = 0
	while x > 0:
		total += x % 10
		x = x // 10
	return total
count = int(input())
for i in range(count):
	jump = 0
	(a, b) = map(int, input().split())
	copy = a
	while digit_sum(copy + 1) > b:
		copy //= 10
		jump += 1
	print(10 ** jump - a % 10 ** jump if digit_sum(a) > b else 0)


t = int(input())
for _ in range(t):
	(n, s) = input().split()
	s = int(s)
	n = int(n)

	def check(n):
		res = 0
		for i in str(n):
			i = int(i)
			res += i
		return res
	ans = 0
	if check(n) <= s:
		print(ans)
	else:
		ans = 0
		pow = 1
		for i in range(len(str(n))):
			dig = n // pow % 10
			ad = pow * ((10 - dig) % 10)
			n += ad
			ans += ad
			if check(n) <= s:
				break
			pow *= 10
		print(ans)


num = int(input())
for i in range(num):
	t = 1
	(a, b) = map(int, input().split())
	k = a
	t2 = 0
	s = str(a)
	for i in s:
		t2 += int(i) - int('0')
	while t <= 10 ** 18:
		if t > 1:
			a += t - a % t
		t2 = 0
		s = str(a)
		for i in s:
			t2 += int(i) - int('0')
		if t2 <= b:
			print(a - k)
			break
		t *= 10


import math
t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	if a > b:
		x = math.ceil(a / b)
		z = x * b - a
	else:
		z = b - a
	print(z)


T = int(input())
for _ in range(T):
	(n, s) = list(map(int, input().split()))
	a = list(map(int, str(n)))
	a = a[::-1]
	if sum(a) <= s:
		print(0)
		continue
	ans = 0
	i = 0
	n = len(a)
	while sum(a) > s and i < n:
		ans += (10 - a[i]) * 10 ** i
		a[i] = 0
		if i + 1 >= n:
			a.append(0)
		a[i + 1] = a[i + 1] + 1
		i += 1
	print(ans)


for _ in range(int(input())):
	l = [int(x) for x in input().split()]
	(a, b) = (l[0], l[1])
	if a < b:
		print(b - a)
	elif a % b == 0:
		print('0')
	else:
		print((a // b + 1) * b - a)


for y in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


from bisect import bisect_right as br
from bisect import bisect_left as bl
import sys, threading
sys.setrecursionlimit(10 ** 6)
scan = lambda : map(int, input().split())

def su(n):
	return sum(list(map(int, str(n))))
for _ in range(int(input())):
	(n, m) = scan()
	s = su(n)
	if s <= m:
		print(0)
	else:
		c = 1
		a = n
		while su(n) > m:
			c *= 10
			n //= 10
			n += 1
		print(n * c - a)


cases = int(input())
for case in range(cases):
	(x, y) = input().split()
	x = int(x)
	y = int(y)
	d = x % y
	if d > 0:
		print(y - d)
	else:
		print(0)


n = int(input())
listA = []
listB = []
for i in range(0, n):
	a = list(map(int, input().split()))
	listA.append(a[0])
	listB.append(a[1])
i = 0
while n:
	if listA[i] % listB[i] == 0:
		print('0')
		i = i + 1
	else:
		num = int(listA[i] / listB[i])
		exactNum = int(listB[i] * (num + 1))
		ans = int(exactNum - listA[i])
		print(ans)
		i = i + 1
	n = n - 1


from math import ceil
n = int(input())
for i in range(n):
	(a, b) = [int(i) for i in input().split()]
	calc = ceil(a / b) * b - a
	print(calc)


def divisibility(a, b):
	if a % b == 0:
		return 0
	else:
		return b - a % b
t = int(input())
for loop in range(t):
	(a, b) = map(int, input().split())
	print(divisibility(a, b))


for t in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b == 0:
		ans = 0
	else:
		ans = (a // b + 1) * b - a
	print(ans)


from math import ceil

def main():
	for test in range(int(input())):
		(a, b) = map(int, input().split())
		print(solution(a, b))

def solution(a, b):
	if a % b == 0:
		return 0
	return (a // b + 1) * b - a
main()


import sys
import math
import os.path
from collections import *
from queue import *
from bisect import *
from heapq import *
MOD = int(1000000000.0 + 7)
inf = float('inf')
ninf = float('-inf')
input = sys.stdin.buffer.readline

def ii():
	return list(map(int, input().strip().split()))
for _ in range(int(input())):
	(n, s) = ii()
	dif = sum(map(int, str(n))) - s
	if dif <= 0:
		print(0)
		continue
	(k, sm, n1) = (0, 0, n)
	while sm - 1 < dif:
		sm += n % 10
		n = n // 10
		k += 1
	k = 10 ** k
	print(k - n1 % k)


for _ in range(int(input())):
	(n, s) = input().split()
	(n, s) = (int(n), int(s))
	ss = 0
	for i in range(len(str(n))):
		ss += int(str(n)[i])
	if n == s or ss <= s:
		print(0)
	else:
		c = str(n)
		a = 0
		for i in range(n):
			a += int(c[i])
			if a >= s:
				break
		p = 10 ** (len(c) - i)
		c = c[i:]
		print(p - int(c))


n = int(input())
l2 = []
l3 = []
for i in range(n):
	s = input()
	l = s.split()
	for j in l:
		l2.append(int(j))
	l3.append(l2)
	l2 = []
for i in l3:
	left = i[0] % i[1]
	if left == 0:
		print(0)
	else:
		need = i[1] - left
		print(need)


n = int(input())
for i in range(n):
	(l, m) = map(int, input().split())
	if l % m != 0:
		count = m - l % m
	else:
		count = 0
	print(count)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a == 0:
		print(b)
		continue
	if a % b == 0:
		print(0)
	else:
		z = a % b
		temp = b - z
		print(temp)


def li():
	return list(map(int, input().split()))

def ii():
	return int(input())
testcases = int(input())
for t in range(testcases):
	(a, b) = li()
	if int(a // b) == a / b:
		print(0)
	else:
		base = a // b
		top = (base + 1) * b
		print(top - a)


t = int(input())
for _ in range(t):
	a = input().split()
	ans = int(a[0]) % int(a[1])
	if ans != 0:
		ans = int(a[1]) - ans
	else:
		ans = 0
	print(ans)


t = int(input())
for i in range(1, t + 1):
	arr = input()
	l = list(map(int, arr.split(' ')))
	if l[0] % l[1] != 0:
		print(l[1] - l[0] % l[1])
	else:
		print(0)


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	elif b > a:
		print(b - a)
	else:
		c = math.ceil(a / b)
		c = c * b
		print(abs(c - a))


def divisible(a, b):
	if a < b:
		n = b - a
	elif a > b:
		if a % b == 0:
			n = 0
		else:
			n = b - a % b
	else:
		n = 0
	return n
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	print(divisible(a, b))


import sys
from random import choice, randint
inp = sys.stdin.readline
out = sys.stdout.write
flsh = sys.stdout.flush
sys.setrecursionlimit(10 ** 9)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def MI():
	return map(int, inp().strip().split())

def LI():
	return list(map(int, inp().strip().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]

def LI_():
	return [int(x) - 1 for x in inp().strip().split()]

def LF():
	return [float(x) for x in inp().strip().split()]

def LS():
	return inp().strip().split()

def I():
	return int(inp().strip())

def F():
	return float(inp().strip())

def S():
	return inp().strip()

def pf(s):
	return out(s + '\n')

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def main():
	t = I()
	l = []
	for _ in range(t):
		(a, b) = MI()
		ans = b - a % b
		if a % b == 0:
			ans = 0
		print(ans)
main()


import math
for i in range(int(input())):
	(a, b) = map(int, input().split())
	i = 0
	k = 0
	c = 0
	if a <= b:
		i = (b - a) // 1
		print(i)
	else:
		k = a / b
		c = math.ceil(k) * b
		print((c - a) // 1)


def Divisibility_Problem(a, b):
	if a % b == 0:
		return 0
	elif a < b:
		return b - a
	else:
		return b - a % b
n = input()
for i in range(0, int(n)):
	(a, b) = input().split()
	print(Divisibility_Problem(int(a), int(b)))


def div(n, m):
	cont = 0
	if n % m != 0:
		cont = m - n % m
	return cont
t = int(input())
for c in range(t):
	(o, i) = map(int, input().split())
	print(div(o, i))


t = int(input())
while t:
	li = [int(i) for i in input().split()]
	a = li[0]
	b = li[1]
	rem = a % b
	if rem == 0:
		print(rem)
	else:
		k = b - rem
		print(k)
	t -= 1


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	k = a % b
	if k != 0:
		ans = b - k
		print(ans)
	else:
		print(0)


import sys
input = sys.stdin.readline
t = int(input())
while t > 0:
	(a, b) = map(int, input().split())
	if a % b > 0:
		print(b - a % b)
	else:
		print(0)
	t -= 1


for q_ in range(int(input())):
	(a, b) = map(int, input().split())
	r = a % b
	if a % b == 0:
		print(0)
	else:
		print(b - r)


n = int(input())
for i in range(n):
	inp = [int(num) for num in input().split()]
	(a, b) = (inp[0], inp[1])
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


def sm(n):
	sod = 0
	for i in str(n):
		sod += int(i)
	return sod
for _ in range(int(input())):
	(n, s) = [int(i) for i in input().split()]
	temp = n
	while sm(n) > s:
		j = 10
		while n % j == 0:
			j *= 10
		n += j - n % j
	print(n - temp)


def fun(a, b):
	if a % b == 0:
		return 0
	return b * (int(a // b) + 1) - a
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	print(fun(a, b))


def sumDigits(n):
	res = 0
	while n:
		res += n % 10
		n //= 10
	return res
cases = int(input())
for _ in range(cases):
	(n, s) = map(int, input().split())
	adds = 0
	multipler = 1
	while sumDigits(n) > s:
		toZero = 10 - n % 10
		if toZero == 10:
			toZero = 0
		adds += multipler * toZero
		n = (n + toZero) // 10
		multipler *= 10
	print(adds)


def sumnum(n):
	s = 0
	while n:
		s += n % 10
		n = n // 10
	return s
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	pw = 1
	ans = 0
	for i in range(18):
		z = sumnum(n)
		if z <= s:
			break
		dig = n // pw % 10
		add = (10 - dig) % 10 * pw
		n += add
		ans += add
		pw *= 10
	print(ans)


import math
test = int(input())
list1 = []
for t in range(test):
	l = list(map(int, input().split()))
	list1.append(l)
for i in range(test):
	a = list1[i][0]
	b = list1[i][1]
	d = math.ceil(a / b)
	print(abs(math.ceil(a / b) * b - a))


t = int(input())
while t:
	(x, y) = map(int, input().split())
	if x % y == 0:
		print('0')
	else:
		print(y - x % y)
	t = t - 1


c = int(input())
j = 0
e = []
d = []
for i in range(0, c):
	k = 0
	(a, b) = [int(x) for x in input().split()]
	j = 0
	k = a % b
	if k != 0:
		print(int(b) - int(k))
	else:
		print('0')


def sum_s(s):
	ans = 0
	for i in s:
		ans += i
	return ans
t = int(input())
while t:
	t -= 1
	(n, s) = map(int, input().split())
	l = []
	s1 = str(n)
	for i in s1:
		l.append(int(i))
	n = l
	if sum_s(n) <= s:
		print(0)
		continue
	steps = 0
	n1 = len(n)
	i = 0
	n.reverse()
	curr = 1
	while i < n1:
		if n[i] != 0:
			steps += (10 - int(n[i])) * curr
			n[i] = 0
			present = False
			for j in range(i + 1, n1):
				if n[j] == 9:
					n[j] = 0
				else:
					present = True
					n[j] = n[j] + 1
					break
			if not present:
				break
		i += 1
		if sum_s(n) <= s:
			break
		curr *= 10
	print(steps)


t = int(input())
for i in range(t):
	case = input().split()
	(n, s) = (case[0], int(case[1]))
	if sum([int(c) for c in n]) <= s:
		print(0)
		continue
	acc = 0
	for (i, digit) in enumerate(n):
		if acc + int(digit) < s:
			acc += int(digit)
		else:
			rest = int(n[i:])
			moves = 10 ** len(str(rest)) - rest
			print(moves)
			break


def Solution(a, b):
	if a < b:
		return b - a
	l = a % b
	if l is 0:
		return 0
	return b - l
for _ in range(int(input())):
	test = input().split(' ')
	print(Solution(int(test[0]), int(test[1])))


import sys
pprint = lambda s: print(' '.join(map(lambda x: str(x), s)))
input = lambda : sys.stdin.readline().strip()
ipnut = input
mod = 1000000007
for i in range(int(input())):
	(n, s) = map(int, input().split())
	ans = 0
	step = 1
	while sum(list(map(int, list(str(n))))) > s:
		x = n % 10
		if x == 0:
			n //= 10
			step *= 10
			continue
		n //= 10
		ans += (10 - x) * step
		step *= 10
		n += 1
	print(ans)


from functools import lru_cache
import bisect
from collections import Counter

def solve():
	(a, b) = map(int, input().split(' '))
	if a % b == 0:
		return 0
	return b - a % b
t = int(input())
for _ in range(t):
	print(solve())


from sys import stdin, stdout
Pi = lambda x: stdout.write(str(x) + '\n')
S = lambda x: x * (x + 1) // 2
I = lambda x: 1 + 2 * x
R = lambda : stdin.readline()
Ri = lambda x: map(int, x.split())
Rs = lambda x: map(str, x.split())
Rf = lambda x: map(float, x.split())

def main():
	t = int(R())
	for x in range(t):
		(a, b) = Ri(R())
		ans = (b - a % b) % b
		Pi(ans)
main()


import sys
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a % b != 0:
		print(b - a % b)
	else:
		print(0)


t = int(input())
while t:
	t -= 1
	(a, b) = [int(x) for x in input().split()]
	if a % b == 0:
		print(0)
	else:
		k = a // b
		k += 1
		c = b * k
		ans = c - a
		print(ans)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	a = [int(k) for k in str(n)]
	if sum(a) <= s:
		print(0)
		continue
	total = 0
	i = 0
	while i < len(a):
		if a[i] + total < s:
			total += a[i]
			i += 1
		else:
			break
	if i == len(a):
		print(0)
		continue
	if i == 0:
		print(10 ** len(a) - n if sum(a) > s else 0)
		continue
	for j in range(i - 1, -1, -1):
		if a[j] == 9:
			a[j] = 0
		else:
			a[j] += 1
			break
	for j in range(i, len(a)):
		a[j] = 0
	ans = int(''.join((str(k) for k in a))) - n
	print(ans if ans >= 0 else 10 ** len(a) - n)


from math import ceil
x = int(input())
for i in range(x):
	a = list(map(int, input().split()))
	z = ceil(a[0] / a[1])
	print(z * a[1] - a[0])


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	a = list(map(int, list(str(n))))
	temp = 0
	ans = 0
	x = len(a)
	for i in range(x):
		if a[i] + temp > s:
			for j in range(i, x):
				a[j] = 0
			c = i - 1
			while c >= 0 and temp + 1 > s:
				temp -= a[c]
				a[c] = 0
				c -= 1
			if c < 0:
				a.insert(0, 1)
			else:
				a[c] += 1
			break
		else:
			temp += a[i]
	new = 0
	p = 0
	for i in range(len(a) - 1, -1, -1):
		new += a[i] * pow(10, p)
		p += 1
	print(new - n)


def solve(a, b):
	sol = a % b
	if sol == 0:
		return 0
	return b - sol
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split(' '))
	y = solve(a, b)
	print(y)


def divisor(a, b):
	c = 0
	while b < 0:
		if a % b == 0:
			print(0)
			b -= 1
	else:
		print((b - a) % b)
		b = b - 11
for i in range(int(input())):
	(a, b) = map(int, input().split())
	divisor(a, b)


import sys
input = sys.stdin.readline
from collections import *
from math import *
t = int(input())
while t:
	t -= 1
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
		continue
	z = ceil(a / b)
	print(z * b - a)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	n = str(n)
	x = len(n)
	z = 0
	for i in range(x):
		z += int(n[i])
	if z <= s:
		print('0')
		continue
	if x == 1:
		print(10 - int(n[0]))
		continue
	i = 0
	z = 0
	while z < s and i < x:
		z += int(n[i])
		if z >= s:
			break
		i += 1
	if i == 0:
		p = '1' + '0' * x
	else:
		p = str(int(n[:i]) + 1) + '0' * (x - i)
	print(int(p) - int(n))


for _ in range(int(input())):
	(a, d) = map(int, input().strip().split())
	count = 0
	x = a % d
	if x == 0:
		print('0')
	else:
		print(d - x)


import sys
import math
input = sys.stdin.readline

def main():
	for _ in range(int(input())):
		(a, b) = map(int, input().split())
		if a % b == 0:
			print(0)
		elif b > a:
			print(b - a)
		else:
			print(b * math.ceil(a / b) - a)
main()


import sys
import time
import math

def calc(a, b):
	temp = math.ceil(a / b)
	temp *= b
	return temp - a

def main():
	for _ in range(int(sys.stdin.readline())):
		(a, b) = list(map(int, sys.stdin.readline().split()))
		sys.stdout.write('%d\n' % calc(a, b))
HELLO_WORLD = False
if HELLO_WORLD is True:
	sys.stdin = open('input.in.txt', 'r')
	start_time = time.time()
	main()
	print('--- %.5s seconds ---' % (time.time() - start_time))
else:
	main()


t = int(input())
tasks = []
for i in range(t):
	tasks.append(list(map(int, input().split())))
for i in range(t):
	(n, s) = tasks[i]
	str_n = str(n)
	if sum([int(str_n[j]) for j in range(len(str_n))]) <= s:
		print(0)
	else:
		x = len(str(n))
		while sum([int(j) for j in '0' + str(n)[:-x]]) < s and x > 0:
			x -= 1
		x += 1
		print((int(('0' + str(n))[:-x]) + 1) * 10 ** x - n)


def sum_dig(n):
	sm = 0
	while n > 0:
		sm += n % 10
		n //= 10
	return sm
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	xs = sum_dig(n) - s
	(cnt, pv) = (0, 1)
	while True:
		m = (10 - n % 10) * pv
		if sum_dig(n) <= s:
			break
		else:
			cnt += m
			n //= 10
			n += 1
			xs = sum_dig(n) - s
		pv *= 10
	print(cnt)


testcases = int(input())
while testcases:
	testcases -= 1
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		z = a // b
		z += 1
		print(b * z - a)


t = int(input())
while t:
	(a, b) = map(int, input().split())
	print((b - a) % b)
	t -= 1


while True:
	t = int(input())
	if t >= 1 and t <= 10 ** 4:
		break
for i in range(t):
	(a, b) = map(int, input().split(' '))
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


n = int(input())
for i in range(n):
	arr = list(map(int, input().split()))
	a = arr[0]
	b = arr[1]
	x = a % b
	if x == 0:
		print('0')
	else:
		j = b - x
		print(j)


import math
t = int(input())
for x in range(t):
	(a, b) = list(map(int, input().split(' ')))
	print(math.ceil(a / b) * b - a)


t = int(input())
for i in range(t):
	(a, b) = [int(i) for i in input().split()]
	if a % b == 0:
		print(0)
	else:
		rem = a % b
		ls = b - rem
		print(ls)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	elif a <= b:
		res = b - a
		print(res)
	else:
		mod = a % b
		res = b - mod
		print(res)


t = int(input())
for i in range(t):
	(n, s) = [int(k) for k in input().split()]
	c = [int(k) for k in str(n)]
	res = 0
	while c and sum(c) > s:
		c.pop()
		res += 1
		while c and c[-1] == 9:
			c.pop()
			res += 1
		if c:
			c[-1] += 1
	if not c:
		print(int('1' + len(str(n)) * '0') - n)
	else:
		print(int(''.join([str(k) for k in c]) + '0' * res) - n)


t = int(input())
for i in range(t):
	(a, b) = [int(x) for x in input().split()]
	ans = b - a % b
	if a % b == 0:
		ans = 0
	print(ans)


n = int(input())
i = 0
lst = list()
result = list()
while i < n:
	data = input()
	for j in data.split():
		lst.append(int(j))
	i = i + 1
l = len(lst)
k = 0
while k < l - 1:
	remainder = lst[k] % lst[k + 1]
	if remainder == 0:
		result.append(remainder)
	else:
		a = lst[k + 1] - remainder
		result.append(a)
	k = k + 2
for a in result:
	print(a)


a = int(input())
for _ in range(a):
	(n, m) = map(int, input().split())
	k = n % m
	print((m - k) % m)


t = int(input())
for _ in range(t):
	(string, k) = map(str, input().split())
	k = int(k)
	arr = []
	sums = 0
	for ch in string[::-1]:
		sums += int(ch)
		arr.append(int(ch))
	arr.append(0)
	if sums <= k:
		print(0)
		continue
	ans = 0
	count = 1
	last = 0
	for i in range(len(arr)):
		if last + arr[i] == 0:
			count = count * 10
			continue
		elif sums - arr[i] - last >= k:
			ans += count * (10 - arr[i] - last)
			sums = sums - arr[i] - last + 1
			last = 1
		else:
			ans += count * (10 - arr[i] - last)
			break
		count = count * 10
	print(ans)


from sys import stdin, stdout
import math
t = int(stdin.readline())
for test in range(t):
	arr = [int(x) for x in stdin.readline().split()]
	big = arr[0]
	num = arr[1]
	if big % num == 0:
		stdout.write('0\n')
	elif big < num:
		stdout.write(str(num - big) + '\n')
	else:
		stdout.write(str(num - big % num) + '\n')


for _ in range(int(input())):
	(n, s) = map(str, input().split())
	n = '0' + n
	l = []
	for a in n:
		l.append(int(a))
	sum = 0
	s = int(s)
	i = 1
	while i < len(l):
		sum = sum + l[i]
		if sum <= s:
			i = i + 1
		else:
			sum = sum - l[i]
			for j in range(i, len(l)):
				l[j] = 0
			i = i - 1
			sum = sum - l[i]
			l[i] += 1
	new = 0
	for a in l:
		new = new * 10 + int(a)
	print(new - int(n))


import sys

def q1():
	for (inx, line) in enumerate(sys.stdin):
		if inx == 0:
			continue
		tokens = line.rstrip('\n').split()
		a = int(tokens[0])
		b = int(tokens[1])
		if a < b:
			print(b - a)
			continue
		elif a % b == 0:
			print(0)
		else:
			d = a // b
			an = b * (d + 1)
			print(an - a)
q1()


output = []
for _ in range(int(input())):
	k = 0
	numbers = input().split()
	(a, b) = (int(numbers[0]), int(numbers[1]))
	if a <= b:
		output.append(b - a)
	else:
		need = b - a % b
		if need == b:
			need = 0
		output.append(need)
for _ in output:
	print(_)


t = int(input())
for z in range(t):
	arr = list(map(int, input().rstrip().split()))
	a = arr[0]
	b = arr[1]
	if a > b and b % a != 0:
		d = int(a / b)
		rem = a % b
		if rem == 0:
			print('0')
		else:
			r = b * (d + 1)
			ans = r - a
			print(ans)
	elif b > a:
		ans = b - a
		print(ans)
	elif a % b == 0:
		print('0')


x = int(input())
for a in range(0, x):
	y = input().split()
	if int(y[0]) % int(y[1]) == 0:
		print(0)
	else:
		print(int(y[1]) - int(y[0]) % int(y[1]))


def solve(n, s):
	dns = [ord(x) - ord('0') for x in str(n)]
	if sum(dns) <= s:
		return 0
	m = len(dns)
	for (i, d) in enumerate(dns):
		if d >= s:
			return 10 ** (m - i) - n % 10 ** (m - i)
		s -= d
	return 42
for _ in range(int(input())):
	(n, s) = [int(x) for x in input().split()]
	print(solve(n, s))


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	m = a % b
	if m > 0:
		m = b - m
	print(m)


import math
for i in range(int(input())):
	(x, y) = map(int, input().split())
	z = math.ceil(x / y)
	print(z * y - x)


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		quo = a // b + 1
		product = quo * b
		inc = product - a
		print(inc)


from math import ceil
numbertest = int(input())
for i in range(0, numbertest):
	numbers = input().split()
	a = int(numbers[0])
	b = int(numbers[1])
	if a % b == 0:
		print('0')
	if a % b != 0:
		print(ceil(a / b) * b - a)


for _ in range(int(input())):
	(n, s) = input().split()
	s = int(s)
	(sum, second_sum, k) = (0, 0, 0)
	for i in n:
		sum += int(i)
	if sum <= s:
		print(0)
	elif int(n[0]) >= s:
		print(int('1' + len(n) * '0') - int(n))
	else:
		for i in n:
			if second_sum == s:
				new = str(int(n[:k - 1]) + 1) + '0' * (len(n) - k + 1)
				print(int(new) - int(n))
				break
			elif second_sum > s or second_sum + int(i) > s:
				new = str(int(n[:k]) + 1) + '0' * (len(n) - k)
				print(int(new) - int(n))
				break
			else:
				second_sum += int(i)
				diff = s - second_sum
				k += 1


for _ in range(int(input())):
	(q, w) = input().split()
	Q = list(map(int, reversed(q)))
	s = sum(Q)
	w = int(w)
	ans = 0
	i = 0
	while s > w:
		if Q[i] != 0:
			add = 10 - Q[i]
			s -= Q[i]
			ans += add * 10 ** i
			Q[i] += add
			s += 1
			if i + 1 < len(Q):
				Q[i + 1] += 1
			else:
				Q.append(1)
		i += 1
	print(ans)


import sys
import math
import heapq
from collections import defaultdict, deque
input = sys.stdin.readline

def r():
	return int(input())

def rm():
	return map(int, input().split())

def rl():
	return list(map(int, input().split()))
for i in range(r()):
	(a, b) = rm()
	if a % b == 0:
		print(0)
		continue
	print(b - a % b)


def divisible():
	t = [int(i) for i in input().split()]
	a = t[0]
	b = t[1]
	sum = 0
	if a % b == 0:
		print(sum)
	else:
		c = int(a / b)
		c = c + 1
		c = b * c
		sum = c - a
		print(sum)
x = int(input())
for i in range(0, x):
	divisible()


t = int(input())
while t:
	(a, b) = [int(x) for x in input().split()]
	if a % b == 0:
		print('0')
		t -= 1
		continue
	a = (int(a / b) + 1) * b - a
	print(int(a))
	t -= 1


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	ns = str(n)
	l = len(ns)
	i = 0
	sum_ = 0
	p = n
	a = []
	while p > 0:
		a.append(p % 10)
		p //= 10
	a.reverse()
	sum_ = sum(a)
	if sum_ <= s:
		print('0')
		continue
	m = 0
	i = 0
	while m + a[i] < s:
		m += a[i]
		i += 1
	j = 0
	ans = 0
	while j < i:
		ans = ans * 10 + a[j]
		j += 1
	ans += 1
	ans = ans * 10 ** (l - i)
	print(ans - n)


T = int(input())

def sumOfDigits(a):
	x = 0
	while a != 0:
		x += a % 10
		a = a // 10
	return x

def newSum(n, digit):
	n += digit
	return (n, sumOfDigits(n))
for i in range(T):
	(n, s) = [int(s) for s in input().split()]
	sumN = sumOfDigits(n)
	if sumN <= s:
		print(0)
	else:
		original = n
		j = 1
		add = n % 10
		while sumN > s:
			if add == 0:
				j *= 10
				add = n // j % 10
				continue
			n += (10 - add) * j
			sumN = sumOfDigits(n)
			j *= 10
			add = n // j % 10
		print(abs(original - n))


for tc in range(int(input())):
	(a, b) = list(map(int, input().split()))
	temp = b - a % b
	if temp == b:
		print(0)
	else:
		print(temp)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print('0')
	else:
		cnt = 0
		if a < b:
			print(b - a)
		else:
			b = b * (a // b + 1)
			print(b - a)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	counter = 0
	per = a % b
	if per == 0:
		print(0)
	else:
		print(b - per)


import os
import sys
from io import BytesIO, IOBase

def solution(a, b):
	if a % b == 0:
		write(0)
		return
	if a < b:
		write(b - a)
		return
	write(b * (a // b + 1) - a)

def main():
	for _ in range(r_int()):
		(a, b) = r_array()
		solution(a, b)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def write(*args, end='\n'):
	for x in args:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())

def w_array(arr):
	for x in arr:
		write(x, end=' ')
	write()
main()


t = int(input())
for i in range(t):
	(a, b) = list(map(int, input().split()))
	if a % b != 0:
		r = a // b
		j = (r + 1) * b - a
		print(j)
	else:
		print('0')


import sys
ii = lambda : sys.stdin.readline().strip()
idata = lambda : [int(x) for x in ii().split()]

def solve():
	(n, s) = idata()
	n = list(str(n))
	summ = 0
	ans = 0
	for i in range(len(n)):
		n[i] = int(n[i])
	summ = sum(n)
	if summ <= s:
		print(0)
	else:
		n = n[::-1]
		n += [0]
		i = 0
		c = 1
		while summ > s:
			if n[i] != 0:
				summ -= n[i] - 1
				ans += (10 - n[i]) * c
				n[i] = 10
				j = 0
				while n[i + j] == 10:
					if j:
						summ -= 9
					j += 1
					n[i + j] += 1
				i += j - 1
				c *= 10 ** (j - 1)
			i += 1
			c *= 10
		print(ans)
	return
for t in range(int(ii())):
	solve()


from math import log2, ceil
from heapq import heappush, heappop, heapify
from copy import deepcopy
from collections import deque, Counter as CC

def main():
	for t in range(int(input())):
		(n, d) = [int(j) for j in input().split()]
		s = [int(j) for j in str(n)]
		m = len(s)
		if sum(s) <= d:
			print(0)
			continue
		ct = 0
		s = [0] + s
		flag = True
		for i in range(m):
			if flag:
				if d - s[i] - ct <= s[i + 1]:
					s[i] = 1 + s[i]
					if s[i] == 10 and i > 0:
						cur = i
						while cur >= 0:
							if s[cur] < 9:
								s[cur] += 1
								break
							s[cur] = 0
							cur -= 1
					flag = False
				else:
					ct += s[i]
			else:
				s[i] = 0
		s[-1] = 0
		print(int(''.join(map(str, s))) - n)
main()


MOD = 1000000007
MOD2 = 998244353
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
let = 'abcdefghijklmnopqrstuvwxyz'
for _ in range(ii()):
	(a, b) = f()
	x = (b - a % b) % b
	print(x)


t = int(input())
for i in range(t):
	(x, y) = map(int, input().split())
	if x % y == 0:
		print(0)
	else:
		u = x // y
		print(-x + (u + 1) * y)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	n1 = str(n)
	l = list(n1)
	sum1 = sum(list(map(int, str(n))))
	moves = sum2 = 0
	for i in l:
		sum2 += int(i)
	if sum2 == s:
		print(0)
		continue
	i = 0
	while sum1 > s:
		dec = 10 - n % 10
		moves += 10 ** i * dec
		n += dec
		n //= 10
		sum1 = sum(list(map(int, str(n))))
		i += 1
	print(moves)


t = int(input())
for i in range(0, t):
	y = input().split()
	a = int(y[0])
	b = int(y[1])
	m = a % b
	if m == 0:
		print(m)
	else:
		print(b - m)


import sys

class DDecreaseTheSumOfDigits:

	def solve(self, tc=0):
		for _ in range(int(input())):
			(n, s) = [int(_) for _ in input().split()]
			ns = [int(x) for x in str(n)]
			ans = 0
			if sum(ns) <= s:
				print(ans)
				continue
			p = len(ns)
			cur = p - 1
			ns.append(0)
			for i in range(len(ns) - 1, -1, -1):
				ans += (10 - ns[cur]) % 10 * 10 ** (p - i)
				if ns[cur] != 0:
					ns[cur] = 0
					ns[cur - 1] += 1
				cur -= 1
				if sum(ns) <= s:
					print(ans)
					break
solver = DDecreaseTheSumOfDigits()
input = sys.stdin.readline
solver.solve()


def digsum(n):
	ans = 0
	while n:
		ans += n % 10
		n //= 10
	return ans
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	a = digsum(n)
	t = n
	if a > s:
		i = 1
		while True:
			r = t % 10 ** i
			t += 10 ** i - r
			if digsum(t) <= s:
				print(t - n)
				break
			i += 1
	else:
		print(0)


import math
import sys
I = sys.stdin.readline
ans = ''
for _ in range(int(I())):
	(a, b) = map(int, I().split())
	ans += '{}\n'.format(b * math.ceil(a / b) - a)
print(ans)


t = int(input())
for z in range(t):
	(a, b) = [int(x) for x in input().split()]
	if a % b == 0:
		print(0)
		continue
	ans = b - a % b
	print(ans)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().strip().split(' '))
	if a % b == 0:
		print('0')
	else:
		c = a // b
		c += 1
		d = b * c - a
		print(d)


t = int(input())
for i in range(t):
	x = input()
	l = str.split(x, ' ')
	a = int(l[0])
	b = int(l[1])
	if a % b == 0:
		print(0)
	else:
		n = a // b
		print((n + 1) * b - a)


t = int(input())
for t1 in range(0, t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		x = a // b
		z = (x + 1) * b
		print(z - a)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n % k == 0:
		p = 0
	else:
		r = int(n / k) + 1
		p = k * r - n
	print(p)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	rest = a % b
	moves = b - rest if rest else 0
	print(moves)


import sys
input()
for line in sys.stdin:
	(a, b) = map(int, line.split())
	r = a % -b
	print(-r)


for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	if a % b == 0:
		print(0)
	else:
		temp = a // b
		ans = (temp + 1) * b - a
		print(ans)


import math as mt
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	ans = mt.ceil(a / b) * b - a
	print(ans)


import sys
import os
DEBUG = True

class Scan:

	def __init__(self):
		self.read = sys.stdin.read
		self.input = sys.stdin.readline

	def integer(self, count=1):
		if count == 1:
			return self._integer()
		return [self._integer() for _ in range(count)]

	def _integer(self):
		sym: str = self.read(1)
		if DEBUG:
			if sym != '-' and (not sym.isdigit()):
				raise ValueError('Not integer')
		(number, sign) = (0, -1) if sym == '-' else (int(sym), 1)
		sym: str = self.read(1)
		while sym.isdigit():
			number = number * 10 + int(sym)
			sym = self.read(1)
		return number * sign

def solution(scan: Scan):
	(a, b) = scan.integer(2)
	if a % b == 0:
		print(0)
	else:
		print((a // b + 1) * b - a)

def main():
	queries: int = 1
	scan = Scan()
	queries = scan.integer()
	for _ in range(queries):
		solution(scan)
main()


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	k1 = a % b
	k2 = a // b
	if a % b == 0:
		print(0)
	else:
		print(b * (k2 + 1) - a)


n = int(input())
numbers = [[int(x) for x in input().split()] for y in range(n)]
div = []
for x in range(len(numbers)):
	if numbers[x][0] % numbers[x][1] == 0:
		div.append(0)
	else:
		div.append(numbers[x][1] - numbers[x][0] % numbers[x][1])
for x in div:
	print(x)


def solver(n, s):
	if n <= s:
		return 0
	if sum(map(int, list(str(n)))) <= s:
		return 0
	memo = []
	X = list(str(n))
	for _ in range(1, len(X)):
		memo.append(int(str(n)[:_]) + 1)
	memo.append(n)
	memo = memo[::-1]
	for i in range(1, len(X) + 1):
		memo[i - 1] = str(memo[i - 1]) + '0' * (i - 1)
	memo.append('1' + '0' * len(X))
	for i in memo:
		reached = sum(map(int, list(i)))
		if reached <= s:
			return int(i) - n
t = int(input())
Testcase = [list(map(int, input().split())) for i in range(t)]
for (n, s) in Testcase:
	opt = solver(n, s)
	print(opt)


import math
a = int(input())
for i in range(0, a):
	(a, b) = map(int, input().split())
	print(math.ceil(a / b) * b - a)


n = int(input())

def solve(a, b):
	if a % b == 0:
		return 0
	count = b - a % b
	return count
for i in range(n):
	data = list(map(int, input().split()))
	a = data[0]
	b = data[1]
	print(solve(a, b))


from sys import stdin
stdin.readline

def mp():
	return list(map(int, stdin.readline().strip().split()))

def it():
	return int(stdin.readline().strip())

def su(s):
	return sum(map(int, str(s)))
for _ in range(it()):
	(n, s) = mp()
	if su(n) <= s:
		print(0)
		continue
	else:
		i = 0
		ans = 0
		while i < 20:
			d = n // 10 ** i
			p = (10 - d) % 10 * 10 ** i
			n += p
			ans += p
			if su(n) <= s:
				print(ans)
				break
			i += 1


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	d = 0
	while a % b != 0:
		c = a % b
		d = b - c
		a += d
	print(d)


t = int(input())
for i in range(t):
	s = input().split()
	a = int(s[0])
	b = int(s[1])
	x = a / b
	y = a // b
	if x == y:
		print('0')
	else:
		r = a % b
		print(b - r)


for _ in range(int(input())):
	(x, y) = tuple(map(int, input().split()))
	if x % y == 0:
		print(0)
	else:
		print(y - x % y)


for _ in range(int(input())):
	(a, d) = (0, 10)
	(n, s) = map(int, input().split())
	sum1 = sum(map(int, list(str(n))))
	if s >= sum1:
		print(0)
		continue
	while sum1 > s:
		r = n % d
		n += d - r
		a += d - r
		sum1 = sum(map(int, list(str(n))))
		d = d * 10
	print(a)


from math import *
t = int(input())
for i in range(1, t + 1):
	(a, b) = map(int, input().split())
	n = 2
	if a <= b:
		print(b - a)
	else:
		n = ceil(a / b)
		print(n * b - a)


def aa(a, b, count):
	if a % b == 0 or a == b:
		count = 0
	elif a < b:
		count = b - a
	else:
		count = b - a % b
	print(count)
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	count = 0
	aa(a, b, count)


t = int(input())
for _ in range(t):
	(a, b) = [int(x) for x in input().strip().split()]
	rem = a % b
	if a < b:
		res = b - a
	else:
		res = (b - rem) % b
	print(res)


test = int(input())
for i in range(1, test + 1):
	id = []
	id = input().split()
	a = int(id[0])
	b = int(id[1])
	cac = 0
	if a % b != 0:
		cac = 1
	ans = (int(a / b) + cac) * b - a
	print(ans)


output = ''
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b is 0:
		output += '0\n'
	else:
		output += str(b - a % b) + '\n'
print(output)


from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
from heapq import *
from fractions import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 300010
MOD = 10 ** 9 + 7
spf = [i for i in range(MAXN)]
spf[0] = spf[1] = -1

def sieve():
	for i in range(2, MAXN, 2):
		spf[i] = 2
	for i in range(3, int(MAXN ** 0.5) + 1):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def fib(n, m):
	if n == 0:
		return [0, 1]
	else:
		(a, b) = fib(n // 2)
		c = a % m * (b % m * 2 - a % m) % m
		d = a % m * (a % m) % m + b % m * b % m % m
		if n % 2 == 0:
			return [c, d]
		else:
			return [d, c + d]

def charIN(x=' '):
	return sys.stdin.readline().strip().split(x)

def arrIN(x=' '):
	return list(map(int, sys.stdin.readline().strip().split(x)))

def ncr(n, r):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % MOD
		den = den * (i + 1) % MOD
	return num * pow(den, MOD - 2, MOD) % MOD

def flush():
	return sys.stdout.flush()
for _ in range(int(input())):
	(a, b) = arrIN()
	x = (a + b - 1) // b
	print(b * x - a)


from math import ceil
for _ in range(int(input())):
	line = input().split()
	a = int(line[0])
	b = int(line[1])
	print(b * ceil(a / b) - a)


n = input()
answears = []
for _ in range(int(n)):
	res = ['']
	last_index = 0
	num = input()
	for i in num:
		if i != ' ':
			res[last_index] += i
		else:
			res.append('')
			last_index += 1
	if int(res[0]) % int(res[1]) != 0:
		buf = int(res[0]) / int(res[1])
		answears.append(round((int(buf) + 1 - buf) * int(res[1])))
	else:
		answears.append(0)
for i in answears:
	print(i)


from math import ceil as c
t = int(input())
while t:
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		g = c(a / b)
		print(abs(a - b * g))
	t = t - 1


import math
import os
import random
import re
import sys

def solve(n, k):
	if n > k:
		if n % k == 0:
			return 0
		else:
			return (int(n / k) + 1) * k - n
	elif n < k:
		return k - n
	elif n == k:
		return 0
result = []
k = int(input())
for _ in range(k):
	nk = input().split()
	n = int(nk[0])
	k = int(nk[1])
	result.append(solve(n, k))
for i in range(len(result)):
	print(result[i], end='\n')


s = int(input())
for a in range(s):
	(h, i) = map(int, input().split())
	print((i - h % i) % i)


def somc(n):
	cnt = 0
	while n != 0:
		cnt = cnt + n % 10
		n = n // 10
	return cnt

def ansc(n, s):
	if somc(n) <= s:
		return 0
	else:
		a = 10
		while n % a == 0:
			a *= 10
		d = a - n % a
		return d + ansc(n + d, s)
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	print(ansc(n, s))


from math import ceil
t = int(input())

def checkio(a, b):
	if a == b:
		return 0
	b_inp = b
	if a < b:
		return b - a
	else:
		return b * ceil(a / b) - a
for i in range(t):
	(a, b) = list(map(int, input().split(' ')))
	print(checkio(a, b))


def solve(a, b):
	if a % b == 0:
		print(0)
	else:
		print(b * (a // b + 1) - a)

def main():
	t = int(input())
	for i in range(t):
		l = list(map(int, input().split()))
		solve(l[0], l[1])
main()


for _ in range(int(input())):
	l = [int(x) for x in input().split(' ')]
	x = l[0] % l[1]
	if x == 0:
		print(0)
		continue
	print(l[1] - x)


n = int(input())
lst = []
for i in range(n):
	count = 0
	(a, b) = map(int, input().split())
	if a % b != 0:
		lst.append(b - a % b)
	else:
		lst.append(0)
print(*lst, sep='\n')


t = int(input())
while t > 0:
	t -= 1
	(a, b) = map(int, input().split())
	c = a % b
	if c == 0:
		print(0)
		continue
	print(b - c)


import math, sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda : int(input())
li = lambda : list(map(int, input().split()))

def case():
	(a, b) = li()
	if a < b:
		print(b - a)
	elif a % b == 0:
		print(0)
	else:
		x = (a // b + 1) * b
		print(x - a)
for _ in range(int(input())):
	case()


import math
t = int(input())
ab = []
for i in range(t):
	ab.append(input())
for i in range(t):
	ab[i] = ab[i].split()
	ab[i][0] = int(ab[i][0])
	ab[i][1] = int(ab[i][1])
	x = ab[i][0] / ab[i][1]
	x = math.ceil(x)
	print(ab[i][1] * x - ab[i][0])


def solve():
	(a, b) = map(int, input().split())
	print(-a % b)

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


import sys
input = sys.stdin.readline
T = int(input())
for test in range(T):
	(a, b) = map(int, input().split())
	if a % b == 0:
		temp = a // b
	else:
		temp = a // b + 1
	b = b * temp
	print(b - a)


t = int(input())
result = []
while t > 0:
	(a, b) = list(map(int, input().split()))
	result.append((b - a % b) % b)
	t = t - 1
for x in result:
	print(x)


n = int(input())
for i in range(n):
	t = list(map(int, input().split()))
	print((t[1] - t[0] % t[1]) % t[1])


for t in range(int(input())):
	(n, s) = map(int, input().split())
	l = [0]
	l = l + list(map(int, str(n)))
	su = sum(l)
	if su <= s:
		print(0)
		continue
	st = ''
	for i in range(len(l) - 1, -1, -1):
		su = sum(l)
		if su <= s:
			print(int(st))
			break
		elif l[i] == 0:
			st = '0' + st
		else:
			st = str(10 - l[i]) + st
			l[i] = 0
			l[i - 1] = l[i - 1] + 1


import math
t = int(input())
Ans = []
for i in range(t):
	(a, b) = list(map(int, input().split()))
	if a <= b:
		ans = b - a
	elif a % b == 0:
		ans = 0
	else:
		ans = abs(a - (math.floor(a // b) + 1) * b)
	Ans.append(ans)
print(*Ans, sep='\n')


for _ in range(int(input())):
	(n, s) = map(str, input().split())
	s = int(s)
	f = [int(i) for i in n]
	(r, j) = ('', -1)
	(m, d, o) = (0, '', 0)
	for i in range(len(n)):
		if o == 0:
			m += int(n[i])
			if m >= s:
				o = 1
				j = i
				break
	if j == -1 or (i == len(n) - 1 and m <= s) or sum(f) <= s:
		print('0')
	else:
		k = 0
		for i in range(len(n) - 1, j - 1, -1):
			if k == 0:
				if n[i] == '0':
					d += '0'
				else:
					d += str(10 - int(n[i]))
					k = 1
			else:
				d += str(9 - int(n[i]))
		if d[-1] == '0':
			w = d[::-1]
			(o, a) = (0, 0)
			for i in range(len(w)):
				if w[i] == '0':
					a += 1
				elif i == a:
					d = w[i:]
					d = d[::-1]
					break
		print(d[::-1])


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	div = 0
	pls = 0
	if a % b == 0:
		print('0')
		continue
	div = a // b
	pls = (div + 1) * b
	print(pls - a)


for i in range(int(input())):
	a = list(map(int, input().strip().split()))[:2]
	if a[0] % a[1] == 0:
		print(0)
	else:
		c = int(a[0] / a[1]) + 1
		c = c * a[1]
		d = c - a[0]
		print(d)


import math
tc = int(input())
for i in range(tc):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		c = math.ceil(a / b)
		d = c * b
		e = d - a
		print(e)


def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))
from math import floor
t = inp()
while t:
	arr = inlt()
	n = int(arr[0])
	s = int(arr[1])
	tn = n
	ts = 0
	for digit in str(n):
		ts += int(digit)
	tn = n
	ttn = tn
	exp = 1
	while ts > s:
		if tn % pow(10, exp):
			tn = pow(10, exp) + tn - tn % pow(10, exp)
		ttn = tn
		exp += 1
		ts = 0
		for digit in str(ttn):
			ts += int(digit)
	print(tn - n)
	t -= 1


test = int(input())
moves = list()
a = list()
b = list()
for i in range(test):
	(x, y) = map(int, input().split(' '))
	a.append(x)
	b.append(y)
	if a[i] % b[i] != 0:
		add = (int(a[i] / b[i]) + 1) * b[i] - a[i]
		moves.append(add)
	else:
		moves.append('0')
print(*moves, sep='\n')


t = int(input())
ans = []
for i in range(t):
	(a, b) = map(int, input().split())
	z = (a // b + (a % b != 0)) * b - a
	ans.append(z)
for i in ans:
	print(i)


no_of_times = int(input())
x = 0
answer = 0
answer_list = []
for n in range(no_of_times):
	f_input = input()
	y = f_input.split(' ')
	a = int(y[0])
	b = int(y[1])
	if a % b == 0:
		answer = 0
		answer_list.append(answer)
	else:
		number = int(a / b)
		answer = b * (number + 1) - a
		answer_list.append(answer)
for n in range(no_of_times):
	print(answer_list[x])
	x += 1


import sys
import math
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
for i in range(t):
	(a, b) = invr()
	if a % b == 0:
		print(0)
	elif a < b:
		print(b - a)
	else:
		x = a / b
		x = math.ceil(x)
		ans = b * x - a
		print(ans)


t = int(input())
for _ in range(t):
	(n, s) = input().split()
	cnt = 0
	keta = len(n)
	wa = 0
	ans = ''
	for i in n:
		wa += int(i)
	if wa <= int(s):
		print(0)
		continue
	else:
		wa = 0
		for (i, x) in enumerate(n):
			wa += int(x)
			if wa >= int(s):
				break
			ans += x
			cnt = i + 1
		if ans == '':
			ans = 1
		else:
			ans = int(ans) + 1
		ans = str(ans) + '0' * (keta - cnt)
		ans = int(ans)
		print(ans - int(n))


t = int(input())
for i in range(0, t):
	(a, b) = map(int, input().split())
	c = a
	a1 = str(a)
	yy = len(a1)
	summ = 0
	a2 = []
	for j in range(0, yy):
		summ = summ + int(a1[j])
		a2.append(int(a1[j]))
	if summ <= b:
		print(0)
	else:
		s1 = summ - b
		j = yy - 1
		while j >= 0:
			s1 = s1 - int(a1[j])
			a2[j] = 0
			if j != 0:
				if a1[j - 1] != '9':
					a2[j - 1] += 1
				else:
					while a1[j - 1] == '9':
						a2[j - 1] = 0
						s1 = s1 - 9
						j -= 1
						if j == 0:
							break
					if j > 0:
						a2[j - 1] += 1
					else:
						a2.insert(0, 1)
			else:
				a2.insert(0, 1)
			if s1 < 0:
				break
			j -= 1
		str1 = ''
		for ii in a2:
			str1 = str1[0:] + str(ii)
		a22 = int(str1)
		print(a22 - a)


t = int(input())
for _ in range(t):
	values = [int(x) for x in input().split()]
	(a, b) = (values[0], values[1])
	if a % b == 0:
		print(0)
	elif a > b:
		div = (int(a / b) + 1) * b
		print(div - a)
	else:
		print(b - a)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	temp = a // b
	if not temp == a / b:
		temp = (temp + 1) * b
		print(temp - a)
	else:
		print(0)


def solve():
	(a, b) = [int(v) for v in input().split()]
	if a % b == 0:
		print(0)
		return
	d = a // b
	amt = (d + 1) * b - a
	print(amt)
t = int(input())
for _ in range(t):
	solve()


a = []
res = []
for i in range(int(input())):
	a.append(list(map(int, input().split())))
for i in a:
	if i[0] % i[1] == 0:
		print(0)
	else:
		print(i[1] - i[0] % i[1])


m = int(input())
a = []
n = m
for i in range(0, n):
	b = input()
	a.append(b)
for i in range(0, m):
	k = a[i]
	x = [int(y) for y in k.split()]
	count = 0
	if x[0] > x[1] and x[0] % x[1] != 0:
		h = x[0] % x[1]
		count = count + x[1] - h
	elif x[0] < x[1]:
		count = count + x[1] - x[0]
	print(count)


from bisect import *
t = int(input())

def solve(a, b):
	if a % b == 0:
		return 0
	lo = a
	hi = a + b
	dif = a % b
	while lo < hi:
		mid = (lo + hi) // 2
		if mid % b >= dif:
			lo = mid + 1
		else:
			hi = mid
	return lo - a
for test in range(1, t + 1):
	(a, b) = map(int, input().split())
	print(solve(a, b))


t = int(input())
for e in range(t):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	c = 0
	if a % b == 0:
		print('0')
	else:
		c = b - a % b
		print(c)


from math import sqrt
from collections import defaultdict
t = int(input())
while t:
	t = t - 1
	(a, b) = map(int, input().split())
	if not a % b:
		print(0)
	else:
		print(b - a % b)


def func(collection):
	if len(collection) == 2 and collection[1] >= 0 and (collection[0] >= 0):
		if collection[0] % collection[1] == 0:
			return 0
		else:
			return abs(collection[0] % collection[1] - collection[1])
temp_ls = []
mv_ls = []
i = 0
temp = True
while temp == True:
	if i == 0:
		message = int(input(''))
	elif i <= message:
		temp_ls = list(map(int, input('').split(' ')))
		mv_ls.append(func(temp_ls))
	else:
		temp = False
	i += 1
for i in range(len(mv_ls)):
	print(f'{mv_ls[i]}', end='\n')


def solve(a, b):
	if a >= b:
		m = (b - a % b) % b
	else:
		m = b - a
	return m
t = int(input())
for i in range(t):
	numbers = list(map(int, input().split()))
	e = solve(numbers[0], numbers[1])
	print(e)


count = int(input())
num = []
for y in range(count):
	n = 2
	a = list(map(int, input('').strip().split()))[:n]
	x = a[0] % a[1]
	if x == 0:
		value = 0
	else:
		value = a[1] - x
	num.append(value)
for i in num:
	print(i)


from math import floor, ceil
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	count = 0
	if a % b == 0:
		print(0)
	elif a < b:
		print(b - a)
	else:
		c = ceil(a / b)
		print(b * c - a)


def main():
	n = int(input())
	arr = []
	for i in range(0, n):
		(a, b) = input().split()
		(a, b) = (int(a), int(b))
		if a % b == 0:
			arr.append(0)
		elif a % b != 0:
			arr.append(b - a % b)
	for i in arr:
		print(i)
if __name__ == main():
	main()


test_cases = int(input())
data = []
while test_cases > 0:
	data.append(list(map(int, input().split())))
	test_cases -= 1
for test in data:
	if test[0] % test[1] == 0:
		print('0')
	else:
		ans = test[1] - test[0] % test[1]
		print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, s) = (int(i) for i in input().split())
	res = 0
	deg = 10
	while sum((int(i) for i in str(n))) > s:
		res += deg - n % deg
		n += deg - n % deg
		deg *= 10
	print(res)


from math import *

def solution(p):
	l = []
	for pair in p:
		if pair[0] % pair[1] == 0:
			l.append(0)
		else:
			l.append(ceil(pair[0] / pair[1]) * pair[1] - pair[0])
	return l
t = int(input())
lst = []
for i in range(t):
	lst.append(list(map(int, input().split())))
result = solution(lst)
for j in result:
	print(j)


def f():
	s = input().split(' ')
	a = int(s[0])
	b = int(s[1])
	if a % b == 0:
		print(0)
	else:
		print(b * (a // b + 1) - a)
t = int(input())
for i in range(t):
	f()


for test_c in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print('0')
	else:
		c = int(a / b)
		print((c + 1) * b - a)


n = int(input())
results = []
for i in range(n):
	(a, b) = map(int, input().split())
	if a % b == 0:
		results.append(0)
	elif a < b:
		results.append(b - a)
	elif a > b:
		results.append((a // b + 1) * b % a)
for i in range(len(results)):
	print(results[i])


case = int(input())
ans = []
for i in range(case):
	x = input().split()
	a = int(x[0])
	b = int(x[1])
	if a % b == 0:
		ans.append(0)
	else:
		ans.append((a // b + 1) * b - a)
for i in ans:
	print(i)


from sys import stdin, stdout

def read():
	x = stdin.readline().rstrip()
	return x

def __main__():
	t = int(read())
	for t0 in range(t):
		y = read()
		(a, b) = map(int, y.split())
		if a % b == 0:
			stdout.write('0\n')
		else:
			d = b * (a // b + 1) - a
			d_out = str(d) + '\n'
			stdout.write(d_out)
__main__()


from os import path
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input().rstrip()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')
file = 1

def solve():
	for _ in range(ii()):
		(n, s) = map(str, input().split())
		s1 = list(n[:])
		s1.reverse()
		(n, s) = (int(n), int(s))
		tot = 0
		for i in s1:
			tot += int(i)
		if tot <= s:
			print(0)
			continue
		n1 = len(s1)
		for i in range(n1):
			tot -= int(s1[i])
			if tot < s:
				f = i
				break
		if f == n1 - 1:
			print(pow(10, n1) - n)
			continue
		res = 0
		rem = 1
		for i in range(f + 1, n1):
			x = int(s1[i]) + rem
			if x == 10:
				x = 0
				rem = 1
			else:
				rem = 0
			res = x * pow(10, i) + res
		if rem:
			res = pow(10, n1) + res
		print(res - n)
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


cases = int(input(''))
for i in range(cases):
	actual_sum = 0
	flag = False
	info = input('').split(' ')
	digit_sum = int(info[1])
	corrector_digits = 0
	for j in range(len(info[0])):
		actual_sum = actual_sum + int(info[0][j])
		if actual_sum >= digit_sum and flag == False:
			if j > 0:
				corrector_digits = int(info[0][0:j]) + 1
			flag = True
	if actual_sum <= digit_sum:
		print('0')
		continue
	if corrector_digits == 0:
		print(10 ** int(len(info[0])) - int(info[0]))
		continue
	if corrector_digits != 0:
		while corrector_digits < int(info[0]):
			corrector_digits = corrector_digits * 10
		print(corrector_digits - int(info[0]))


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	f = 1
	if a % b == 0:
		f = 0
		print('0')
	elif a < b:
		f = 0
		print(b - a)
	if f == 1:
		n = a // b
		n += 1
		d = b * n
		print(d - a)


T = int(input())
for i in range(T):
	(a, b) = input().strip().split()
	(a, b) = (int(a), int(b))
	to_big = a % b
	if to_big == 0:
		print(0)
	else:
		print(b - to_big)


def main():
	t = int(input())
	for i in range(t):
		(n, s) = map(int, input().split())
		result = find_min_fix_cost(n, necessary_digits_sum=s)
		print(result)

def find_min_fix_cost(n, necessary_digits_sum):
	result_cost = 0
	curr_digit_index = 0
	while sum(map(int, str(n))) > necessary_digits_sum:
		curr_end_value = n % 10 ** (curr_digit_index + 1)
		new_end_value = 10 ** (curr_digit_index + 1)
		increment = new_end_value - curr_end_value
		n += increment
		result_cost += increment
		curr_digit_index += 1
	return result_cost
main()


tc = int(input())
for _ in range(tc):
	(a, b) = list(map(int, input().split()))
	now = a // b
	if a % b == 0:
		print(0)
	else:
		print(b * (now + 1) - a)


import sys
from operator import xor

def alele():
	return list(map(int, sys.stdin.readline().strip().split()))

def ilele():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
import bisect
for _ in range(int(input())):
	(a, b) = ilele()
	c = a // b
	if a % b == 0:
		print(0)
	else:
		d = b * (c + 1)
		print(abs(d - a))


def get_digit_sum(num: int) -> int:
	res = 0
	while num != 0:
		res += num % 10
		num //= 10
	return res
count = int(input())
for i in range(count):
	(n, s) = map(int, input().split())
	digit_sum = get_digit_sum(n)
	original = n
	if digit_sum > s:
		exp = 1
		carried = 0
		while get_digit_sum(n) > s:
			val = n % (exp * 10)
			if val:
				n -= val
				n += exp * 10
			exp *= 10
		print(n - original)
	else:
		print(0)


import sys
from sys import stdin
import math

def iinput():
	return int(input())

def minput():
	return map(int, input().split())

def linput():
	return list(map(int, input().split()))

def fiinput():
	return int(stdin.readline())

def fminput():
	return map(int, stdin.readline().strip().split())

def flinput():
	return list(map(int, stdin.readline().strip().split()))
for _ in range(iinput()):
	(n, s) = input().split()
	s = int(s)
	ss = 0
	n = list(n)
	for i in range(len(n)):
		ss += int(n[i])
	if ss <= s:
		print(0)
	else:
		n = n[::-1]
		n.append('0')
		c = 0
		i = 0
		while ss > s:
			ss -= int(n[i])
			if int(n[i]) != 0:
				c += 10 ** (i + 1) - int(n[i]) * 10 ** i
				n[i] = '0'
				if n[i + 1] != '9':
					n[i + 1] = chr(ord(n[i + 1]) + 1)
				else:
					n[i + 1] = '0'
					ss -= 9
					while n[i + 2] == '9':
						ss -= 9
						n[i + 2] = '0'
						i += 1
					n[i + 2] = chr(ord(n[i + 2]) + 1)
				ss += 1
			i += 1
		print(c)


import sys
input = sys.stdin.readline
read = lambda : map(int, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0, hi=None):
	if hi == None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
from itertools import permutations
import math
from bisect import bisect_left

def solve():
	(n, s) = map(int, input().split())
	v = n
	d = 1
	while sum(map(int, str(n))) > s:
		c = n // d % 10
		n += (10 - c) % 10 * d
		d *= 10
	print(n - v)
for _ in range(int(input())):
	solve()


test = int(input())
for ans in range(test):
	(n, s) = map(int, input().split())
	add = 0
	x = 10
	while n > 0:
		sums = sum(map(int, str(n)))
		if sums <= s:
			break
		else:
			add += x - n % x
			n = n + (x - n % x)
			x = x * 10
	print(add)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	elif a % b != 0 and a > b:
		print(b * (a // b + 1) - a)
	else:
		print(b - a)


for j in range(int(input())):
	(a, b) = map(int, input().split())
	if a >= b:
		if a % b == 0:
			print(0)
		else:
			c = a // b
			ans1 = (c + 1) * b - a
			print(ans1)
	elif a < b:
		print(b - a)


T = int(input())
for i in range(T):
	(a, b) = list((int(x) for x in input().strip().split()))[:2]
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


T = int(input())
for _ in range(T):
	(A, B) = map(int, input().split())
	if A % B == 0:
		print(0)
	else:
		C = (A // B + 1) * B
		print(C - A)


t = int(input())
for tc in range(t):
	(n, m) = map(int, input().split())
	if n % m != 0:
		print('{}'.format(m - n % m))
	else:
		print('0')


def solve(a, b):
	val = a % b
	if val == 0:
		return 0
	else:
		return b - val
t = int(input())
for ti in range(t):
	(a, b) = map(int, input().split())
	res = solve(a, b)
	print(res)


num = int(input())
for i in range(num):
	(a, b) = [int(_) for _ in input().split()]
	if a % b == 0:
		print(0)
	else:
		divide = int(a / b) + 1
		print(divide * b - a)


t = int(input())
while t:
	c = 0
	s = input()
	li = s.split(' ')
	lis = [0, 0]
	for i in range(2):
		lis[i] = int(li[i])
	a = lis[0]
	b = lis[1]
	if a % b == 0:
		print(c)
	elif a < b:
		print(b - a)
	else:
		print(b - a % b)
	t = t - 1


def solve():

	def digit_sum(x):
		res = 0
		while x > 0:
			res += x % 10
			x //= 10
		return res
	(n, s) = map(int, input().split())
	if digit_sum(n) <= s:
		print(0)
		return
	for i in range(1, 20):
		q = 10 ** i
		r = q - n % q
		n += r
		if digit_sum(n) <= s:
			print(r)
			return
		n -= r
t = int(input())
for i in range(t):
	solve()


import math

def check(a, b):
	count = 0
	x = math.ceil(a / b)
	x = x * b
	return x - a
for i in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	elif a < b:
		print(b - a)
	else:
		print(check(a, b))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	print((m - n) % m)


try:
	t = int(input())
	while t:
		(a, b) = [int(x) for x in input().split()]
		if a % b == 0:
			print('0')
		else:
			r = a % b
			print(b - r)
		t -= 1
except:
	pass


nbtests = int(input())
for k in range(nbtests):
	donnees = input().split(' ')
	a = int(donnees[0])
	b = int(donnees[1])
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


def sum_of_digits(m):
	ans = 0
	while m != 0:
		ans += m % 10
		m = m // 10
	return ans

def avalin_gheyresefr(n):
	i = 0
	while n % 10 == 0:
		n = n // 10
		i += 1
	return (10 - n % 10, i)

def find_ans(n, s):
	ans = 0
	while sum_of_digits(n) > s:
		(q, i) = avalin_gheyresefr(n)
		n += 10 ** i * q
		ans += 10 ** i * q
	return ans
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	print(find_ans(n, s))


import math

def noMoves(a, b):
	if a % b == 0:
		return 0
	return math.ceil(a / b) * b - a
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	print(noMoves(a, b))


t = int(input())
matrix = []
answer_list = []
for _ in range(t):
	matrix.append(list(map(int, input().split())))
for row in range(len(matrix)):
	for col in range(1, len(matrix[row])):
		if matrix[row][col - 1] % matrix[row][col] != 0:
			remainder = matrix[row][col - 1] % matrix[row][col]
			answer = matrix[row][col] - remainder
			answer_list.append(answer)
		elif matrix[row][col - 1] % matrix[row][col] == 0:
			answer = matrix[row][col - 1] % matrix[row][col]
			answer_list.append(answer)
for i in answer_list:
	print(i)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a < b:
		print(b - a)
	elif a >= b:
		num = a % b
		if num == 0:
			print(num)
		else:
			num2 = b - num
			ans = num2
			print(ans)


def sum(s):
	ans = 0
	while s > 0:
		ans += s % 10
		s //= 10
	return ans

def fun(n, target):
	(n, target) = (int(n), int(target))
	ans = 0
	if sum(n) <= target:
		return 0
	power = 1
	while sum(n) > target:
		digit = n // power % 10
		add = power * (10 - digit)
		ans += add
		n += add
		power *= 10
	return ans
for _ in range(int(input())):
	(start, target) = input().split()
	print(fun(start, target))


t = int(input())
while t > 0:
	inp = list(map(int, input().split()))
	temp = inp[0] % inp[1]
	if temp == 0:
		print(0)
	else:
		print(inp[1] - temp)
	t -= 1


x = int(input())
for i in range(x):
	(a, b) = map(int, input().split(' '))
	y = a // b
	if a % b == 0:
		print(0)
	else:
		print(b * (y + 1) - a)


n = int(input())
x = []
for i in range(0, n):
	a = list(map(int, input().split()))
	x.append(a)
for j in range(0, n):
	if x[j][0] >= x[j][1]:
		if x[j][0] % x[j][1] != 0:
			y = int(x[j][0] / x[j][1])
			z = y + 1
			print(x[j][1] * z - x[j][0])
		else:
			print(0)
	else:
		print(x[j][1] - x[j][0])


def sd(n):
	sm = 0
	while n > 0:
		sm += n % 10
		n = n // 10
	return sm

def lis(n):
	l = []
	while n > 0:
		l.append(n % 10)
		n = n // 10
	l.reverse()
	return l
T = int(input())
for t in range(T):
	(n, s) = map(int, input().split())
	sm = sd(n)
	n_s = lis(n)
	ind = len(n_s) - 1
	exp = 1
	cnt = 0
	while ind >= 0 and sm > s:
		sm = sm + 1
		sm = sm - n_s[ind]
		cnt = cnt + (10 - n_s[ind]) * exp
		exp *= 10
		ind -= 1
		while ind >= 0 and n_s[ind] == 9:
			ind = ind - 1
			sm = sm - 9
			exp = exp * 10
		if ind >= 0:
			n_s[ind] = n_s[ind] + 1
	print(cnt)


def f(y):
	c = 0
	while y > 0:
		c = c + y % 10
		y = y // 10
	return c
t = int(input())
for i in range(t):
	(n, s) = map(int, input().split())
	if f(n) <= s:
		print(0)
	else:
		for j in range(1, 19):
			x = n + 10 ** j - n % 10 ** j
			if f(x) <= s:
				print(x - n)
				break


def count_moves(a, b):
	return (b - a % b) % b
number_of_tests = int(input())
for _ in range(number_of_tests):
	(a, b) = [int(x) for x in input().split()]
	result = count_moves(a, b)
	print(result)


a = int(input())
mod = pow(10, 9)
while a != 0:
	a = a - 1
	(p, q) = map(int, input().split(' '))
	if p % q == 0:
		print('0')
	else:
		print((q - p) % q)


d = []
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	c = b - a % b
	if c != b:
		d.append(c)
	else:
		d.append(0)
for i in d:
	print(i)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		print((divmod(a, b)[0] + 1) * b - a)


def a(n, s):
	if sum((ord(x) - 48 for x in str(n))) <= s:
		return 0
	return 10 - n % 10 + 10 * a(n // 10 + 1, s) if n % 10 else 10 * a(n // 10, s)
for t in range(int(input())):
	print(a(*map(int, input().split())))


for i in [0] * int(input()):
	(q, w) = map(int, input().split())
	t = q % w
	print([w - t, 0][t == 0])


n = int(input())
v1 = 0
for i in range(1, n + 1):
	(v, d) = map(int, input().split())
	if v % d == 0:
		print(0)
	else:
		a = d - v % d
		print(a)


from sys import stdout
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		stdout.write('0\n')
		continue
	t = b - (a - b * (a // b))
	stdout.write(f'{t}\n')


t = int(input())
result = []
for i in range(t):

	def find(a, b):
		x = a % b
		result.append(b - x)
	(a, b) = [int(j) for j in input().split()]
	if a % b == 0:
		result.append(0)
	elif b > a:
		result.append(b - a)
	else:
		find(a, b)
for i in range(t):
	print(result[i])


def calcsum(n):
	res = 0
	while n:
		(n, m) = divmod(n, 10)
		res += m
	return res
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	if calcsum(n) <= s:
		print(0)
		continue
	c = 1
	while True:
		c *= 10
		cs = calcsum(n - n % c) + 1
		if cs <= s:
			break
	print(c - n % c)


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math
from collections import defaultdict

def su(n):
	res = 0
	while n > 0:
		res += n % 10
		n //= 10
	return res
for _ in range(ri()):
	(n, s) = ria()
	if su(n) <= s:
		print(0)
		continue
	p = 1
	ans = 0
	for i in range(18):
		d = n // p % 10
		add = p * ((10 - d) % 10)
		n += add
		ans += add
		if su(n) <= s:
			break
		p *= 10
	wi(ans)


t = input()
t = int(t)
for tt in range(0, t):
	(a, b) = input().split()
	(a, b) = (int(a), int(b))
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def solve(a, b, x, y, n):
	temp = min(b - y, n)
	b -= temp
	n -= temp
	temp = min(a - x, n)
	a -= temp
	n -= temp
	return a * b

def main():
	try:
		(a, b) = In()
		an = 1
		l = list(str(a))
		n = len(l)
		tsum = 0
		masu = 1
		for x in range(n):
			tsum += int(l[x])
		if tsum == b:
			print(0)
		elif tsum < b:
			print(0)
		else:
			pos = -1
			temp = 0
			for i in range(n - 1, -1, -1):
				if tsum - temp + 1 <= b:
					pos = i
					break
				temp += int(l[i])
			if pos == -1:
				ans = []
				q = 0
				for i in range(n - 1, -1, -1):
					if q == 0:
						if int(l[i]) == 0:
							ans.insert(0, str(0))
						else:
							ans.insert(0, str(10 - int(l[i])))
							q = 1
					else:
						ans.insert(0, str(9 - int(l[i])))
				print(int(''.join(ans)))
			else:
				ans = []
				q = 0
				for i in range(n - 1, pos, -1):
					if q == 0:
						if int(l[i]) == 0:
							ans.insert(0, str(0))
						else:
							ans.insert(0, str(10 - int(l[i])))
							q = 1
					else:
						ans.insert(0, str(9 - int(l[i])))
				print(int(''.join(ans)))
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


def sumdigits(n):
	acc = 0
	while n != 0:
		acc = acc + n % 10
		n = n // 10
	return acc
t = int(input())
for i in range(t):
	(a, b) = [int(j) for j in input().split()]
	result = 0
	moder = 10
	while True:
		suma = sumdigits(a)
		if suma <= b:
			break
		lastdigit = a % moder
		if lastdigit != 0:
			a = a + (moder - lastdigit)
			result += moder - lastdigit
		moder *= 10
	print(result)


for i in range(int(input())):
	(A, B) = [int(i) for i in input().split(' ')]
	if A % B == 0:
		print(0)
	else:
		print(B - A % B)


n = int(input())
list1 = []
for i in range(n):
	(a, b) = map(int, input().split())
	if a % b == 0:
		list1.append(0)
	else:
		ans = (int(a / b) + 1) * b - a
		list1.append(ans)
print(*list1, sep='\n')


def dsum(x):
	res = 0
	while x:
		res += x % 10
		x //= 10
	return res
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	p = 1
	ans = 0
	csum = dsum(n)
	while csum > s:
		add = 10 * p - n % (10 * p)
		if add == 10 * p:
			add = 0
		ans += add
		n += add
		csum = dsum(n)
		p *= 10
	print(ans)


t = int(input())

def sum(tmp):
	result = 0
	for i in str(tmp):
		result += int(i)
	return result

def solve(n, s):
	if sum(n) <= s:
		return 0
	n = str(n)
	i = 0
	while s - int(n[i]) > 0:
		s -= int(n[i])
		i += 1
	tmp = n[i:]
	return 10 ** len(tmp) - int(tmp)
for i in range(t):
	(n, s) = map(int, input().split())
	print(solve(n, s))


def solve():
	A = list(map(int, input().split()))
	x = A[0] % A[1]
	if x == 0:
		print(0)
	elif A[0] > A[1]:
		print(A[1] - x)
	else:
		print(A[1] - A[0])
T = int(input())
for i in range(T):
	solve()


import math
import sys
import re
n = int(input())
for x in range(n):
	(a, b) = map(int, input().rstrip().split())
	c = a % b
	if c == 0:
		print(0)
	else:
		print(b - c)


def main():
	t = int(input())
	for tt in range(t):
		(n, s) = input().split()
		s = int(s)
		k = len(n) + 1
		stt = int(n)
		n = [0] + [int(i) for i in n]
		if sum(n) <= s:
			print(0)
			continue
		bst = 10 ** (k - 1)
		for i in range(1, k):
			if n[i] == 0:
				continue
			new = n.copy()
			new[i - 1] += 1
			new[i:] = [0] * (k - i)
			if sum(new) > s:
				continue
			nm = 0
			for j in range(k):
				nm = nm * 10 + new[j]
			if bst - stt >= nm - stt:
				bst = nm
		print(bst - stt)
main()


N = int(input())
for _ in range(N):
	data = input()
	split = data.split()
	a = int(split[0])
	b = int(split[1])
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


t = int(input())

def f(temp_n):
	total = 0
	while temp_n > 0:
		total += temp_n % 10
		temp_n = temp_n // 10
	return total
for _ in range(t):
	(n, target) = map(int, input().split())
	pw = 1
	res = 0
	while f(n) > target:
		digit = n // pw % 10
		add = pw * ((10 - digit) % 10)
		n += add
		res += add
		pw *= 10
	print(res)


import math
t = int(input())
while t != 0:
	t -= 1
	c = list(map(int, input().rsplit()))
	a = c[0]
	b = c[1]
	if a % b == 0:
		print(0)
	elif a < b:
		print(b - a)
	else:
		f = math.ceil(a / b)
		print(f * b - a)


from math import *
for ct in range(int(input())):
	(n, s) = input().split()
	s = int(s)
	t1 = sum([int(i) for i in n])
	if t1 <= s:
		print(0)
	else:
		res = ''
		soma = 0
		for i in range(len(n)):
			soma += int(n[i])
			if soma >= s:
				for j in range(i, len(n)):
					res += str(10 - int(n[j]) - 1)
				break
		print(int(res) + 1)


inp = int(input())
x = 0
y = True
t = 0
for num in range(inp):
	inp1 = input().split()
	y = True
	while y:
		if int(inp1[0]) < int(inp1[1]):
			x = int(inp1[1]) - int(inp1[0])
			print(x)
			x = 0
			y = False
		elif int(inp1[0]) % int(inp1[1]) != 0:
			t = int(inp1[0]) // int(inp1[1])
			t += 1
			x = int(inp1[1]) * t - int(inp1[0])
			print(x)
			x = 0
			t = 0
			y = False
		else:
			print(x)
			x = 0
			y = False


T = int(input())
while T > 0:
	(a, b) = map(int, input().split(' '))
	if a % b == 0:
		print('0')
	else:
		x = a % b
		print(b - x)
	T -= 1


from sys import stdin
from math import ceil, gcd

def sumdigit(n):
	s = 0
	while n:
		s += n % 10
		n //= 10
	return s
for _ in range(int(stdin.readline())):
	(n, s) = map(int, stdin.readline().split())
	N = n
	if sumdigit(n) <= s:
		print(0)
	else:
		ans = 0
		i = 1
		cond = True
		while sumdigit(n) > s:
			p = 10 ** i
			if p > n:
				cond = False
				break
			if n % p == 0:
				k = n
			else:
				k = p * (n // p + 1)
			ans += k - n
			n = k
			i += 1
		if cond == False:
			print(p - N)
		else:
			print(ans)


import math
lower = int(input(''))
for i in range(0, lower):
	inp = list(map(int, input().split()))
	a = inp[0]
	b = inp[1]
	value = math.ceil(a / b) * b - a
	print(value)


t = int(input())
for _ in range(t):
	ab = input().split()
	n = int(ab[0])
	m = int(ab[1])
	if n % m == 0:
		print('0')
	else:
		q = int(n / m)
		n1 = m * q
		if n * m > 0:
			n2 = m * (q + 1)
		print(n2 - n)


import heapq
t = input()
t = int(t)
for case in range(t):
	a = input().split()
	c = int(a[0])
	d = int(a[1])
	if c % d == 0:
		print(0)
	else:
		ans = c % d
		ans = d - ans
		print(ans)


import sys

def rl():
	return sys.stdin.readline().strip()

def ri():
	return int(sys.stdin.readline().strip())

def rn():
	return list(map(int, sys.stdin.readline().strip().split()))

def rnn():
	return map(int, sys.stdin.readline().strip().split())

def rln(n):
	l = [None] * n
	for i in range(n):
		l[i] = int(rl())
	return l
t = ri()
for _ in range(t):
	(a, b) = rn()
	r = a % b
	solved = False
	if r == 0:
		print(0)
		solved = True
	if not solved:
		if a >= b:
			print(b - r)
		else:
			print(b - a)


t = int(input())

def ck(n, s):
	total = 0
	for e in n:
		total += int(e)
	return total <= s
for i in range(1, t + 1):
	(n, s) = input().split()
	s = int(s)
	mul = 1
	count = 0
	n = list(map(int, n))
	if ck(n, s):
		print(0)
		continue
	for i in range(len(n) - 1, -1, -1):
		dig = n[i]
		add = (10 - dig) % 10
		count += add * mul
		if n[i] != 0:
			n[i - 1] += 1
		n[i] = 0
		mul *= 10
		if ck(n, s):
			break
	print(count)


for i in range(int(input())):
	(a, s) = [x for x in input().split()]
	n = len(a)
	s = int(s)
	lst = []
	for i in a:
		lst.append(int(i))
	su = 0
	i = 0
	while i != n:
		su += lst[i]
		if su > s:
			break
		i += 1
	if i == n:
		print(0)
	else:
		while i != -1:
			if su < s:
				break
			su -= lst[i]
			i -= 1
		if i == -1:
			num = 10 ** n
			print(num - int(a))
		else:
			num = 10 ** (n - i - 1)
			print(num - int(a[i + 1:]))


n = int(input())
Result = []
for i in range(0, n):
	List = list(map(int, input().strip().split()))[0:2]
	a = List[0]
	b = List[1]
	residue = a % b
	if residue == 0:
		Result.append(0)
	else:
		Res = b - residue
		Result.append(Res)
for i in Result:
	print(i)


import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def LS():
	return sys.stdin.readline().split()

def S():
	return input()

def main():
	n = I()
	ans = []
	for _ in range(n):
		(a, b) = LI()
		if a % b == 0:
			ans.append(0)
			continue
		x = a % b
		ans.append(b - x)
	for x in ans:
		print(x)
main()


def possible(n, a):
	rem = n % a
	if rem != 0:
		return a - rem
	else:
		return 0
for _ in range(int(input())):
	(n, a) = map(int, input().split())
	print(possible(n, a))


import math

def main():
	op = ''
	t = int(input())
	for i in range(t):
		(a, b) = map(int, input().split(' '))
		if (a / b).is_integer():
			op += str('0') + '\n'
		else:
			op += str((math.floor(a / b) + 1) * b - a) + '\n'
	print(op)
main()


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
		continue
	tmp = b - a % b
	print(tmp)


for _ in range(int(input())):
	X = list(map(int, input().split()))
	print(0 if X[0] % X[1] == 0 else X[1] - X[0] % X[1])


n = int(input())
res = []
for i in range(n):
	(a, b) = (int(i) for i in input().split(' '))
	cal = (b - a % b) % b
	res.append(cal)
for i in res:
	print(i)


for i in range(int(input())):
	d = list(map(int, input().split()))
	count = 0
	n = 1
	print((d[1] - d[0] % d[1]) % d[1])


(T,) = map(int, input().split())
for _ in range(T):
	(N, s) = map(int, input().split())
	k = len(str(N))
	m = 10 ** k - N
	c = 0
	f = 1
	for l in range(k - 1, -1, -1):
		tmp = N // 10 ** l
		if tmp == 9:
			c += tmp
			N -= tmp * 10 ** l
			continue
		if c + tmp + 1 > s:
			f = 0
		if f:
			m = (tmp + 1) * 10 ** l - N
		c += tmp
		N -= tmp * 10 ** l
	if c <= s:
		m = 0
	print(m)


k = int(input())
i = 0
my_list = []
while i < k:
	t = list(map(int, input().rstrip().split()))
	a = t[0] % t[1]
	b = t[1] - a
	if a == 0:
		my_list.append(0)
	else:
		my_list.append(b)
	i = i + 1
j = 0
while j < k:
	print(my_list[j])
	j = j + 1


n = int(input())
l = list()

def process(x, y):
	r = 0
	if x % y != 0:
		print(y - x % y)
	else:
		print('0')
while n > 0:
	f = [int(x) for x in input().split()]
	l.append(f)
	n -= 1
for i in l:
	process(i[0], i[1])


import sys, math
import io, os
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
from decimal import Decimal
mod = int(1000000000.0) + 7
INF = 2 ** 32

def cal(n):
	ans = 0
	while n:
		ans += n % 10
		n //= 10
	return ans
for t in range(int(data())):
	(n, s) = mdata()
	ans = 0
	t = 1
	while cal(n) > s:
		last = n % 10
		n //= 10
		if last != 0:
			ans += t * (10 - last)
			n += 1
		t *= 10
	out(ans)


n = int(input())
l = list()
for i in range(n):
	l.append(list(map(int, input().split(' '))))
len = len(l)
for i in range(len):
	c = l[i][0] % l[i][1]
	if c == 0:
		print(0)
		continue
	c = l[i][1] - c
	print(c)


for i in range(int(input())):
	(n, s) = map(int, input().split())
	res = '0'
	while sum((int(x) for x in str(n))) > s:
		res = str((10 - n % 10) % 10) + res
		n = n // 10 + 1 * (n % 10 != 0)
	print(int(res) // 10)


T = input()
for t in range(int(T)):
	r = input()
	r = r.split(' ')
	n = int(r[0])
	s = int(r[1])
	digits = []
	sum = 0
	m = n
	while m > 0:
		sum += m % 10
		digits.append(m % 10)
		m = m // 10
	digits.reverse()
	if sum <= s:
		print(0)
	else:
		p = len(digits)
		ans = 10 ** p - n
		v = 0
		for i in range(p):
			v = v + digits[i] * 10 ** (p - i - 1)
			val = v + 10 ** (p - i - 1)
			digit_sum = 0
			c = val
			while c > 0:
				digit_sum += c % 10
				c = c // 10
			if digit_sum <= s:
				if ans > val - n:
					ans = val - n
		print(ans)


def hod(a, b):
	if a > b:
		x = (b - a % b) % b
	else:
		x = b - a
	return x
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	print(hod(a, b))


from sys import stdin, stdout
from math import *
input = stdin.readline
for __ in range(int(input())):
	(n, m) = map(int, input().split())
	if n % m == 0:
		print(0)
	elif n > m:
		print(ceil(n / m) * m - n)
	else:
		print(m - n)


t = int(input())
for _ in range(t):
	(a, b) = input().split()
	(a, b) = (int(a), int(b))
	if a % b == 0:
		minimum = 0
	else:
		minimum = (int(a / b) + 1) * b - a
	print(minimum)


from sys import stdin, stdout
from collections import defaultdict as df
t = int(input())
for i in range(t):
	(a, b) = list(map(int, input().split()))
	if a % b == 0:
		print(0)
	elif a > b:
		y = a // b
		print((y + 1) * b - a)
	else:
		print(b - a)


from math import ceil

def main():
	T = int(input())
	for _ in range(T):
		(a, b) = map(int, input().split())
		print(b * ceil(a / b) - a)
main()


C = int(input())
while True:
	try:
		(A, B) = input().split()
		A = int(A)
		B = int(B)
		if A % B:
			print(abs(B - A % B))
		else:
			print(A % B)
	except EOFError:
		break


T = int(input())
for i in range(T):
	f = 0
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
		f = 1
	if not f:
		c = a + (b - a % b)
		print(c - a)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	print((m - n % m) % m)


def carryAdd(arr, start):
	carry = 1
	n = len(arr)
	for i in range(start, n):
		if arr[i] < 9:
			arr[i] += 1
			carry = 0
			break
		else:
			arr[i] = 0
	if carry == 1:
		arr.append(1)
	return arr
t = int(input())
for _ in range(t):
	x = input().split()
	n = x[0][::-1]
	arr = []
	sum1 = 0
	for i in range(len(n)):
		arr.append(int(n[i]))
		sum1 += arr[-1]
	s = int(x[1])
	n = len(arr)
	if sum1 <= s:
		print(0)
	else:
		for i in range(len(arr) - 1):
			if arr[i] == 0:
				continue
			arr[i] = 0
			if arr[i + 1] < 9:
				arr[i + 1] += 1
			else:
				arr = carryAdd(arr, i + 1)
			sum1 = sum(arr)
			if sum1 <= s:
				break
		sum1 = sum(arr)
		if sum1 > s:
			arr[-1] = 0
			arr.append(1)
		ans = ''
		for i in range(len(arr) - 1, -1, -1):
			ans += str(arr[i])
		ans = int(ans)
		print(ans - int(x[0]))


for nt in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
		continue
	print(b - a % b)


def ok(a, b):
	cnt = 0
	for x in str(a):
		cnt += int(x)
	return cnt <= b
t = int(input())
for i in range(t):
	(n, s) = map(int, input().split())
	if ok(n, s):
		print(0)
	else:
		ans = 0
		ten = 1
		while not ok(n, s):
			cur = n % 10 ** ten
			ans += (10 ** ten - cur) % 10 ** ten
			n += (10 ** ten - cur) % 10 ** ten
			ten += 1
		print(ans)


n = int(input())
c = []
for i in range(n):
	(a, b) = map(int, input().split())
	cnt = 0
	if a < b:
		cnt = b - a
	elif a % b != 0:
		cnt = b - a % b
	c.append(cnt)
for i in c:
	print(i)


def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
entries = inp()
for i in range(entries):
	l = inlt()
	n = l[0]
	k = l[1]
	c = k
	if n % k == 0:
		print(0)
	else:
		m = n // k * k + k
		print(m - n)


import sys
import math
from bisect import bisect_right as br

def int_arr():
	return list(map(int, sys.stdin.readline().split()))

def str_arr():
	return list(map(str, sys.stdin.readline().split()))

def input():
	return sys.stdin.readline().strip()
mod = 1000000007
for _ in range(int(input())):
	(n, k) = int_arr()
	sm = 0
	i = 0
	st = str(n)
	l = len(st)
	flag = 0
	s = 0
	for p in st:
		s += int(p)
	if s <= k:
		print(0)
		continue
	elif l == 1:
		print(10 - n)
		continue
	elif int(st[0]) + 1 > k:
		print(int(str(1) + '0' * l) - n)
		continue
	while i < l:
		if sm + int(st[i]) + 1 > k:
			big = int(str(int(st[i - 1]) + 1) + '0' * (l - i))
			diff = big - int(st[i - 1:])
			print(diff)
			break
		else:
			sm += int(st[i])
			i += 1


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	m = a // b + (a % b > 0)
	print(m * b - a)


t = int(input())
for T in range(t):
	L = list(map(int, input().split()))
	a = L[0]
	b = L[1]
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


from functools import reduce
import operator
import itertools
from bisect import bisect_left
t = int(input())

def solve():
	(n, x) = map(int, input().split(' '))
	print(x - n % x if n % x else 0)
for i in range(t):
	solve()


from math import *
n = int(input())
ans = []

def fun(List):
	(x, y) = (int(List[0]), int(List[1]))
	m = ceil(x / y)
	return y * m - x
for i in range(n):
	lis = list(input().split(' '))
	ans.append(fun(lis))
for i in range(n):
	print(ans[i])


t = int(input())
while t > 0:
	(a, b) = [int(x) for x in input().split()]
	if a <= b:
		print(b - a)
	else:
		lower = int(a / b)
		if a % b == 0:
			print('0')
		else:
			goal = b * (lower + 1)
			print(goal - a)
	t = t - 1


import sys

def input():
	return sys.stdin.readline()[:-1]

def main():
	t = int(input())
	for _ in range(t):
		(a, b) = map(int, input().split())
		if a % b == 0:
			print(0)
		else:
			print(b - a % b)
main()


t = int(input())
while t > 0:
	raw = input().split(' ')
	n = raw[0]
	s = int(raw[1])
	sum = 0
	res = 0
	for i in n:
		sum += int(i)
	if s >= sum:
		print(0)
	else:
		sum = 0
		idx = 0
		while sum + int(n[idx]) < s:
			sum += int(n[idx])
			idx += 1
		res = 0
		base = int(n[idx:])
		res += pow(10, len(n[idx:])) - base
		print(res)
	t -= 1


testes = int(input())
for t in range(testes):
	ent = input().split(' ')
	a = int(ent[0])
	b = int(ent[1])
	r = a % b
	if r != 0:
		print(b - r)
	else:
		print(r)


n = int(input())
for i in range(n):
	a = list(map(int, input().rstrip().split()))
	resto = a[0] % a[-1]
	if resto > 0:
		print(a[-1] - resto)
	else:
		print(resto)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if b > a:
		print(b - a)
	elif a % b == 0:
		print(0)
	else:
		i = a // b + 1
		num_up = b * i - a
		print(num_up)


n = int(input())
for i in range(n):
	arr = input().split(' ')
	count = 0
	a = int(arr[0])
	b = int(arr[1])
	if a <= b:
		print(abs(a - b))
	elif a % b != 0:
		c = a // b + 1
		print(int(c * b - a))
	else:
		print(count)


from math import factorial, ceil
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 1000000007
INF = float('inf')

def main():
	for _ in range(N()):
		(a, b) = RL()
		print(ceil(a / b) * b - a)
main()


import math
t = int(input())
for w in range(t):
	(n, s) = (int(i) for i in input().split())
	s1 = str(n)
	k = len(s1)
	s2 = 0
	for i in s1:
		s2 += int(i)
	if s2 <= s:
		print(0)
	elif k == 1:
		print(10 - n)
	else:
		c = 0
		s3 = 0
		for i in range(k - 1, 0, -1):
			s3 += int(s1[i])
			if int(s1[i - 1]) != 9:
				if s2 - s3 + 1 <= s:
					c = 1
					k2 = i - 1
					break
			else:
				continue
		if c == 1:
			j = s1[:k2] + str(int(s1[k2]) + 1) + '0' * (k - k2 - 1)
			print(int(j) - n)
		else:
			j = '1' + '0' * k
			print(int(j) - n)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a % b:
		if a > b:
			x = a // b
			y = b * (x + 1)
			print(y - a)
		else:
			print(b - a)
	else:
		print(0)


def sum(s):
	cnt = 0
	for i in range(len(s)):
		cnt += ord(s[i]) - ord('0')
	return cnt
for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	s = str(n)
	now = sum(s)
	if now <= k:
		print(0)
		continue
	bl = False
	for i in range(len(s) - 2, -1, -1):
		if s[i] == '9':
			s = s[:i] + '0' * (len(s) - i)
			continue
		char = chr(ord(s[i]) + 1)
		s = s[:i] + char + '0' * (len(s) - i - 1)
		now = sum(s)
		if now <= k:
			bl = True
			break
	if bl == False:
		s = '1' + '0' * len(s)
	opa = int(s)
	print(opa - n)


def check(li, n):
	for ele in li:
		moves = 0
		(a, b) = (ele[0], ele[1])
		if a % b == 0:
			moves = 0
		else:
			c = a // b
			c += 1
			d = b * c
			moves = d - a
		print(moves)
	return
n = int(input())
li = [[int(j) for j in input().split()] for i in range(n)]
check(li, n)


q = int(input())
for _ in range(q):
	(a, b) = map(int, input().split())
	temp = a % b
	if temp == 0:
		print(0)
	else:
		print(b - temp)


result = []
total_test_case = int(input())
for i in range(total_test_case):
	(first_number, second_number) = map(int, input().split())
	if first_number % second_number == 0:
		result.append(0)
	elif first_number < second_number:
		result.append(second_number - first_number)
	else:
		reminder = int(first_number / second_number) + 1
		a = second_number * reminder - first_number
		result.append(a)
for i in range(total_test_case):
	print(result[i])


import functools
import logging
import os
import sys
import time
from typing import List
logger = logging.getLogger()
reader = sys.stdin
is_judge = os.getenv('DEBUGGING') is None

def timeit(func):

	@functools.wraps(func)
	def timed(*args, **kwargs):
		if is_judge:
			rv = func(*args, **kwargs)
		else:
			ts = time.time()
			rv = func(*args, **kwargs)
			te = time.time()
			logger.debug('performance %r %2.2fms', func.__name__, (te - ts) * 1000)
		return rv
	return timed

def read_ints():
	return [int(v) for v in reader.readline().strip().split(' ')]

def main():
	n = read_ints()[0]
	for i in range(n):
		(a, b) = read_ints()
		m = a % b
		if m == 0:
			print(0)
		else:
			print(b - m)

def setup():
	global logger, reader
	if is_judge:
		logger.setLevel(logging.WARNING)
	else:
		handler = logging.StreamHandler(sys.stdout)
		handler.setLevel(logging.DEBUG)
		formatter = logging.Formatter('{asctime}s - {message}', style='{')
		handler.setFormatter(formatter)
		logger.addHandler(handler)
		logger.setLevel(logging.DEBUG)
		reader = open('input.txt')
setup()
try:
	main()
except KeyboardInterrupt:
	logger.debug('KeyboardInterrupt')
except IOError as e:
	logger.error(f'I/O error({e.errno}): {e.strerror}')


from collections import defaultdict
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	ans = (b - a % b) % b
	print(ans)


n = int(input())
for i in range(n):
	ar = [int(x) for x in input().split()]
	if ar[0] % ar[1] == 0:
		print(0)
		continue
	r = int(ar[0] / ar[1])
	c = ar[1] * (r + 1)
	print(c - ar[0])


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	arr1 = [int(d) for d in list(str(n))]
	arr2 = []
	k = 0
	if sum(arr1) <= s:
		print(0)
		continue
	for i in range(len(arr1)):
		if s - arr1[i] > 0:
			arr2.append(arr1[i])
			s -= arr1[i]
			k += 1
		else:
			break
	str1 = ''
	for i in range(k, len(arr1)):
		str1 += str(arr1[i])
	l = int(str1)
	w = 10 ** (len(arr1) - k)
	print(w - l)


def find(a, b):
	count = 0 if a % b == 0 else b - a % b
	print(count)
n = int(input())
for i in range(0, n):
	(a, b) = list(map(int, input().split()))
	find(a, b)


from sys import stdin, gettrace
if gettrace():
	inputi = input
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def solve():
	(n, s) = input().split()
	s = int(s)
	nn = [0] + list(map(int, n))
	if sum(nn) < s:
		print(0)
		return
	mult = 1
	res = 0
	for i in range(len(nn) - 1, 0, -1):
		if sum(nn) <= s:
			break
		v = nn[i]
		if v != 0:
			res += (10 - v) * mult
			nn[i] = 0
			nn[i - 1] += 1
		mult *= 10
	print(res)

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


def solution(str_n, s):
	S = 0
	for j in str_n:
		S = S + int(j)
	if S <= s:
		print(0)
	else:
		S = 0
		p = 0
		while p < len(str_n) and S < s:
			S = S + int(str_n[p])
			p = p + 1
		p = len(str_n) - p + 1
		solution = 1
		for i in range(p):
			solution = solution + (9 - int(str_n[len(str_n) - i - 1])) * 10 ** i
		print(solution)
for j in range(int(input())):
	(str_n, str_s) = input().split()
	solution(str_n, int(str_s))


t = int(input())
answer = []

def sum(n):
	result = 0
	while n > 0:
		result += n % 10
		n = n // 10
	return result
for t in range(t):
	(n, s) = list(map(int, input().split(' ')))
	nv = len(str(n))
	count = 0
	pow = 1
	while sum(n) > s:
		digit = n // pow % 10
		temp = pow * ((10 - digit) % 10)
		count += temp
		n += temp
		pow *= 10
	answer.append(str(int(count)))
print('\n'.join(answer))


def s(n: str):
	r = 0
	for i in n:
		r += int(i)
	return r

def sol(a, b):
	(k, tmp) = (1, a)
	while s(str(tmp)) > b:
		tmp += 10 ** k - tmp % 10 ** k
		k += 1
	return tmp - a
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	print(sol(a, b))


q = int(input())
while q > 0:
	q = q - 1
	n_moves = 0
	(a, b) = map(int, input().split())
	if a % b == 0:
		print('0')
	else:
		print(b - a % b)


a = int(input())
t = []
for i in range(0, a):
	s = input().split()
	if int(s[0]) >= int(s[1]):
		if int(s[0]) % int(s[1]) == 0:
			t.append(0)
		else:
			t.append(int(s[1]) - int(s[0]) % int(s[1]))
	else:
		t.append(int(s[1]) - int(s[0]))
for i in t:
	print(i)


for _ in range(int(input())):
	(number, mx) = input().split()
	number = [i for i in number]
	mx = int(mx)
	su = sum((int(i) for i in number))
	if su <= mx:
		print(0)
		continue
	number = ['0'] + number
	inumber = int(''.join(number))
	ln = len(number)
	res = int(2e+18)
	for i in range(ln):
		nn = number.copy()
		if int(nn[i]) < 9:
			nn[i] = str(int(nn[i]) + 1)
		for j in range(i + 1, ln):
			nn[j] = '0'
		su = sum((int(i) for i in nn))
		inn = int(''.join(nn))
		if inumber <= inn < res and su <= mx:
			res = inn
	print(res - inumber)


from math import ceil
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a < b:
		print(b - a)
	else:
		d = b * ceil(a / b)
		print(d - a)


import sys
input = sys.stdin.readline
for k in range(int(input())):
	(a, b) = map(int, input().split(' '))
	if a < b:
		print(b - a)
	elif a % b == 0:
		print(0)
	else:
		print(b - a % b)


import sys

def read_line():
	return sys.stdin.readline()[:-1]

def read_int():
	return int(sys.stdin.readline())

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]
t = read_int()
for i in range(t):
	(a, b) = read_int_line()
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


def sp():
	return map(int, input().split())

def fun(x):
	return sum((int(i) for i in str(x)))
t = int(input())
for _ in range(t):
	(n, s) = sp()
	x = n
	if fun(x) > s:
		while fun(x + 1) > s:
			x //= 10
		x += 1
	while x < n:
		x *= 10
	print(x - n)


import math

def compute(a, b):
	if a <= b:
		return b - a
	elif a % b == 0:
		return 0
	else:
		nth = math.ceil((a - b) / b) + 1
		return b * nth - a
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	print(compute(a, b))


def vang(n):
	d = 0
	s = 0
	while n:
		d += 1
		s += n % 10
		n = n // 10
	return [d, s]
t = int(input(''))
dig = []
for i in range(t):
	dig.append(list(map(int, input().split())))
for i in dig:
	n = i[0]
	s = i[1]
	num = list(str(n))
	for j in range(len(num)):
		num[j] = int(num[j])
	[ndig, sm] = vang(n)
	if sm <= s:
		print(0)
		continue
	else:
		cnt = 0
		j = len(num) - 1
		asi = 0
		while sm > s:
			d = num[j]
			if sm <= s:
				break
			bodlise = 10 - d
			if d == 0:
				j -= 1
				asi += 1
				continue
			cnt += bodlise * 10 ** asi
			sm -= d
			sm += 1
			j -= 1
			asi += 1
			num[j] += 1
			if j < 0:
				break
		print(cnt)


def suma(num):
	res = 0
	while num > 0:
		res += num % 10
		num = num // 10
	return res
t = int(input())
for _ in range(t):
	(n, s) = map(int, input().split())
	_n = n
	k = 10
	if suma(n) > s:
		while True:
			n += k // 10
			if n % k == 0:
				k *= 10
				if suma(n) <= s:
					break
	print(n - _n)


from sys import stdin, stdout
for i in range(int(stdin.readline())):
	(a, b) = map(int, stdin.readline().split())
	answer = b - a % b
	if a % b == 0:
		stdout.write(str(0) + '\n')
	else:
		stdout.write(str(answer) + '\n')


t = int(input())
while t > 0:
	t = t - 1
	(n, s) = map(int, input().split())
	pot = 1
	sum = 0
	while pot <= n:
		sum += n // pot % 10
		pot *= 10
	pot = 1
	ans = 0
	while sum > s:
		if n % 10 == 0:
			if ans > 0:
				sum -= 9
			n = n // 10
			pot *= 10
			continue
		d = 10 - n % 10
		ans += d * pot
		n += d
		pot *= 10
		n = n // 10
		sum = sum - (10 - d) + 1
	print(ans)


x = int(input())
for i in range(x):
	(a, b) = [int(i) for i in input().split()]
	if a % b != 0:
		y = a % b
		z = b - y
		print(z)
	else:
		print(0)


t = int(input())
while t:
	user_input = list(map(int, input().split()))
	digits = []
	i = 0
	total = 0
	temp = user_input[0]
	while temp:
		digits.append(temp % 10)
		temp //= 10
		total += digits[i]
		i += 1
	if total <= user_input[1]:
		print(0)
	else:
		for i in range(0, len(digits)):
			total = total - digits[i] + 1
			if total <= user_input[1]:
				if i == len(digits) - 1:
					number = total
					for j in range(0, len(digits)):
						number *= 10
					solution = number - user_input[0]
					print(solution)
					break
				j = len(digits) - 1
				number = digits[j]
				j -= 1
				while j > i:
					number = number * 10 + digits[j]
					j -= 1
				number += 1
				for j in range(0, i + 1):
					number = number * 10
				solution = number - user_input[0]
				print(solution)
				break
			total -= 1
	t -= 1


from heapq import *
from collections import deque
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():
	q = II()
	for _ in range(q):
		(a, b) = MI()
		r = a % b
		if r:
			print(b - r)
		else:
			print(0)
main()


cases = int(input())

def get_moves_to_divisibility(a, b):
	if a % b == 0:
		return 0
	div_value = b * (a // b + 1)
	return div_value - a
for _ in range(cases):
	vals = input().split(' ')
	print(get_moves_to_divisibility(int(vals[0]), int(vals[1])))


for _ in range(int(input())):
	lst = list(map(int, input().split()))
	a = lst[0]
	b = lst[1]
	if a < b:
		print(b - a)
	if a == b:
		print(0)
	if a > b:
		if a % b == 0:
			print(0)
		else:
			c = int(a / b)
			d = b * (c + 1)
			print(d - a)


from math import *
for i in range(int(input())):
	(a, b) = (int(x) for x in input().split())
	if a < b:
		print(b - a)
	elif a % b == 0:
		print(0)
	else:
		print(b - a % b)


from sys import stdin, stdout

def suum(S):
	return sum(map(int, list(str(S))))

def find(S, K):
	S1 = S
	i = 0
	while suum(S) > K:
		S += 10 ** i - S % 10 ** i
		i += 1
	return S - S1

def main():
	for _ in range(int(stdin.readline())):
		(N, S) = list(map(int, stdin.readline().split()))
		print(find(N, S))
main()


k = int(input())
i = 0
for x in range(k):
	c = input().split()
	if int(c[0]) % int(c[1]) != 0:
		print(int(c[1]) - int(c[0]) % int(c[1]))
	else:
		print('0')


import sys
input = sys.stdin.readline
(inp, ip) = (lambda : int(input()), lambda : [int(w) for w in input().split()])

def cal(n, add):
	global nn
	n = int(''.join(n)) + add
	nn = list(str(n))
	return sum(list(map(int, str(n))))
for _ in range(inp()):
	(n, k) = ip()
	nn = list(str(n))
	if cal(nn, 0) <= k:
		print(int(''.join(nn)) - n)
		continue
	for i in range(len(nn) - 1, -1, -1):
		add = (10 - int(nn[i])) * 10 ** (len(nn) - 1 - i)
		if cal(nn, add) <= k:
			print(int(''.join(nn)) - n)
			break


def solve(a, b):
	x = a % b
	if x:
		print(b - x)
	else:
		print(x)
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	solve(a, b)


def sumDigits(n):
	res = 0
	while n:
		res += n % 10
		n //= 10
	return res
t = int(input())
while t:
	(n, s) = map(int, input().split())
	steps = 0
	multipler = 1
	while sumDigits(n) > s:
		toZero = 10 - n % 10
		if toZero == 10:
			toZero = 0
		steps += multipler * toZero
		n = (n + toZero) // 10
		multipler *= 10
	print(steps)
	t -= 1


t = int(input())
for x in range(t):
	s = input()
	s1 = s.split()
	sum1 = int(s1[1])
	sum2 = 0
	s = s1[0]
	flag = 0

	def fun(s):
		sum2 = 0
		for i in range(len(s)):
			sum2 = sum2 + int(s[i])
		if sum2 <= sum1:
			return 0
		else:
			return -1
	if fun(s) == 0:
		print(0)
	else:
		for i in range(len(s) - 1, -1, -1):
			rem = int(''.join(['1'] + ['0'] * (len(s) - i))) - int(s[i:])
			if fun(str(rem + int(s))) == 0:
				print(rem)
				break


def div(x, y):
	r = x % y
	return y - r
t = int(input())
for i in range(t):
	(x, y) = [int(v) for v in input().split(' ')]
	if x % y == 0:
		print(0)
	else:
		print(div(x, y))


import math as m
t = int(input())
for i in range(t):
	delta = 0
	(a, b) = map(int, input().split())
	if a % b != 0:
		delta = (int(a / b) + 1) * b - a
	print(delta)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	res = 0
	rem = a % b
	res = b - rem
	if rem == 0:
		print(rem)
	else:
		print(res)


def sumDigits(string):
	ans = 0
	for char in string:
		ans += ord(char) - ord('0')
	return ans

def solve(string, maxSum):
	if sumDigits(string) <= maxSum:
		return string
	for i in range(len(string) - 2, -1, -1):
		if string[i] == '9':
			continue
		newString = string[:i] + chr(ord(string[i]) + 1) + '0' * (len(string) - i - 1)
		if sumDigits(newString) <= maxSum:
			return newString
	return '1' + '0' * len(string)
t = int(input())
for _ in range(t):
	(n, s) = input().split()
	sumMax = int(s)
	final = solve(n, sumMax)
	print(int(final) - int(n))


for i in range(int(input())):
	(a, b) = map(int, input().split())
	from math import ceil as d
	c = d(a / b)
	if a >= b:
		print(b * c - a)
	else:
		print(b - a)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	bb = b
	can = 0
	d = 10000000000000000000
	while d > 0:
		bb = bb - a // d % 10
		d = d // 10
	if bb >= 0:
		can = 1
	d = 10000000000000000000
	t = 0
	while d > 0 and b - a // d % 10 >= 1:
		b = b - a // d % 10
		t = (a // d + 1) * d
		d = d // 10
	if can:
		print(0)
	else:
		print(t - a)
	t = 0


t = int(input())
while t:
	t -= 1
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if a <= b:
		print(b - a)
	elif a % b == 0:
		print(0)
	else:
		res = a // b
		mul_res = b * (res + 1)
		print(mul_res - a)


import math
t = int(input())
for _ in range(t):
	l = list(map(int, input().split(' ')))
	a = l[0]
	b = l[1]
	if a <= b:
		print(b - a)
		continue
	else:
		x = math.ceil(a / b)
		print(abs(b * x - a))


def sumofdigit(n):
	sum = 0
	while n:
		sum += n % 10
		n = n // 10
	return sum
t = int(input())
for _ in range(t):
	(n, s) = list(map(int, input().strip().split()))
	N = n
	fact = 10
	while 1:
		if sumofdigit(n) <= s:
			break
		temp = fact - n % fact
		n = n + temp
		fact = fact * 10
	print(n - N)


def dsum(num):
	s = 0
	while num > 0:
		s += num % 10
		num //= 10
	return s
T = int(input())
for t in range(T):
	(num, s) = [int(x) for x in input().strip().split(' ')]
	pow10 = 1
	current_added = 0
	for i in range(18):
		if dsum(num) <= s:
			break
		pos = (10 - num // pow10 % 10) * pow10
		num += pos
		current_added += pos
		pow10 *= 10
	print(current_added)


t = int(input())
while t:
	t = t - 1
	(n, s) = map(int, input().split())
	n = str(n)
	summ = 0
	for i in range(len(n)):
		summ += int(n[i])
	if summ <= s:
		print(0)
	else:
		summ = 0
		for i in range(len(n)):
			summ += int(n[i])
			if summ >= s:
				n2 = n[i:len(n)]
				break
		minusstr = '1'
		minusstr += '0' * len(n2)
		n2 = int(n2)
		print(int(minusstr) - n2)


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	if n <= d:
		print(abs(n - d))
	elif n % d:
		print(d * (n // d + 1) - n)
	else:
		print(0)


x = int(input())
for i in range(x):
	d = list(map(int, input().split()))
	print((d[1] - d[0] % d[1]) % d[1])


t = int(input())
l = []
for i in range(t):
	(a, b) = map(int, input().strip().split())
	m = a % b
	if m == 0:
		l.append(m)
	else:
		l.append(b - m)
for i in l:
	print(i)


t = int(input())
i = 0
k = 0
while i < t:
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)
	i += 1


import sys
import math
for _ in range(int(input())):
	(n, s) = input().split()
	n1 = int(n)
	n = list(n)
	n = ['0'] + n
	ln = len(n)
	s1 = 0
	s = int(s)
	for i in n:
		s1 += int(i)
	if s1 <= s:
		print(0)
		continue
	for i in range(ln - 1, -1, -1):
		flag = 0
		s1 -= int(n[i])
		for j in range(int(n[i]) + 1, 10):
			if s1 + j <= s:
				n[i] = str(j)
				flag = 1
				break
		if flag == 1:
			break
		n[i] = '0'
	print(int(''.join(n)) - n1)


INT_MAX = 10 ** 18 + 7

def INPUT():
	return list((int(i) for i in input().split()))

def LIST_1D_ARRAY(n):
	return [0 for _ in range(n)]

def LIST_2D_ARRAY(m, n):
	return [[0 for _ in range(n)] for _ in range(m)]
import math as M
for _ in range(int(input())):
	(a, b) = INPUT()
	if a <= b:
		print(b - a)
	else:
		print(b * M.ceil(a / b) - a)


t = int(input())
for i in range(t):
	(a, b) = tuple(map(int, input().split()))
	if a % b == 0:
		print(0)
		continue
	print((a // b + 1) * b - a)


t = int(input())
for i in range(t):
	lt = input().split()
	a = int(lt[0])
	b = int(lt[1])
	ch = 0
	if a % b == 0:
		print(0)
	elif b > a:
		print(b - a)
	else:
		ch = a % b
		print(b - ch)


x = int(input())
for i in range(x):
	y = str(input())
	x = y.split(' ')
	a = int(x[0])
	b = int(x[1])
	increament = 0
	if a % b == 0:
		print(0)
	else:
		print(b * (int(a / b) + 1) - a)


t = int(input())
for i in range(t):
	(s, p) = map(int, input().split())
	if s % p == 0:
		print('0')
	else:
		x = s % p
		v = p - x
		print(v)


for t in range(int(input())):
	(a, b) = map(int, input().split())
	s = b - int(a % b)
	if a % b == 0:
		s = 0
	print(s)


import sys, os.path
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
sys.setrecursionlimit(10 ** 5)

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def solve():
	(a, b) = MI()
	if a % b != 0:
		print((a // b + 1) * b - a)
	else:
		print(0)
for _ in range(II()):
	solve()


import sys
from functools import reduce
from collections import Counter
import time
import datetime
from math import sqrt, gcd

def ip():
	return int(sys.stdin.readline())

def sip():
	return sys.stdin.readline()

def mip():
	return map(int, sys.stdin.readline().split())

def mips():
	return map(str, sys.stdin.readline().split())

def lip():
	return list(map(int, sys.stdin.readline().split()))

def matip(n, m):
	lst = []
	for i in range(n):
		arr = lip()
		lst.append(arr)
	return lst

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def minJumps(arr, n):
	jumps = [0 for i in range(n)]
	if n == 0 or arr[0] == 0:
		return float('inf')
	jumps[0] = 0
	for i in range(1, n):
		jumps[i] = float('inf')
		for j in range(i):
			if i <= j + arr[j] and jumps[j] != float('inf'):
				jumps[i] = min(jumps[i], jumps[j] + 1)
				break
	return jumps[n - 1]

def dic(arr):
	return Counter(arr)

def check_prime(n):
	if n < 2:
		return False
	for i in range(2, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			return False
	return True

def sum_(n):
	su = 0
	while n > 0:
		su += n % 10
		n = n // 10
	return su
N = ip()
while N:
	N -= 1
	(a, b) = mip()
	k = sum_(a)
	if k <= b:
		print(0)
	else:
		mul = 1
		while 1:
			mul *= 10
			val = a // mul
			val += 1
			val *= mul
			if sum_(val) <= b:
				break
		print(val - a)


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	z = x // y
	if x % y != 0:
		print((z + 1) * y - x)
	else:
		print(0)


def getSteps(a, b):
	if a % b == 0:
		return 0
	else:
		return (a // b + 1) * b - a
n = int(input())
for i in range(n):
	inp = input().split()
	a = int(inp[0])
	b = int(inp[1])
	print(getSteps(a, b))


import sys

def gets():
	return sys.stdin.readline().strip()

def get():
	return int(sys.stdin.readline().strip())

def geti():
	return map(int, sys.stdin.readline().strip().split())

def getli():
	return list(map(int, sys.stdin.readline().strip().split()))
for _ in range(get()):
	(a, b) = geti()
	if a % b == 0:
		print(0)
	else:
		n = a // b + 1
		print(n * b - a)


tc = int(input())
for jk in range(tc):
	a = input().split(' ')
	for lm in range(len(a)):
		a[lm] = int(a[lm])
	if a[0] % a[1] == 0 and a[0] >= a[1]:
		print(0)
	else:
		s = a[0] // a[1]
		chai = s + 1
		yv = chai * a[1]
		print(yv - a[0])


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve(case):
	(n, s) = strsep()
	n = list(n)
	aim = int(s)
	curr = 0
	for i in range(len(n)):
		curr += int(n[i])
	if curr <= aim:
		print(0)
		return
	cnt = 0
	for i in range(len(n) - 1, -1, -1):
		if n[i] == '0':
			continue
		cnt += (10 - int(n[i])) * 10 ** (len(n) - (i + 1))
		curr += 1
		curr -= int(n[i])
		n[i] = '0'
		if i > 0:
			n[i - 1] = str(int(n[i - 1]) + 1)
		if curr <= aim:
			break
	print(cnt)
testcase(int(inp()))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	x = a // b
	val = (x + 1) * b - a
	print(val % b)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	f = 0
	if a % b == 0:
		print('0')
	elif b > a:
		print(b - a)
	else:
		print(b - a % b)


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
from collections import deque
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	su = sum(list(map(int, list(str(n)))))
	if su <= s:
		print(0)
	else:
		t = 1
		count = 0
		while su > s:
			f = n // t % 10
			if f != 0:
				n += (10 - f) * t
				count += (10 - f) * t
			t *= 10
			su = sum(list(map(int, list(str(n)))))
		print(count)


a = int(input())
for i in range(a):
	(x, y) = list(map(int, input().split()))
	if x % y == 0:
		print(0)
	else:
		k = (x + y) // y * y
		print(k - x)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
from collections import deque

def main():

	def solve():
		(n, s) = input().split()
		n = deque([int(x) for x in n])
		initialN = n.copy()
		s = int(s)
		total = sum(n)
		if total <= s:
			print(0)
			return
		numOfSteps = 0
		roundedStart = -1
		for i in range(len(n)):
			if n[~i] == 0:
				roundedStart += 1
			else:
				break
		while total > s:
			total -= n[~(roundedStart + 1)]
			numOfSteps += (10 - n[~(roundedStart + 1)]) * 10 ** (roundedStart + 1)
			n[~(roundedStart + 1)] = 0
			if roundedStart + 1 < len(n) - 1:
				n[~(roundedStart + 2)] += 1
				current = ~(roundedStart + 2)
				while n[current] >= 10:
					if current == -len(n):
						n.appendleft(0)
					n[current - 1] += n[current] // 10
					total += n[current] // 10
					total -= n[current] // 10 * 10
					n[current] = n[current] % 10
					current -= 1
				total += 1
			else:
				n.appendleft(1)
				total = 1
			roundedStart += 1
		print(numOfSteps)
	t = int(input())
	for i in range(t):
		solve()
BUFFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
input = lambda : sys.stdin.readline().rstrip('\r\n')

def print(*args, **kwargs):
	sep = kwargs.pop('sep', ' ')
	file = kwargs.pop('file', sys.stdout)
	atStart = True
	for x in args:
		if not atStart:
			file.write(sep)
		file.write(str(x))
		atStart = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
main()


from sys import stdin, stdout
DEBUG = True

class Scan:

	def __init__(self):
		self.read = stdin.read
		self.input = stdin.readline

	def integer(self, count=1):
		if count == 1:
			return self._integer()
		return [self._integer() for _ in range(count)]

	def _integer(self):
		sym: str = self.read(1)
		while sym != '-' and (not sym.isdigit()):
			sym = self.read(1)
		(number, sign) = (0, -1) if sym == '-' else (int(sym), 1)
		sym: str = self.read(1)
		while sym.isdigit():
			number = number * 10 + int(sym)
			sym = self.read(1)
		return number * sign

	def array(self, func=int, sep=' '):
		if func == str:
			return input().split(sep)
		return list(map(func, input().split(sep)))

	def string(self, count=1):
		if count == 1:
			return self._string()
		return (self._string() for _ in range(count))

	def _string(self):
		sym = self.read(1)
		while sym in ('\n', '\r', ' '):
			sym = self.read(1)
		s = str()
		while sym not in ('\n', '\r', ' '):
			s += sym
			sym = self.read(1)
		return s

class Write:
	pass

class Number:

	def gcd(self, a, b):
		while b > 0:
			(a, b) = (b, a % b)
		return a

	def lcm(self, a, b):
		return a * b // gcd(a, b)

class Constants:
	EPS = 10 ** (-9)
	INF = 10 ** 18
	MOD = 10 ** 9 + 7
(scan, write) = (Scan(), Write())

def solution():
	(a, b) = scan.integer(2)
	if a % b == 0:
		stdout.write(str(0) + '\n')
	else:
		stdout.write(str((a // b + 1) * b - a) + '\n')

def main():
	queries: int = 1
	queries = scan.integer()
	for _ in range(queries):
		solution()
main()


import math

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())
for _ in range(ii()):
	(a, b) = mi()
	j = math.ceil(a / b)
	print(b * j - a)


def divisible(a, b):
	x = a
	y = b
	if x % y == 0:
		return 0
	if x < y:
		return y - x
	else:
		return y - x % y
n = int(input())
for i in range(n):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	result = divisible(a, b)
	print(result)


import math
t = int(input())
while t:
	(a, b) = list(map(int, input().split()))
	m = math.ceil(a / b)
	d = m * b
	print(d - a)
	t = t - 1


for t in range(int(input())):
	t1 = input().split(' ')
	n = '0' + t1[0]
	s = int(t1[1])
	sum = 0
	f = 0
	a = []
	for i in range(len(n)):
		sum += int(n[i])
		a.append(int(n[i]))
		if sum > s:
			f = i
			break
	if sum > s:
		for j in range(f, -1, -1):
			sum -= a[j]
			a[j] = 0
			a[j - 1] += 1
			sum += 1
			if sum <= s:
				break
	else:
		print(0)
		continue
	i = 1
	sub = 0
	for j in range(f, -1, -1):
		sub += a[j] * i
		i *= 10
	sub = sub * 10 ** (len(n) - f - 1)
	print(abs(sub - int(t1[0])))


import sys
import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b:
		r = a % b
		print(b - r)
	else:
		print('0')


test = int(input())
while test > 0:
	(a, b) = [int(a) for a in input().split()]
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)
	test -= 1


from sys import stdin, stdout
n = int(stdin.readline())
q = list()
for i in range(0, n):
	l = stdin.readline()
	l = l.split(' ')
	l = [int(i) for i in l]
	if l[1] > l[0]:
		q.append(l[1] - l[0])
	elif l[0] % l[1] == 0:
		q.append(0)
	else:
		q.append((l[0] // l[1] + 1) * l[1] - l[0])
for i in q:
	print(i)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	n1 = n
	l = []
	while n:
		l.append(n % 10)
		n = n // 10
	l.append(0)
	x = sum(l)
	i = 0
	while x > k:
		x -= l[i]
		l[i] = 0
		l[i + 1] += 1
		if l[i + 1] < 10:
			x += 1
		else:
			while l[i + 1] == 10:
				l[i + 1] = 0
				l[i + 2] += 1
				x -= 9
				i += 1
			x += 1
		i += 1
	s = ''
	for i in l:
		s = str(i) + s
	print(int(s) - n1)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	a = [int(i) for i in str(n)][::-1]
	sm = sum(a)
	mul = 1
	res = 0
	num = 0
	while sm > s and num < len(a):
		if a[num] > 0:
			res += mul * (10 - a[num])
			cr = 1
			a[num] = 0
			for i in range(num + 1, len(a)):
				a[i] += cr
				cr = a[i] // 10
				a[i] %= 10
			if cr:
				a.append(1)
				cr = 0
		sm = sum(a)
		mul *= 10
		num += 1
	print(res)


from sys import stdin, stdout
a = int(stdin.readline())
for i in range(a):
	s = list(map(int, stdin.readline().split()))
	c = 0
	while s[0] % s[1] != 0:
		d = s[0] // s[1]
		d += 1
		c = s[1] * d - s[0]
		s[0] += c
	print(c)


n = int(input())
while n > 0:
	n = n - 1
	(a, b) = map(int, input().split())
	if a < b:
		print(b - a)
	elif a % b == 0:
		print('0')
	else:
		s = int(a / b)
		x = (s + 1) * b - a
		print(x)


n = int(input())
for i in range(n):
	pair = list(map(int, input().split()))
	if pair[0] % pair[1] == 0:
		print(0)
	else:
		remainder = pair[0] % pair[1]
		print(pair[1] - remainder)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	w = n % m
	print((m - w) % m)


import sys
import math

def ii():
	return sys.stdin.readline().strip()

def idata():
	return [int(x) for x in ii().split()]

def binary_search(array, x):
	(left, right) = (-1, len(array))
	while left + 1 != right:
		middle = (left + right) // 2
		if array[middle] >= x:
			right = middle
		elif array[middle] < x:
			left = middle
	return right

def solve_of_problem():
	(a, b) = idata()
	k = a // b
	z = a % b
	if z == 0:
		print(0)
		return
	if k == 0:
		print(b - a)
		return
	print(b - z)
	return
for ______ in range(int(ii())):
	solve_of_problem()


tc = int(input())
for i in range(tc):
	(a, b) = map(int, input().split())
	c = int(a / b)
	ans = (c + 1) * b
	if a % b == 0:
		ans = a
	print(ans - a)


for t in range(int(input())):
	(n, s) = input().split()
	s = int(s)
	nl = [int(i) for i in n]
	digits = len(nl)
	sum_s = sum(nl)
	while sum_s > s:
		sum_s -= nl.pop()
		while nl and nl[-1] == 9:
			sum_s -= nl.pop()
		if nl:
			nl[-1] += 1
		else:
			nl.append(1)
		sum_s += 1
	n = int(n)
	nl = [str(i) for i in nl]
	while int(''.join(nl)) < n:
		nl.append('0')
	print(int(''.join(nl)) - n)


n = int(input())
l = []
while n:
	l.append([int(x) for x in input().split()])
	n = n - 1
for i in l:
	c = 0
	t = 0
	if i[1] > i[0]:
		t = i[1] - i[0]
	elif i[0] % i[1] != 0:
		a = i[0] % i[1]
		t = i[1] - a
	print(t)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	start_a = a
	t = 0
	s = 0
	for i in str(a):
		s += int(i)
	while s > b:
		s = 0
		for i in str(a):
			s += int(i)
			if s > b:
				break
		if s > b:
			a = (a // 10 ** (len(str(a)) - 1) + 1) * 10 ** (len(str(a)) - 1)
	f_ans = 0
	r = a - start_a
	answer = r
	for i in range(0, len(str(r))):
		s = 0
		some_a = start_a + int(str(r)[i:])
		for j in str(some_a):
			s += int(j)
		if s <= b and some_a - start_a >= 0:
			answer = str(r)[i:]
	print(answer)


def ans(a, b):
	count = 0
	p = 0
	x = 1
	y = 1
	if len(a) < len(b):
		print(int(b) - int(a))
	else:
		d = int(a)
		f = int(b)
		if int(a) % int(b) == 0:
			print(0)
		else:
			print(f - d % f)
t = int(input())
f = 0
while t > 0:
	(a, b) = map(str, input().split())
	if a == b:
		print(0)
	else:
		ans(a, b)
	t -= 1


casos = int(input())
for i in range(casos):
	(a, b) = input().split(' ')
	a = int(a)
	b = int(b)
	if a % b == 0:
		print(0)
		continue
	elif a < b:
		print(b - a)
	else:
		print(b * (a // b + 1) - a)


t = int(input())
cases = []

def func(n, s):
	for i in range(len(n)):
		digit = int(n[i])
		if s > digit:
			s -= digit
		elif digit == s:
			if i == len(n) - 1:
				return 0
			elif all([v == '0' for v in n[i + 1:]]):
				return 0
			else:
				left = len(n) - i
				num = 10 ** left
				remaining = n[i:]
				remaining = int(''.join(remaining))
				return num - remaining
		else:
			left = len(n) - i
			num = 10 ** left
			remaining = n[i:]
			remaining = int(''.join(remaining))
			return num - remaining
	return 0
for i in range(t):
	(n, s) = [int(x) for x in input().split(' ')]
	cases.append([n, s])
for k in cases:
	n = k[0]
	s = k[1]
	n = str(n)
	n = list(n)
	print(func(n, s))


n = int(input())
a = []
b = []
for i in range(n):
	Input = list(map(int, input().split(' ')))
	a.append(Input[0])
	b.append(Input[1])
for i in range(n):
	Output = b[i] - a[i] % b[i]
	print(0 if a[i] % b[i] == 0 else Output)


from sys import stdin, stdout
input = stdin.readline

def su(n):
	ans = 0
	for i in str(n):
		ans += int(i)
	return ans
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	l = su(n)
	ans = 0
	i = 0
	while l > s:
		ans += 10 ** (i + 1) - n % 10 ** (i + 1)
		n += 10 ** (i + 1) - n % 10 ** (i + 1)
		l = su(n)
		i += 1
	stdout.write(str(ans) + '\n')


t = int(input())
for i in range(t):
	count1 = 0
	(a, b) = map(int, input().split())
	k = a % b
	if k == 0:
		print('0')
	elif a <= b:
		c = b - a
		print(c)
	else:
		c = b - k
		print(c)


import math
t = int(input())
while t > 0:
	t -= 1
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		print(math.ceil(a / b) * b - a)


t = int(input())
while t:
	(a, b) = map(int, input().split())
	if a % b == 0 and a > b or a == b:
		print('0')
	elif b > a:
		print(b - a)
	else:
		print(b - a % b)
	t = t - 1


t = int(input())
res = []
for _ in range(t):
	(a, b) = map(int, input().split())
	r = a % b
	if r:
		res.append(b - a % b)
	else:
		res.append(0)
for r in res:
	print(r)


import math
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	summ = 0
	str_n = str(n)
	for i in str_n:
		summ += int(i)
	d = summ - s
	if d <= 0:
		print(0)
	else:
		ans = ''
		m = len(str_n)
		i = m - 1
		while i >= 0 and str_n[i] == '0':
			i -= 1
			ans += '0'
		ans += str(10 - int(str_n[i]))
		d -= int(str_n[i]) - 1
		i -= 1
		if d <= 0:
			ans = ans[::-1]
			print(int(ans))
		else:
			for j in range(i, -1, -1):
				x = int(str_n[j])
				d -= x
				ans += str(10 - (x + 1))
				if d <= 0:
					break
			ans = ans[::-1]
			print(int(ans))


import sys
import math as mt
import collections as cc
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))

def re(n):
	ss = 0
	for i in str(n):
		ss += int(i)
	return ss
for tc in range(int(input())):
	(n, s) = I()
	cur = 1
	st = n
	for i in range(20):
		temp = n % cur
		if temp != 0:
			n += cur - temp
		if re(n) <= s:
			print(n - st)
			break
		cur *= 10


for _ in range(int(input())):
	(a, b) = [int(i) for i in input().split()]
	i = 0
	if a % b != 0:
		c = a // b + 1
		i = b * c - a
	print(i)


def su(x):
	s = 0
	for d in x:
		s += int(d)
	return s
for _ in range(int(input())):
	(n, s) = input().split()
	s = int(s)
	if su(n) <= s:
		print(0)
	else:
		le = len(n) + 1
		ans = ['0']
		for d in n:
			ans.append(d)
		while le > 0:
			ans[le - 1] = '0'
			k = le - 1
			fl = 1
			while fl == 1:
				if ans[k - 1] == '9':
					ans[k - 1] = '0'
					k -= 1
				else:
					ans[k - 1] = str(int(ans[k - 1]) + 1)
					fl = 0
			if su(ans) <= s:
				st = ''.join(ans)
				print(int(st) - int(n))
				break
			else:
				le -= 1


def main():
	n = int(input())
	for _ in range(n):
		(a, b) = [int(x) for x in input().split()]
		if a % b == 0:
			print('0')
		elif a < b:
			print(f'{b - a}')
		else:
			print(f'{b % a - a % b}')
main()


import math

def main():
	for x in range(int(input())):
		arr = list(map(int, input().split()))
		if arr[0] % arr[1] == 0:
			print(0)
		elif arr[0] < arr[1]:
			print(arr[1] - arr[0])
		else:
			print(round((math.ceil(float(arr[0] / arr[1])) - float(arr[0] / arr[1])) * arr[1]))
main()


from collections import defaultdict as dd, deque as dq
import sys
input = sys.stdin.readline
t = int(input())
while t:
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)
	t -= 1


num = int(input())
for i in range(num):
	l = input().split()
	f_n = int(l[0])
	s_n = int(l[1])
	if f_n % s_n != 0:
		print(s_n * (f_n // s_n + 1) - f_n)
	else:
		print(0)


import time
import heapq
import sys
from collections import *
from heapq import *
import math
import bisect
from itertools import *
mod = 10 ** 9 + 7
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	string = str(n)
	summ = 0
	for i in string:
		summ += int(i)
	if summ <= s:
		print(0)
		continue
	i = 0
	summ = 0
	while i < len(string) and summ + int(string[i]) < s:
		summ += int(string[i])
		i += 1
	diff = len(string) - i
	num = n % pow(10, diff)
	print(pow(10, diff) - num)


from fractions import Fraction
from collections import defaultdict
import math
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
t = int(input())
for _ in range(t):
	(n, s) = [int(x) for x in input().split()]
	tmp = n
	ds = 0
	nd = 0
	while tmp != 0:
		nd += 1
		ds += tmp % 10
		tmp = tmp // 10
	if ds <= s:
		print('0')
	elif n <= 1:
		print(1 - n)
	else:
		c = nd - 1
		sm = 0
		k = n
		lc = 0
		lk = 0
		while sm < s:
			sm += k // pow(10, c)
			lk = k
			k = k % pow(10, c)
			lc = c
			c -= 1
		print(pow(10, lc + 1) - lk)


def solution(line, n):
	crnt_sum = 0
	res = []
	for (idx, item) in enumerate(line):
		crnt_sum += item
		if crnt_sum < n:
			res.append(item)
		elif crnt_sum == n and (idx == len(line) - 1 or sum(line[idx + 1:]) == 0):
			res.append(item)
		else:
			res.extend([0] * (len(line) - idx))
			while True:
				if idx == 0:
					res[0] = 0
					res = [1] + res
					break
				elif res[idx - 1] != 9:
					res[idx - 1] += 1
					break
				else:
					res[idx - 1] = 0
					idx -= 1
			return ''.join(tuple(map(str, res)))
	return ''.join(tuple(map(str, res)))
n = int(input())
for _ in range(n):
	(line, n) = input().split()
	z = int(line)
	line = tuple(map(int, list(line)))
	n = int(n)
	print(int(solution(line, n)) - z)


t = int(input())
for e in range(t):
	(x, y) = map(int, input().split())
	if x % y == 0:
		print('0')
	elif x > y:
		q = x % y
		print(y - q)
	else:
		print(y - x)


n = int(input(''))
l = []
for i in range(n):
	(a, b) = [int(x) for x in input('').split()]
	z = (b - a % b) % b
	l.append(z)
for i in l:
	print(i)


t = int(input().strip())
for i in range(t):
	(a, b) = map(int, input().strip().split())
	if a < b:
		print(abs(a - b))
	elif a % b == 0:
		print(0)
	else:
		val = a // b + 1
		val = b * val
		val = val - a
		print(val)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	r = a % b
	if r != 0:
		r = b - r
	print(r)


def sum_digits(n):
	x = n
	ans = 0
	while x > 0:
		ans += x % 10
		x = x // 10
	return ans
t = int(input())
for i in range(t):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	x = a
	if sum_digits(x) > b:
		for i in range(20):
			dig = x % 10 ** (i + 1) // 10 ** i
			if dig != 0:
				x += (10 - dig) * 10 ** i
			if sum_digits(x) <= b:
				break
	print(x - a)


def su(n):
	return sum(list(map(int, str(n))))
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = su(n)
	if s <= m:
		print(0)
	else:
		c = 1
		a = n
		while su(n) > m:
			c *= 10
			n //= 10
			n += 1
		print(n * c - a)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	if n < m:
		print(m - n)
	elif n % m == 0:
		print('0')
	else:
		o = n // m
		y = o + 1
		l = m * y - n
		print(l)


import sys
input = sys.stdin.readline

def getsum(n):
	x = list(str(n))
	sumi = 0
	for i in range(len(x)):
		sumi += int(x[i])
	return sumi
for _ in range(int(input())):
	(n, s) = [int(j) for j in input().split()]
	ans = 0
	i = 0
	while getsum(n) > s:
		temp = 10 ** i - n % 10 ** i
		ans += temp
		n += temp
		i += 1
	print(ans)


t = int(input())
for i in range(t):
	l = list(map(int, input().split()))
	c = 0
	temp = l[0] % l[1]
	if temp == 0:
		print(0)
		continue
	print(l[1] - temp)


n = int(input())
for i in range(n):
	(a, b) = input().split()
	(a, b) = (int(a), int(b))
	if a % b != 0:
		nxt = b * (a // b + 1)
		count = nxt - a
	else:
		count = 0
	print(count)


def divisible(x, y):
	temp = x % y
	if temp == 0:
		return 0
	else:
		return y - temp
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	res = divisible(a, b)
	print(res)


from sys import stdout, stdin
read = stdin.readline
write = stdout.write
t = int(read())
for _ in range(t):
	(a, b) = map(int, read().split())
	c = a % b
	print(b - c if c != 0 else 0)


def moves(n, s):
	d = 10
	P = 0
	k = n
	j = 1
	if S(n) <= s:
		P += 0
	else:
		while S(n) > s:
			dig = k % 10
			C = (10 - dig) * j
			P += C
			n += C
			k = n
			k //= d
			j *= 10
			d *= 10
	print(P)

def S(n):
	J = 0
	while n != 0:
		J += n % 10
		n //= 10
	return J
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	moves(n, s)


from math import *
for k in range(int(input())):
	(b, c) = map(int, input().split())
	res = ceil(b / c)
	print(res * c - b)


def func(b, c):
	if b >= c:
		d = b // c
		if b % c != 0:
			e = c * (d + 1)
			return e - b
		else:
			return 0
	else:
		return c - b
t = int(input())
while t > 0:
	a = input().split()
	print(func(int(a[0]), int(a[1])))
	t = t - 1


def getSum(n):
	sum1 = 0
	while n != 0:
		sum1 = sum1 + 1
		n = n // 10
	return sum1

def getNearest(n):
	c = 10 - n % 10
	c = c + n
	return c

def getSum1(n):
	sum = 0
	while n != 0:
		sum = sum + n % 10
		n = n // 10
	return sum
c = int(input())
for i in range(c):
	(a, b) = [int(x) for x in input().split()]
	res = list(map(int, str(a)))
	if getSum1(a) <= b:
		print('0')
	else:
		e = 0
		g = 0
		h = 0
		f = len(res)
		for i in range(f):
			e = e * 10 + res[i]
			h = i
			g = g + res[i]
			if g >= b:
				break
		e = getNearest(e)
		f = f - (h + 1)
		e = e * 10 ** f
		e = e - a
		print(e)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	num = []
	for d in str(n):
		num.append(int(d))
	if sum(num) <= s:
		print('0')
	else:
		moves = 0
		diff = sum(num) - s
		for i in range(len(num) - 1, -1, -1):
			diff -= num[i]
			if i != 0 and num[i] != 0:
				num[i - 1] += 1
				diff += 1
			if num[i] != 0:
				moves += (10 - num[i]) * 10 ** (len(num) - 1 - i)
			if diff <= 0:
				break
		print(moves)


t = int(input())
while t > 0:
	(s, sum) = map(str, input().split())
	sum = int(sum)
	tsum = 0
	n = len(s)
	num = 0
	q = 0
	for i in range(n):
		q += int(s[i])
	if q <= sum:
		print(0)
		t -= 1
		continue
	for i in range(n):
		if num != 0:
			break
		tsum = tsum + ord(s[i]) - 48
		if tsum >= sum:
			if i > 0:
				ans = (int(s[i - 1]) + 1) * 10 ** (n - i) - int(s[i - 1:])
				print(ans)
				num += 1
			else:
				ans = 10 ** n - int(s)
				print(ans)
				num += 1
	if num == 0:
		print(0)
	t -= 1


for tc in range(int(input())):
	(n, s) = [int(x) for x in input().split()]
	sumOf = sum((int(x) for x in str(n)))
	cost = 0
	carry = False
	for (pos, char) in enumerate(reversed('0' + str(n))):
		if sumOf <= s:
			break
		digit = int(char)
		if carry:
			digit += 1
		if digit != 0:
			carry = True
			cost += (10 - digit) * 10 ** pos
			sumOf -= digit - 1
	print(cost)


def main():
	t = int(input())
	while t > 0:
		t = t - 1
		l = str(input())
		l = l.split()
		a = int(l[0])
		b = int(l[1])
		fun(a, b)

def fun(a, b):
	if a % b == 0:
		print('0')
	else:
		print(b - a % b)
main()


tot = int(input())
string = ''
for _ in range(tot):
	(a, b) = map(int, input().split())
	if a % b == 0:
		string += '0\n'
	else:
		string += str(b - a % b) + '\n'
print(string)


t = int(input())
for xx in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		z = (a // b + 1) * b - a
		print(z)


def solve():
	(a, b) = map(int, input().split())
	if a % b == 0:
		resh = 0
	else:
		ost = a % b
		resh = b - ost
	print(resh)
t = int(input())
for i in range(t):
	solve()


cf = int(input())
for _ in range(cf):
	(sn, x) = input().split()
	x = int(x)
	n = [0] * len(sn)
	s = 0
	for i in range(len(n)):
		n[i] = int(sn[i])
		s += n[i]
	if s <= x:
		print(0)
		continue
	ans = 0
	deg = -1
	for i in range(len(n) - 1, -1, -1):
		deg += 1
		if n[i] == 0:
			continue
		ans += (10 - n[i]) * 10 ** deg
		if i == 0:
			break
		n[i] = 0
		for j in range(i - 1, -1, -1):
			if n[j] < 9:
				n[j] += 1
				break
			n[j] = 0
			if j == 0:
				n = [1] + n
				break
		s = 0
		for j in range(len(n)):
			s += n[j]
		if s <= x:
			break
	print(ans)


n = int(input())
for t in range(n):
	(a, b) = map(int, input().split())
	if a < b:
		print(b - a)
	elif a == b:
		print(0)
	elif a % b == 0:
		print(0)
	else:
		f = a + (b - a % b)
		print(f - a)


import collections, heapq, itertools, math
groupby = itertools.groupby
ri = lambda : int(input())
rm = lambda : map(int, input().split())

def solve(a, b):
	return math.ceil(a / b) * b - a
for t in range(1, 1 + ri()):
	(a, b) = rm()
	ans = solve(a, b)
	print('{}'.format(ans))


t = int(input())
import math

def get_min_moves(a, b):
	bb = math.ceil(a / b)
	bbb = b * bb
	return bbb - a
for _ in range(t):
	(a, b) = map(int, input().split())
	min_moves = get_min_moves(a, b)
	print(min_moves)


from sys import stdin, stdout
from collections import defaultdict, Counter
from functools import lru_cache
from math import gcd, floor, ceil

def ilist():
	return [int(x) for x in stdin.readline().strip().split(' ')]

def iint():
	return int(stdin.readline().strip())

def istr():
	return stdin.readline().strip()
t = iint()
for _x in range(t):
	(m, n) = ilist()
	k = ceil(m / n) * n
	print(k - m)


n = int(input())
for x in range(0, n):
	k = list(map(int, input().split()))
	if k[0] % k[1] == 0:
		print('0')
	else:
		print(k[1] - k[0] % k[1])


t = int(input())
while t:
	(n, num) = map(int, input().split())
	s = str(n)
	a = []
	ans = [0]
	for i in s:
		p = int(i)
		a.append(p)
		ans.append(0)
	i = len(a) - 1
	count = 0
	mul = 1
	check = 0
	while i > 0:
		if sum(a) > num:
			count = count + (10 - a[i]) * mul
			a[i] = 0
			a[i - 1] = a[i - 1] + 1
			i = i - 1
			mul = mul * 10
			if sum(a) <= num:
				check = 1
				break
		else:
			check = 1
			break
	if check:
		print(count)
	elif sum(a) <= num:
		print(0)
	else:
		print(mul * 10 - n)
	t = t - 1


tx = int(input())
for i in range(tx):
	(a, b) = [int(i) for i in input().split()]
	k = a
	t = 1
	t2 = 0
	s = str(a)
	for i in s:
		t2 += ord(i) - ord('0')
	while t <= pow(10, 18):
		if t > 1:
			a += t - a % t
		t2 = 0
		s = str(a)
		for i in s:
			t2 += ord(i) - ord('0')
		if t2 <= b:
			print(a - k)
			break
		t *= 10


import math as m
for i in range(int(input())):
	(n, k) = map(int, input().split())
	ans = 0
	if n < k:
		ans = k - n
	elif n % k != 0:
		s = m.ceil(n / k)
		ans = k * s - n
	print(ans)


T = int(input())
while T:
	(n, s) = input().split()
	n = int(n)
	s = int(s)
	tmp = n
	sum = 0
	while tmp:
		sum += tmp % 10
		tmp //= 10
	x = 0
	tmp = n
	idx = 1
	while sum > s:
		i = idx
		while tmp:
			num10 = 10 ** i
			if tmp % num10:
				x += num10 - tmp % num10
				tmp += num10 - tmp % num10
				break
			i += 1
		n = tmp
		idx = i
		sum = 0
		while tmp:
			sum += tmp % 10
			tmp //= 10
		tmp = n
	print(x)
	T -= 1


l = []
x = int(input())
for _ in range(x):
	(a, b) = list(map(int, input().split()))
	c = a % b
	if c != 0:
		d = b - c
		l.append(d)
	elif c == 0:
		d = 0
		l.append(d)
for k in l:
	print(k)


t = int(input())
while t != 0:
	(a, b) = map(int, input().split())
	x = None
	if a % b == 0:
		x = a / b
	else:
		x = a // b + 1
	x = int(x)
	print(f'{x * b - a}')
	t -= 1


def div_prblm(a, b):
	if a % b == 0:
		print('0')
	else:
		print(b - a % b)
	return
n = int(input())
for _ in range(n):
	(a, b) = input().split()
	div_prblm(int(a), int(b))


t = int(input())
for _ in range(t):
	(x, y) = map(int, input().split())
	c = 0
	print((y - x % y) % y)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	li = list(str(a))
	li = list(map(int, li))
	if sum(li) <= b:
		print(0)
	else:
		diff = sum(li) - b
		total = 0
		carry = 0
		for j in range(len(li) - 1, -1, -1):
			val = li[j] + carry
			x = (10 - val) * 10 ** (len(li) - j - 1)
			total += x
			carry = 1
			li[j] = 0
			if sum(li) + carry <= b:
				break
		print(total)


import io, os, math
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
rr = lambda : input()
rri = lambda : int(input())
rrm = lambda : list(map(int, input().split()))
INF = float('inf')

def sumd(m):
	sd = 0
	while m > 0:
		sd += m % 10
		m //= 10
	return sd

def solve(n, s):
	amt = 0
	sd = sumd(n)
	if sd <= s:
		return 0
	else:
		construct = 0
		m = n
		leng = len(str(m))
		large = 10
		rightside = m % 10
		leftside = n // 10
		for ll in range(1, leng + 1):
			construct = large - rightside
			if sumd(construct + n) <= s:
				return construct
			rightside += leftside % 10 * large
			large *= 10
			leftside //= 10
		return construct
t = rri()
for _ in range(t):
	(n, s) = rrm()
	print(solve(n, s))


def mdc(a, b):
	while b != 0:
		resto = a % b
		a = b
		b = resto
	return a
entrada = int(input())
for k in range(entrada):
	(a, b) = list(map(int, input().split()))
	resp = a % b
	if resp == 0:
		print(0)
	else:
		print(b - resp)


t = int(input())
for i in range(t):
	a = 0
	(s, m) = map(int, input().split())
	a = m - s % m
	if a % m != 0:
		print(a)
	else:
		print(0)


t = int(input())
l = []
for _ in range(t):
	(n, s) = input().split()
	(ans, k, cur, f, n1) = (0, 0, 0, False, '')
	for p in range(len(n)):
		k += int(n[p])
	if k <= int(s):
		l.append(0)
	else:
		for i in range(len(n)):
			if not f:
				cur += int(n[i])
				if cur >= int(s):
					n1 = n[i:len(n)]
					f = True
		if f:
			r = 10 ** len(n1)
			ans = r - int(n1)
		l.append(ans)
for i in l:
	print(i)


for t in range(int(input())):
	(n, s) = [int(i) for i in input().split()]
	n = str(n)
	n = [int(i) for i in n]
	res = 0
	if sum(n) <= s:
		print(res)
	else:
		cnt = 1
		while n and sum(n) > s:
			q = n.pop()
			res += (10 - q) * cnt
			if n:
				n[-1] += 1
			cnt *= 10
		print(res)


t = int(input())
for test in range(t):
	(a, b) = [int(x) for x in input().split()]
	n = a % b
	if a % b == 0:
		print(0)
	else:
		print(b - n)


t = int(input())

def digitsSum(x):
	s = str(x)
	res = 0
	for i in range(len(s)):
		res += int(s[i])
	return res

def digitsSumStr(s):
	res = 0
	for i in range(len(s)):
		res += int(s[i])
	return res
for i in range(t):
	(n, s) = map(int, input().split(' '))
	if digitsSum(n) < s:
		print(0)
		continue
	p = 1
	sum_ = 0
	while digitsSum(n) > s:
		p *= 10
		sum_ += p - n % p
		n += p - n % p
	print(sum_)


import math
t = int(input())
while t:
	inp = list(map(int, input().strip().split()))[:2]
	(x, y) = (inp[0], inp[1])
	l = math.ceil(x / y) * y - x
	print(l)
	t -= 1


import math
n_tests = int(input())
for _ in range(n_tests):
	(a, b) = [int(i) for i in input().split()]
	print(b * math.ceil(a / b) - a)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		e = a // b
		f = b * e
		d = f + b
		res = d - a
		print(res)


t = int(input())

def get_digit_sum(num):
	sum = 0
	num_str = str(num)
	for digit in num_str:
		sum += int(digit)
	return sum

def ans(num, s):
	sum = get_digit_sum(num)
	if sum <= s:
		return 0
	num_str = str(num)[::-1]
	moves = 0
	add_one = False
	factor = 1
	for letter in num_str:
		digit = int(letter) + add_one
		sum = sum - digit + 1
		moves = moves + (10 - digit) * factor
		if sum <= s:
			return moves
		add_one = True
		factor *= 10
while t:
	(num, s) = list(map(int, input().split(' ')))
	print(ans(num, s))
	t -= 1


a = int(input())
i = 1
while i < a + 1:
	(b, c) = input().split()
	j = 0
	sum = 0
	while j < len(b):
		sum += int(b[j])
		j += 1
	num = []
	for x in b:
		num += x
	ans = 0
	k = 1
	while sum > int(c) and len(num) - k > 0:
		if int(num[len(num) - k]) > 0:
			ans += (10 - int(num[len(num) - k])) * 10 ** (k - 1)
			sum += 1 - int(num[len(num) - k])
			num[len(num) - k] = 0
			num[len(num) - k - 1] = int(num[len(num) - k - 1]) + 1
		k += 1
	if k <= len(num) and sum <= int(c):
		print(ans)
	elif int(b) != int(c) and sum != int(c):
		print(int(10 ** len(num)) - int(b))
	else:
		print('0')
	i += 1


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	a = []
	temp = n
	while temp > 0:
		a.append(temp % 10)
		temp //= 10
	if sum(a) <= s:
		print(0)
		continue
	su = 0
	x = len(a)
	temp = -1
	for i in range(x - 1, -1, -1):
		if su + a[i] >= s:
			temp = i
			break
		su += a[i]
	if temp == x - 1:
		a.insert(x, 1)
	else:
		a[temp + 1] += 1
	for i in range(0, temp + 1):
		a[i] = 0
	num = 0
	for i in a[::-1]:
		num *= 10
		num += i
	print(num - n)


import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]
inf = 10 ** 19
for _ in range(II()):
	(t, s) = SI().split()
	n = len(t)
	s = int(s)
	if sum((int(c) for c in t)) <= s:
		print(0)
		continue
	i = 0
	while i < n and s > 0:
		s -= int(t[i])
		i += 1
	ans = []
	m = 0
	for j in range(n - 1, i - 2, -1):
		a = int(t[j])
		if a + m == 0:
			ans.append(0)
		else:
			ans.append(10 - a - m)
			m = 1
	while len(ans) > 1 and ans[-1] == 0:
		ans.pop()
	print(*ans[::-1], sep='')


n = int(input())
for l in range(n):
	(a, b) = list(map(int, input().split()))
	print((b - a % b) % b)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	print(a % b and b - a % b)


def gt():
	return list(map(int, input().split()))

def digsum(x):
	return sum([int(val) for val in str(x)])
(t,) = gt()
while t:
	t -= 1
	(n, s) = gt()
	tmp = n
	dec = 0
	while digsum(tmp) > s:
		tmp = (tmp + 9) // 10
		dec += 1
	print(tmp * 10 ** dec - n)


for x in range(int(input())):
	(a, b) = map(int, input().split())
	c = a
	a = list('0' + str(a))
	arr = []
	b = b - (ord(a[0]) - 48)
	t = 1
	f = 0
	while b >= 0:
		arr.append(b)
		b = b - (ord(a[t]) - 48)
		t += 1
		if t == len(a):
			f = 1
			break
	arr.append(b)
	for i in range(len(a) - len(arr) - 1, -1, -1):
		arr.append(0)
	if f == 1 and b >= 0:
		print(0)
	else:
		s1 = ''
		f = 0
		t = 1
		k = 0
		for i in range(len(arr) - 1, 0, -1):
			if arr[i] <= 0 and f == 0:
				s1 += '0'
			else:
				f = 1
				if t:
					k = len(arr) - i - 1
					t = 0
				s1 += a[i]
		if int(s1) == 0:
			s1 = s1 + '1'
		ans = int(s1[::-1])
		if k > 0:
			ans += pow(10, k)
		print(ans - int(''.join(a)))


for tc in range(int(input())):
	(a, b) = map(int, input().split())
	k = a % b
	if k == 0:
		print(k)
	else:
		print(b - k)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	tmp = n
	t = 1
	while sum(map(int, str(n))) > s:
		c = n // t % 10
		n += (10 - c) % 10 * t
		t *= 10
	print(n - tmp)


num = int(input())
div = []
for i in range(num):
	arr = [i for i in input().split()][:2]
	j = 0
	if int(arr[0]) % int(arr[1]) == 0:
		div.append(0)
	else:
		div.append(int(arr[1]) - int(arr[0]) % int(arr[1]))
print(*div, sep='\n')


testCase = int(input())
for i in range(testCase):
	(a, b) = map(int, input().split())
	i = 1
	r1 = a / b
	r2 = int(a / b)
	if r1 > r2:
		r2 = r2 + 1
	print(r2 * b - a)


import sys
input = sys.stdin.readline
ins = lambda : input().rstrip()
ini = lambda : int(input().rstrip())
inm = lambda : map(int, input().rstrip().split())
inl = lambda : list(map(int, input().split()))
out = lambda x, s='\n': print(s.join(map(str, x)))

def sum(n):
	ans = 0
	while n > 0:
		ans += n % 10
		n //= 10
	return ans
ans = []
t = ini()
for _ in range(t):
	(n, s) = inm()
	tmp = 0
	count = 1
	while True:
		if sum(n) <= s:
			break
		else:
			tmp += (10 - n % 10) * count
			count *= 10
			n = (n + 10) // 10
	ans.append(tmp)
out(ans)


t = int(input())
for i in range(t):
	g = 1
	(a, b) = map(int, input().split())
	a = str(a)
	d = sum(list(map(int, a)))
	a = int(a)
	k = 0
	while d > b:
		g *= 10
		f = g - a % g
		a += f
		k += f
		a = str(a)
		d = sum(list(map(int, a)))
		a = int(a)
	print(k)
	i += 1


for i in range(int(input())):
	(a, b) = list(map(int, input().split()))
	r = b - a
	print(r % b)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split(' '))
	if a % b == 0:
		print(0)
	elif a < b:
		print(b - a)
	elif a > b:
		divided = (int(a / b) + 1) * b
		print(divided - a)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	cop_b = b
	c = 0
	i = 2
	if a % b == 0:
		c = 0
	elif a > b:
		remainder = a // b + 1
		c = abs(a - remainder * b)
	elif a < b:
		c = b - a
	print(c)


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
		continue
	print((a // b + 1) * b - a)


t = int(input())
list = []
for i in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		list.append(0)
	else:
		list.append(b - a % b)
print(*list, sep='\n')


n = int(input())
for i in range(n):
	(s1, s2) = map(int, input().split())
	if s1 % s2 == 0:
		print('0')
	else:
		print(s2 * (s1 // s2 + 1) - s1)


def sod(num):
	sums = 0
	while num > 0:
		sums += num % 10
		num = num // 10
	return sums
t = int(input())
for _ in range(t):
	(n, s) = map(int, input().split())
	if sod(n) <= s:
		print(0)
	else:
		temp = n
		i = 1
		while sod(temp) > s:
			temp = temp // 10 ** i
			temp += 1
			temp = temp * 10 ** i
			i += 1
		print(temp - n)


t = int(input())
for _ in range(t):
	(n, s) = map(int, input().split())
	arr = list(map(int, str(n)))
	currSum = sum(arr)
	i = len(arr) - 1
	while currSum > s:
		while arr[i] == 0:
			i -= 1
		currSum -= arr[i]
		arr[i] = 0
		i -= 1
		while i >= 0 and arr[i] == 9:
			currSum -= arr[i]
			arr[i] = 0
			i -= 1
		if i < 0:
			currSum += 1
			arr = [1] + arr
			i = 0
		else:
			currSum += 1
			arr[i] += 1
	smallest = int(''.join(map(str, arr)))
	print(smallest - n)


import math
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a < b:
		print(b - a)
		continue
	if a == b:
		print(0)
		continue
	elif a > b:
		if a % b == 0:
			print(0)
			continue
		else:
			temp = math.ceil(a / b)
			print(b * temp - a)
			continue


for test_i in range(int(input())):
	(a, b) = map(int, input().split())
	print((b - a % b) % b)


t = int(input())
while t > 0:
	t -= 1
	(n, x) = input().split()
	n = int(n)
	x = int(x)
	ans = 0
	b = True
	while b:
		b = False
		s = str(n)
		sum = 0
		for i in range(0, len(s)):
			if sum + int(s[i]) > x:
				k = s[i:]
				tmp = 10 ** len(k)
				k = int(k)
				ans += tmp - k
				n += tmp - k
				b = True
				break
			sum += int(s[i])
	print(ans)


import math
for _testcases_ in range(int(input())):
	(n, k) = map(int, input().split())
	s = math.ceil(n / k)
	print(s * k - n)


tc = int(input())

def func(s):
	x = 0
	while s > 0:
		x += s % 10
		s = s // 10
	return x
while tc > 0:
	tc -= 1
	(n, s) = input().split(' ')
	if func(int(n)) <= int(s):
		print(0)
		continue
	for i in range(1, len(n) + 1):
		nn = int(n)
		ex = 10 ** i - int(n[len(n) - i:])
		nn += ex
		ans = ex
		if func(nn) <= int(s):
			break
	print(ans)


rr = lambda : input().strip()
rri = lambda : int(rr())
rrm = lambda : [int(x) for x in rr().split()]
from sys import stdin, stdout, setrecursionlimit
from math import ceil

def sol():
	(x, n) = rrm()
	s = str(x)[::-1]
	sm = 0
	z = ord('0')
	for c in s:
		sm += ord(c) - z
	if sm <= n:
		print(0)
		return
	n = sm - n
	res = 0
	zz = z + 10
	m = 1
	prev = 0
	for c in s:
		res += m * (zz - ord(c) - prev)
		n -= ord(c) - z
		prev = 1
		if n + prev <= 0:
			print(res)
			return
		m *= 10
	return

def main():
	T = rri()
	for t in range(1, T + 1):
		ans = sol()
main()


t = int(input())
for k in range(t):
	(a, b) = list(map(int, input().split()))
	c = 0
	if a % b == 0:
		print(c)
	else:
		c = b * (a // b + 1) - a
		print(c)


def linput():
	return [int(i) for i in input().split()]
q = int(input())
for ______ in range(q):
	(n, m) = linput()
	if n % m == 0:
		print(0)
	else:
		print(m - n % m)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	count = 0
	if n % k == 0:
		print(0)
	else:
		x = int(n / k)
		a = k * (x + 1)
		count = a - n
		print(count)


t = int(input())
for i in range(t):
	ab = list(map(int, input().split()))
	if ab[0] % ab[1] != 0:
		count = (ab[0] // ab[1] + 1) * ab[1] - ab[0]
	else:
		count = 0
	print(count)


n = int(input())
l = []
for i in range(n):
	(a, b) = map(int, input().split())
	l.append(a)
	l.append(b)
i = 0
while i < 2 * n - 1:
	ct = 0
	if l[i] % l[i + 1] != 0:
		q = int(l[i] / l[i + 1])
		ct = l[i + 1] * (q + 1) - l[i]
	i += 2
	print(ct)


import os
import sys
from io import BytesIO, IOBase
from math import *
readn = lambda : int(input())
readl = lambda : list(map(int, input().split()))
reads = lambda : input()
readns = lambda : map(int, input().split())

def main():
	for _ in range(readn()):
		(a, b) = readns()
		m = a % b
		if (a + m) % b == 0:
			print(m)
		else:
			print(b - m)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def moves(a, b):
	if a % b == 0:
		return 0
	return b - a % b
test_cases = int(input())
for i in range(test_cases):
	(a, b) = map(int, input().split(' '))
	print(moves(a, b))


from sys import stdin

def int_input():
	return int(stdin.readline())

def str_input():
	return input()

def multiple_input():
	return map(int, stdin.readline().split())

def list_input():
	return list(map(int, stdin.readline().split()))
t = int_input()
while t:
	t -= 1
	(a, b) = multiple_input()
	print(b - a % b if a % b else 0)


import math
for i in range(int(input())):
	n = list(map(int, input().split()))
	ceil = math.ceil(n[0] / n[1])
	print(abs(ceil * n[1] - n[0]))


for _ in range(int(input())):
	(m, n) = map(int, input().split())
	copy = m % n
	if copy == 0:
		print(0)
	else:
		print(n - copy)


def solution(nums):
	if nums[0] % nums[1] == 0:
		return '0\n'
	target = (nums[0] // nums[1] + 1) * nums[1]
	return str(target - nums[0]) + '\n'
casesNum = int(input())
output = ''
for i in range(casesNum):
	output += solution(list(map(int, input().split())))
print(output)


n = int(input())
for i in range(n):
	(x, y) = input().split()
	x = int(x)
	y = int(y)
	if x < y:
		print(y - x)
	elif x % y == 0:
		print(0)
	else:
		print(y - x % y)


for _ in range(int(input())):
	(n, s) = list(map(int, input().split()))
	arr = [n]
	p = 1
	for i in range(19):
		num = n // p
		num = num * p
		num += p
		p *= 10
		arr.append(num)
	ans = 10 ** 20
	for x in arr:
		t = x
		su = 0
		while t:
			su += t % 10
			t = t // 10
		if su <= s:
			ans = min(ans, x - n)
	print(ans)


def f(num, rn, x):
	sum = 0
	i = 0
	j = 1
	c = 0
	while i <= rn - 1:
		buffX = int(num[i])
		if i > 0:
			if int(num[i - 1]) != 0:
				c = int(num[i - 1])
				j = 1
			else:
				j = j + 1
		else:
			j = 1
		sum = sum + buffX
		if sum > x:
			if i > 0:
				if c == x:
					return f(plus1(num, i - j), rn, x)
				else:
					return f(plus1(num, i - 1), rn, x)
			else:
				return f(str(10 ** len(num)), rn, x)
		if i == rn - 1:
			return num
		i = i + 1

def plus1(num, x):
	while x >= 0:
		buff = int(num[x]) + 1
		if buff > 9:
			buff0 = str(10 ** len(num[x + 1:]))
			num = num[:x] + '0' + buff0[1:]
			if x == 0:
				num = '1' + num
			x = x - 1
		else:
			buff0 = str(10 ** len(num[x + 1:]))
			num = num[:x] + str(buff) + buff0[1:]
			break
	return num
n = int(input())
for i in range(n):
	(ip1, ip2) = input().split()
	ip2 = int(ip2)
	r = len(ip1)
	print(int(f(ip1, r, ip2)) - int(ip1))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	c = 0
	if a % b == 0:
		print(0)
	elif a > b:
		be = a // b + 1
		c = be * b - a
		print(c)
	else:
		print(b - a)


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	count = x // y
	while True:
		check = y * count
		if check % y == 0 and check >= x:
			print(check - x)
			break
		count += 1


numCases = int(input())
for i in range(1, numCases + 1):
	line = input()
	arrNums = line.split(' ')
	num1 = int(arrNums[0])
	num2 = int(arrNums[1])
	if num1 % num2 != 0:
		print(num2 - num1 % num2)
	else:
		print(0)


import sys
input = sys.stdin.readline

def getInt():
	return int(input())

def getVars():
	return map(int, input().split())

def getList():
	return list(map(int, input().split()))

def getStr():
	return input().strip()
t = getInt()
for _ in range(t):
	(a, b) = getVars()
	c = a % b
	if c > 0:
		c = (a // b + 1) * b - a
	print(c)


import sys
input = sys.stdin.readline
Q = int(input())
Query = [list(map(int, input().split())) for _ in range(Q)]
for (a, b) in Query:
	ans = (b - a) % b
	print(ans)


def algo(a, b):
	if a < b:
		return b - a
	if a % b == 0:
		return 0
	if a >= b:
		return b - a % b
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	print(algo(a, b))


import sys
input = sys.stdin.readline

def input_list():
	return [int(x) for x in input().split()]

def a():
	(x, y) = input_list()
	if x % y == 0:
		print(0)
		return
	print(y - x % y)

def main():
	n = int(input())
	for _ in range(n):
		a()
main()


import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
from functools import lru_cache
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

def input():
	return sys.stdin.readline()

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
for _ in range(int(input())):
	(a, b) = mapi()
	res = a % b
	if res == 0:
		print(res)
	else:
		print(b - res)


t = int(input(''))
i = 0
while i < t:
	(x, y) = [int(x) for x in input().split()]
	if x % y != 0:
		print((x // y + 1) * y - x)
	else:
		print(0)
	i += 1


def base(a, b):
	remaider = a % b
	if remaider:
		return b - remaider
	else:
		return remaider
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	print(base(a, b))


test = False
test_cases = [[10, 4], [13, 9], [100, 13], [123, 456], [92, 46]]

def solve(input_data):
	(a, b) = input_data
	print(0 if a % b == 0 else b - a % b)
if test:
	n = len(test_cases)
	while n > 0:
		solve(test_cases[-n])
		n -= 1
else:
	n = int(input())
	while n > 0:
		solve([int(x) for x in input().split()])
		n -= 1


for x in range(int(input())):
	(a, b) = map(int, input().split())
	print([b - a % b, 0][a % b == 0])


t = int(input())
for i in range(t):
	(num, s) = input().split()
	s = int(s)
	ss = 0
	l = len(num)
	for e in num:
		ss += int(e)
	if ss <= s:
		print('0')
		continue
	if int(num[0]) >= s:
		tt = int('1' + '0' * l)
		print(tt - int(num))
		continue
	i = 0
	temp = 0
	while i < l and temp + int(num[i]) < s:
		temp += int(num[i])
		i += 1
	tt = int(num[:i])
	tt += 1
	tt *= 10 ** (l - i)
	print(tt - int(num))


import sys, math
input = sys.stdin.readline
t = int(input())
for r in range(t):
	(a, b) = map(int, input().split())
	if a >= b:
		if a % b == 0:
			print(0)
		else:
			x = math.ceil(a / b)
			ans = int(b * x) - a
			print(ans)
	else:
		x = math.ceil(a / b)
		ans = int(b * x) - a
		print(ans)


test = int(input())
i = 1
while i <= test:
	[a, b] = list(map(int, input().split()))
	rem = a % b
	if rem == 0:
		print(0)
	else:
		print(b - rem)
	i += 1


from sys import stdin, stdout
from os import path
if path.exists('input.txt'):
	stdin = open('input.txt', 'r')
for _ in range(int(stdin.readline())):
	(x, y) = map(int, stdin.readline().strip().split())
	f = 1
	w = q = z = x
	sum = 0
	while w != 0:
		sum += w % 10
		w //= 10
	i = 0
	if sum <= y:
		print(0)
	else:
		while True:
			if sum + 1 <= y:
				if f != 1:
					q = q * f + f
				break
			else:
				f *= 10
				sum -= q % 10
				q //= 10
		print(q - x)


import math
t = int(input())
while t:
	(a, b) = list(map(int, input().split()))
	k = math.ceil(a / b)
	print(k * b - a)
	t -= 1


def R():
	return map(int, input().split())

def I():
	return int(input())

def S():
	return str(input())

def L():
	return list(R())
from collections import Counter
import math
import sys
from itertools import permutations
import bisect
for _ in range(I()):
	(a, b) = R()
	print(math.ceil(a / b) * b - a)


n = int(input())
for i in range(n):
	(a, b) = [int(x) for x in str(input()).split()]
	res = (b - a % b) % b
	print(res)


test = int(input())
for i in range(test):
	(a, b) = map(int, input().split(' '))
	print((b - a % b) % b)


import math
t = int(input())
while t:
	(a, b) = map(int, input().strip().split())
	print(math.ceil(a / b) * b - a)
	t -= 1


import math
for w in range(int(input())):
	a = list(map(int, input().split()))
	if a[0] <= a[1]:
		print(a[1] - a[0])
	else:
		pt = a[0] // a[1]
		if a[0] % a[1] == 0:
			print(0)
		else:
			print(a[1] * (pt + 1) - a[0])


def main():
	t = int(input())
	while t > 0:
		t -= 1
		(a, b) = [int(i) for i in input().split(' ')]
		if a % b == 0:
			print(0)
		else:
			print(b - a % b)
main()


t = int(input())
l = []
for i in range(t):
	(a, b) = input().split(' ')
	a = int(a)
	b = int(b)
	x = 0
	if a % b != 0:
		x = b - a % b
	l.append(x)
for i in range(t):
	print(l[i])


t = int(input())
ans = []
for i in range(t):
	(a, b) = input().strip().split()
	a = int(a)
	b = int(b)
	if a % b == 0:
		ans.append(0)
	else:
		ans.append(b - a % b)
for i in ans:
	print(i)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	temp = n % m
	if temp == 0:
		print(0)
	else:
		print(m - temp)


import sys
n = input()
for line in sys.stdin:
	(a, b) = map(int, line.strip().split())
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	p = a % b
	q = a // b
	x = a // b + 1
	if a % b == 0:
		print(0)
	elif x * b > a:
		print(b * x - a)


for _ in range(int(input())):
	(lst, s) = input().split()
	(lst, s) = (list(lst), int(s))
	summ = 0
	for i in lst:
		summ += int(i)
	length = len(lst)
	if summ <= s:
		count = 0
	else:
		for i in range(length):
			s -= int(lst[i])
			summ -= int(lst[i])
			if s <= 0 and summ >= 0:
				remaining = ''.join(lst[i:length])
				val = '1' + '0' * (length - i)
				count = int(val) - int(remaining)
				break
	print(count)


x = int(input())
listnew = list()
for i in range(0, x):
	list1 = input().split(' ')
	list2 = [int(i) for i in list1]
	a = list2[0]
	b = list2[1]
	if a % b == 0:
		listnew.append(0)
	else:
		c = a // b
		d = (c + 1) * b - a
		listnew.append(d)
for i in listnew:
	print(i)


def solve(a, b):
	if a < b:
		return b - a
	else:
		c = a % b
		if c == 0:
			return 0
		else:
			return abs(c - b)
t = int(input())
a = []
b = []
for i in range(t):
	ab = []
	ab = input().split()
	a.append(int(ab[0]))
	b.append(int(ab[1]))
for i in range(t):
	print(solve(a[i], b[i]))


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	a = list(map(int, list(str(n))))
	if sum(a) <= s:
		print(0)
	else:
		tot = 0
		b = a[::-1]
		i = 0
		while i < len(b) and sum(b) > s:
			if b[i] == 0:
				i += 1
				continue
			else:
				tot += (10 - b[i]) * 10 ** i
				b[i] = 0
				if i != len(b) - 1:
					b[i + 1] += 1
				i += 1
		print(tot)


from math import *

def main():
	t = int(input())
	for _ in range(t):
		(m, n) = list(map(int, input().split()))
		if m % n == 0:
			print(0)
		else:
			print(n - m % n)
main()


t = int(input())
for i in range(t):
	num1 = list(map(int, input().split()))
	a = num1[0] % num1[1]
	print((num1[1] - a) % num1[1])


import sys
from math import sqrt
from collections import defaultdict
inpt = sys.stdin.readline

def inp():
	return int(inpt())

def inlist():
	return list(map(int, inpt().split()))

def instr():
	s = inpt()
	return list(s[:len(s) - 1])

def invr():
	return map(int, inpt().split())

class Graph:

	def __init__(self, n):
		self.n = n
		self.graph = defaultdict(list)
		self.marked = defaultdict(int)

	def addEdge(self, u, v):
		self.graph[u].append(v)
		self.graph[v].append(u)

	def dfs(self, u):
		self.marked[u] = 1
		for i in self.graph[u]:
			if self.marked[i] == 0:
				self.dfs(i)

def main():
	t = inp()
	for l in range(t):
		(n, s) = invr()
		sdigit = 0
		for dgt in str(n):
			sdigit += int(dgt)
		ans = 0
		x = 1
		while sdigit > s:
			ldgt = n % 10
			if ldgt != 0:
				ans += (10 - ldgt) * x
			else:
				ans += 10 * x
			n = n // 10
			x = x * 10
			n += 1
			sdigit = 0
			for dgt in str(n):
				sdigit += int(dgt)
		print(ans)
main()


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def solve(a, b):
	r = a % b
	if r == 0:
		return 0
	else:
		return b - r

def output():
	t = inp()
	res = []
	for i in range(t):
		(a, b) = invr()
		res.append(solve(a, b))
	for elt in res:
		print(elt)
output()


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	lin = n
	d = []
	su = 0
	while n != 0:
		su += n % 10
		d.append(n % 10)
		n //= 10
	d.reverse()
	m = len(d)
	p = 0
	i = 0
	while i < m:
		p += d[i]
		if p >= s:
			break
		i += 1
	a = 0
	if i == 0:
		a = 10 ** m
	else:
		b = 0
		i -= 1
		j = i
		d[i] += 1
		q = 1
		while i >= 0:
			b += d[i] * q
			q *= 10
			i -= 1
		a = b * 10 ** (m - j - 1)
	if su <= s:
		print(0)
	else:
		print(a - lin)


n = int(input())
arr = []
for _ in range(n):
	(a, b) = map(int, input().split())
	if a % b == 0:
		arr.append(0)
	else:
		x = (a // b + 1) * b - a
		arr.append(x)
for values in arr:
	print(values)


import sys, math, cmath, time
start_time = time.time()

def solve():
	(n, s) = invr()
	a = str(n)
	qw = n
	q = 0
	for i in range(len(a)):
		q = q + int(a[i])
		if q >= s:
			if q > s or (q == s and a[i + 1:].count('0') != len(a) - i - 1):
				if i == 0:
					qw = int('1' + '0' * len(a))
				else:
					qw = int(str(int(a[:i]) + 1) + '0' * (len(a) - len(a[:i])))
				break
	print(qw - n)

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = inp()
	for tt in range(t):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	return input().strip()

def invr():
	return map(int, input().split())

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def counter_elements(a):
	q = dict()
	for i in range(len(a)):
		if a[i] not in q:
			q[a[i]] = 0
		q[a[i]] = q[a[i]] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return list(sorted(q))

def transpose(a):
	(n, m) = (len(a), len(a[0]))
	b = [[0] * n for i in range(m)]
	for i in range(m):
		for j in range(n):
			b[i][j] = a[j][i]
	return b

def factorial(n, m=1000000007):
	q = 1
	for i in range(n):
		q = q * (i + 1) % m
	return q
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


t = int(input())
while t:
	(n, m) = map(int, input().split())
	if n % m == 0:
		print(0)
	else:
		z = min(n, m)
		p = max(n, m)
		k = n // m + 1
		k = k * z
		print(abs(k - p))
	t -= 1


exec(int(input()) * 'x,y=map(int,input().split());print((y-x%y)%y);')


k = int(input())
for j in range(k):
	(m, n) = [int(i) for i in input().split()]
	if m % n == 0:
		print(0)
	else:
		print(n - m % n)


import math, sys
s = list(map(int, sys.stdin.read().split()))
(p, q) = (1, 3)
L = []
for x in range(s[0]):
	L.append(s[p:q])
	(p, q) = (q, q + 2)
	(a, b) = (L[x][0], L[x][1])
	print(b * math.ceil(a / b) - a)


import sys
line = sys.stdin.readline()
cases = int(line.strip())
for case in range(cases):
	nums = sys.stdin.readline().strip().split()
	a = int(nums[0])
	b = int(nums[1])
	add = a % b
	if add != 0:
		res = int(a / b)
		add = (res + 1) * b - a
	print(int(add))


t = int(input())
list1 = []
out = []
for x in range(t):
	list1.append(list(map(int, input().split())))
	if list1[x][0] % list1[x][1] == 0:
		out.append(0)
	else:
		n = list1[x][1] - list1[x][0] % list1[x][1]
		out.append(n)
for x in range(t):
	print(out[x])


import math
t = int(input())
for zz in range(t):
	(a, b) = map(int, input().split())
	temp = math.ceil(a / b)
	print(temp * b - a)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
import math
t = inp()
for testcase in range(t):
	(a, b) = invr()
	r = math.ceil(a / b)
	print(b * r - a)


I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


tc = int(input())
import math

def sd(n):
	s = 0
	while n:
		s += n % 10
		n //= 10
	return s
for _ in range(tc):
	(n, s) = [int(x) for x in input().split()]
	n2 = n
	diff = sd(n) - s
	mult = 10
	while diff > 0:
		n = n - n % mult
		n += mult
		diff = sd(n) - s
		mult *= 10
	print(n - n2)


for _ in range(int(input())):
	(n, s) = [int(c) for c in input().split()]
	strn = str(n)
	totalsum = 0
	for i in strn:
		totalsum += int(i)
	if totalsum <= s:
		print(0)
		continue
	strn = [int(i) for i in strn[::-1]]
	strn.append(0)
	finalans = 0
	x = 1
	init = 0
	for i in range(len(strn) - 1):
		digit = int(strn[i])
		strn[i] = 0
		strn[i + 1] += 1
		finalans = finalans + x * (10 - digit)
		x *= 10
		if sum(strn) <= s:
			break
	print(finalans)


def solve():
	(a, b) = map(int, input().split())
	if a <= b:
		ans = b - a
		print(ans)
	elif a % b == 0:
		print(0)
	else:
		f = int(a / b)
		f += 1
		ans = b * f - a
		print(ans)
t = int(input())
for i in range(t):
	solve()


n = int(input())
for i in range(0, n):
	x = list(map(int, input().split()))
	a = int(x[0])
	b = int(x[1])
	x = a % b
	if x == 0:
		pass
	else:
		x = b - x
	count = x
	print(count)


n = int(input())
j = []

def cont(a, b):
	if a % b == 0:
		j.append(0)
	elif b > a:
		j.append(b - a)
	else:
		h = a % b
		ans = b - h
		j.append(ans)
for i in range(n):
	(a, b) = map(int, input().split())
	cont(a, b)
print(*j, sep='\n')


for i in range(int(input())):
	s = list(map(int, input().split()))
	if s[0] > s[1]:
		if s[0] % s[1] == 0:
			print(0)
		else:
			print((int(s[0] / s[1]) + 1) * s[1] - s[0])
	else:
		print(s[1] - s[0])


for _ in range(int(input())):
	(s, n) = map(str, input().split())
	cnt = 0
	n = int(n)
	flag = 0
	sm = 0
	for i in range(len(s)):
		sm += int(s[i])
	if sm <= n:
		flag = 1
	for i in range(len(s)):
		if int(s[i]) < n:
			n -= int(s[i])
		elif flag == 0:
			cnt = 10 ** (len(s) - i) - int(s[i:])
			break
	print(cnt)


n = int(input(''))
for i in range(0, n):
	(p, q) = input('').split(' ')
	a = int(p)
	b = int(q)
	c = a // b
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


def sum(n):
	s = str(n)
	ans = 0
	for i in s:
		ans += int(i)
	return ans
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	if sum(n) <= s:
		print(0)
	else:
		num = ''
		sm = 0
		for i in str(n):
			sm += int(i)
			if sm >= s:
				if num == '':
					num = '1'
					while int(num) < n:
						num = num + '0'
					break
				else:
					num = str(int(num) + 1)
					while int(num) < n:
						num = num + '0'
					break
			else:
				num += i
		print(int(num) - n)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a > b and a % b != 0:
		print(str(b * (a // b + 1) - a))
	elif a % b == 0:
		print('0')
	else:
		print(str(b - a))


def main():
	t = int(input())
	for _ in range(t):
		(a, b) = map(int, input().split())
		r = a // b
		ans = (r + 1) * b - a
		if ans == b:
			ans = 0
		print(ans)
main()


def greedy(nums, target):
	if sum(map(int, list(nums))) <= target:
		return 0
	size = len(nums)
	for (ind, num) in enumerate(nums):
		if target - int(num) <= 0:
			return 10 ** (size - ind) - int(nums[ind:])
		target -= int(num)
	return
t = int(input())
for _ in range(t):
	(nums, target) = input().split()
	target = int(target)
	print(greedy(nums, target))


for _ in range(int(input())):
	(n, s) = input().split()
	l = [int(c) for c in n]
	s = int(s)
	if sum(l) <= s:
		print(0)
		continue
	index = -1
	total = 0
	while total < s and index < len(l):
		total += l[index + 1]
		index += 1
	print(10 ** (len(l) - index) - int(n[index:]))


n = int(input())
lst = list()
for i in range(n):
	lst.append(input().split())
for j in range(n):
	if int(lst[j][0]) % int(lst[j][1]):
		x = int(lst[j][1]) - int(lst[j][0]) % int(lst[j][1])
		print(x)
	else:
		x = 0
		print(x)


t = int(input())
for i in range(0, t):
	ip = str(input()).split(' ')
	a = int(ip[0])
	b = int(ip[1])
	print(-a % b)


import sys
from math import ceil
t = int(input())
for _ in range(t):
	(a, b) = [int(x) for x in input().split()]
	if a >= b and a % b == 0:
		print(0)
	elif a > b:
		print(ceil(a / b) * b - a)
	else:
		print(b - a)


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputstringnum():
	return [ord(x) - ord('a') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d

def getsum(num):
	sm = 0
	while num != 0:
		sm += num % 10
		num //= 10
	return sm
t = int(input())
for q in range(t):
	(n, s) = inputnums()
	sm = getsum(n)
	ans = 0
	i = 1
	while sm > s:
		ans += i * (10 - n % 10)
		n //= 10
		n += 1
		sm = getsum(n)
		i *= 10
	print(ans)


t = int(input())
for i in range(t):
	(n1, n2) = map(int, input().split())
	if n1 % n2 == 0:
		print(0)
	else:
		x = n1 % n2
		print(n2 - x)


def main():
	t = int(input())
	for i in range(t):
		(a, b) = map(int, input().split())
		if a % b == 0:
			print(0)
		else:
			print(b - a % b)
main()


import time
p = int(input())
for i in range(p):
	k = 0
	(a, b) = map(int, input().split())
	if a / b != a // b:
		print((a // b + 1) * b - a)
	elif b > a:
		print(b - a)
	else:
		print(0)


for _ in range(int(input())):
	(n, s) = map(str, input().split())
	s = int(s)
	l = [0, int(n[0])]
	for i in range(1, len(n)):
		l.append(l[-1] + int(n[i]))
		if l[-1] > s:
			break
	if l[-1] <= s:
		print(0)
	else:
		i = len(l) - 1
		while l[i] >= s:
			i -= 1
		if i == 0:
			thing = 1
		else:
			thing = int(n[:i]) + 1
		thing *= 10 ** (len(n) - i)
		print(thing - int(n))


n = int(input())
for i in range(n):
	(c, d) = input().split()
	a = int(c)
	b = int(d)
	if a % b != 0:
		e = b - a % b
		print(e)
	else:
		print('0')


import sys
input = sys.stdin.readline
from collections import defaultdict
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	l = list(str(n))
	n = len(l)
	for i in range(n):
		l[i] = int(l[i])
	l = l[::-1].copy()
	l.append(0)
	c = 0
	for i in range(n):
		if l[i] == 0:
			continue
		if sum(l) <= s:
			break
		c += (10 - l[i]) * pow(10, i)
		l[i] = 0
		j = i + 1
		l[j] += 1
		while j < n and l[j] == 10:
			l[j] = 0
			j += 1
			l[j] += 1
	print(c)


import math
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	t = math.ceil(a / b)
	print(abs(b * t - a))


from collections import defaultdict as dd
import sys
input = sys.stdin.readline
t = int(input())
while t:
	(n, s) = input().split()
	s = int(s)
	nn = int(n)
	n = list(map(int, n.strip()))
	i = len(n) - 1
	su = sum(n)
	ans = 0
	po = 1
	num = 0
	if su <= s:
		print(0)
	else:
		while i >= 0 and su + 1 > s:
			su -= n[i]
			po = po * 10
			num = num + n[i] * (po // 10)
			ans = po - num
			i -= 1
		print(ans)
	t -= 1


l = int(input())
for i in range(l):
	(n, m) = map(int, input().split())
	print((n + m - 1) // m * m - n)


n = input()
integers = [input() for i in range(int(n))]
for i in integers:
	(a, b) = i.split()
	a = int(a)
	b = int(b)
	if a % b == 0:
		print(0)
		continue
	if a < b:
		print(b - a)
		continue
	else:
		div = a // b
		div += 1
		factor = div * b
		print(factor - a)


import sys, bisect
t = int(sys.stdin.readline())
for _ in range(t):
	(n, s) = sys.stdin.readline().split()
	ori = list(n)
	s = int(s)
	pref = [int(ori[0])]
	for i in range(1, len(ori)):
		pref.append(pref[i - 1] + int(ori[i]))
	if pref[-1] <= s:
		print(0)
		continue
	idx = bisect.bisect_left(pref, s)
	ori = ori[idx:]
	temp = 10 ** len(ori)
	print(temp - int(n[idx:]))


r = int(input())
v1 = 0
for u in range(1, r + 1):
	(v, d) = map(int, input().split())
	if v % d == 0:
		print(0)
	else:
		a = d - v % d
		print(a)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	if (a / b).is_integer():
		print(0)
		continue
	if b < a:
		c = a // b
		ans = b * (c + 1) - a
		print(ans)
	else:
		ans = b - a
		print(ans)


from math import ceil

def main():
	t = int(input())
	for _ in range(t):
		(a, b) = list(map(int, input().strip().split()))
		q = ceil(a / b)
		print(b * q - a)
main()


def sm(s):
	x = 0
	for i in str(s):
		x += int(i)
	return x
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	x = n
	i = 1
	l = len(str(n))
	f = 0
	if sm(x) <= s:
		print(x - n)
		continue
	while 1:
		if sm(x) <= s and x > n:
			f = 1
			break
		x = n // pow(10, i)
		x = x * pow(10, i)
		x += pow(10, i)
		i += 1
	print(x - n)


def checkSum(n, s):
	j = 0
	k = len(n)
	r = int(n)
	sum = 0
	while r > 0:
		sum += r % 10
		r = r // 10
	if sum <= s:
		return 0
	else:
		m = 0
		sum = 0
		while sum < s:
			sum += int(n[j])
			j += 1
		if j - 1 == 0:
			m = m * 10 + 1
			for i in range(k):
				m = m * 10 + 0
		else:
			for i in range(j - 2):
				m = m * 10 + int(n[i])
			m = m * 10 + (int(n[j - 2]) + 1)
			for i in range(k - j + 1):
				m = m * 10 + 0
		return m - int(n)
q = []
t = int(input())
for _ in range(t):
	l = list(input().split())
	s = int(l[1])
	n = l[0]
	q.append(checkSum(n, s))
for i in q:
	print(i)


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		(A, B) = [int(x) for x in input().split()]
		if A % B == 0:
			print(0)
		else:
			print(-(-A // B) * B - A)
main()


def sumofdigits(n):
	n = str(n)
	sum1 = 0
	for i in n:
		sum1 += int(i)
	return sum1
t = int(input())
for i in range(t):
	(n, s) = list(map(int, input().split()))
	value = sumofdigits(n)
	if value <= s:
		print(0)
	elif s == 1:
		tempn = n
		solo = len(str(n))
		d = pow(10, solo)
		print(d - tempn)
	else:
		tempn = str(n)
		sum1 = 1
		for i in range(len(tempn)):
			sum1 += int(tempn[i])
			if sum1 > s:
				flag = i
				break
		l = len(tempn) - flag
		p = pow(10, l)
		arr = tempn[flag:]
		print(p - int(arr))


t = int(input())
for i in range(t):
	ab = list(map(int, input().split()))
	a = ab[0]
	b = ab[1]
	steps = 0
	rest = a % b
	if rest == 0:
		print(steps)
	else:
		steps = b - rest
		print(steps)


n = int(input())
import math

def solve(a, b):
	if a % b == 0:
		return 0
	else:
		options = []
		extra = a % b
		if extra == a:
			options.append(b - a)
		else:
			i = int(a / b)
			j = math.ceil(a / b)
			options.append(b * j - a)
	return min(options)
for x in range(n):
	(a, b) = map(int, input().split())
	print(solve(a, b))


for test in range(int(input())):
	A = list(map(int, input().split()))
	div = int(A[0] / A[1])
	if A[0] % A[1] == 0:
		print('0')
	else:
		print(A[1] * (div + 1) - A[0])


from collections import defaultdict, Counter
import heapq
import math
import sys
import os
di = {}
arr = []
dd = defaultdict(list)

def solve():
	(a, b) = [int(i) for i in input().split(' ')]
	if a % b == 0:
		print(0)
	elif b > a:
		print(b - a)
	else:
		print(b - a % b)
T = int(input())
for i in range(T):
	solve()


t = int(input())
if 1 <= t <= 10 ** 4:
	for i in range(t):
		(a, b) = input().split()
		a = int(a)
		b = int(b)
		if a % b == 0:
			print(0)
		else:
			p = a // b + 1
			q = p * b - a
			print(q)


a = int(input())
liste = []
for i in range(a):
	b = input()
	b = [int(i) for i in b.split(' ')]
	liste.append(b)
for i in range(len(liste)):
	if liste[i][0] % liste[i][1] != 0:
		n = liste[i][0] // liste[i][1] + 1
		m = n * liste[i][1] - liste[i][0]
		print(m)
	else:
		print('0')


def ekline():
	t = int(input())
	for i in range(t):
		(a, b) = map(int, input().split())
		if a % b != 0:
			if a > b:
				c = b * (a // b + 1)
				print(c - a)
			elif a < b:
				print(b - a)
		else:
			print(0)
ekline()


t = int(input())
for i2 in range(t):
	(x, y) = map(int, input().split())
	if x % y == 0:
		print(0)
	else:
		print(y - x % y)


t = int(input())
for _ in range(t):
	(n, s) = map(int, input().split())
	nsum = 0
	ns = str(n)
	for ni in ns:
		nsum += int(ni)
	if nsum <= s:
		print(0)
		continue
	for i in range(19):
		p = pow(10, i + 1)
		plus = p - n % p
		new_n = n + plus
		ns = str(new_n)
		nsum = 0
		for ni in ns:
			nsum += int(ni)
		if nsum <= s:
			print(plus)
			break


n = int(input())
answers = []
numbers = [input() for _ in range(n)]
for _ in numbers:
	(a1, a2) = map(int, _.split())
	dif = int(a1 % a2)
	if dif != 0:
		ans = a2 - dif
	else:
		ans = 0
	answers.append(ans)
[print(_) for _ in answers]


t = int(input())
for _ in range(t):
	(a, b) = [int(i) for i in input().split()]
	div = a / b
	if div == a // b:
		print(0)
	else:
		print((a // b + 1) * b - a)


inp = int(input())
lt = []
for i in range(inp):
	lt.append(input().split())
for i in lt:
	a = int(i[0])
	b = int(i[1])
	if a % b == 0:
		print('0')
	else:
		print((a // b + 1) * b - a)


import math

def divisiblity(a, b):
	c = a % b
	if c == 0:
		return 0
	return b - c
cases = int(input())
for _ in range(cases):
	(a, b) = list(map(int, input().split()))
	print(divisiblity(a, b))

def beautiful_string(n, k):
	a = int((math.sqrt(8 * k + 1) - 1) / 2) + 1
	b = k - int(a * (a - 1) / 2)
	if b == 0:
		s = 'a' * (n - a) + 'bb' + 'a' * (a - 2)
		return s
	else:
		s = 'a' * (n - a - 1) + 'b' + 'a' * (a - b) + 'b' + 'a' * (b - 1)
		return s

def ternary_xor(x):
	a = ''
	b = ''
	c = True
	for i in x:
		if i == '0':
			a += '0'
			b += '0'
		elif i == '1':
			if c:
				a += '1'
				b += '0'
				c = False
			else:
				a += '0'
				b += '1'
		elif c:
			a += '1'
			b += '1'
		else:
			a += '0'
			b += '2'
	return (a, b)


N = int(input())
for _ in range(0, N):
	(a, b) = list(map(int, input().split(' ')))
	if a < b:
		print(b - a)
	elif a % b == 0:
		print(0)
	else:
		tmp = int(a / b) + 1
		print(tmp * b - a)


from sys import stdin
for _ in range(int(stdin.readline())):
	(a, b) = map(int, stdin.readline().split())
	k = a % b
	if k == 0:
		print(0)
	else:
		print(abs(b - k))


for i in range(int(input())):
	(a, b) = map(int, input().split())
	ans = 0
	if a % b == 0:
		print(0)
	else:
		q = a // b
		g = b * (q + 1)
		ans = g - a
		print(ans)


for x in range(int(input())):
	(a, b) = map(int, input().split())
	if b > a:
		print(b - a, end='\n')
	elif a % b == 0:
		print(0, end='\n')
	else:
		print(b - a % b, end='\n')


def calc(n, s):
	curr = 0
	n1 = str(n)
	for i in range(len(n1)):
		curr += ord(n1[i]) - ord('0')
	if curr <= s:
		return 0
	curr = 0
	i = 0
	while i < len(n1) and curr + int(n1[i]) + 1 <= s:
		curr += ord(n1[i]) - ord('0')
		i += 1
	return 10 ** (len(n1) - i) - int(n1[i:])
t = int(input())
for i in range(t):
	(n, s) = list(map(int, input().split()))
	print(calc(n, s))


def sum_digits(stri):
	out = 0
	for i in range(len(stri)):
		out += int(stri[i])
	return out

def findLastNonZero(n):
	for i in range(len(n)):
		if n[len(n) - i - 1] != '0':
			return len(n) - i - 1
lol = int(input())
for i in range(lol):
	nums = input().split()
	n = nums[0]
	s = int(nums[1])
	moves = 0
	while sum_digits(n) > s:
		curr_pos = findLastNonZero(n)
		curr_digit = len(n) - curr_pos - 1
		curr_num = int(n[curr_pos])
		n = int(n)
		temp = (10 - curr_num) * 10 ** curr_digit
		n += temp
		n = str(n)
		moves += temp
	print(moves)


import sys
input = sys.stdin.readline
t = int(input())
for ii in range(t):
	(n, s) = map(int, input().split())
	num = [int(i) for i in str(n)]
	if sum(num) <= s:
		print(0)
	else:
		(i, k) = (len(num) - 1, 0)
		while i > -1:
			if num[i] != 0:
				num[i] = 0
				k = i
			l = -2
			for l in range(k - 1, -1, -1):
				if num[l] != 9:
					num[l] += 1
					break
				else:
					num[l] = 0
			if l > -2:
				i = l
			else:
				i -= 1
			if sum(num) <= s and int(''.join(map(str, num))) >= n:
				tmp = int(''.join(map(str, num)))
				sys.stdout.write(str(tmp - n) + '\n')
				break
		else:
			num.insert(0, 1)
			tmp = int(''.join(map(str, num)))
			sys.stdout.write(str(tmp - n) + '\n')


import math

def sod(n):
	if n < 10:
		return n
	return n % 10 + sod(n // 10)

def func(s):
	flag = False
	for i in range(len(s) - 1, -1, -1):
		if s[i] != '9':
			ans = s[:i] + str(int(s[i]) + 1) + '0' * (len(s) - i - 1)
			flag = True
			break
	if flag:
		return ans
	return '1' + len(s) * '0'
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	k = sod(n)
	if k <= s:
		print(0)
		continue
	n1 = str(n)
	if k > s:
		sum = 0
		kp = ''
		for i in range(len(n1)):
			sum += int(n1[i])
			if sum >= s:
				ans = func(kp) + '0' * (len(n1) - i)
				print(int(ans) - n)
				break
			kp += n1[i]


def solve():
	for _ in range(ii()):
		(a, b) = mi()
		mod = a % b
		if mod == 0:
			print(0)
		else:
			print(b - mod)
ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
si = lambda : input()
solve()


def sod(n):
	return sum(list(map(int, list(str(n)))))

def blah(n):
	nz = 0
	sn = str(n)
	while sn[-1] == '0':
		sn = sn[:-1]
		nz += 1
	bl = 10 ** (nz + 1)
	return n + (bl - n % bl)
for t in range(int(input())):
	(n, s) = map(int, input().split())
	nw = n
	while sod(nw) > s:
		nw = blah(nw)
	print(nw - n)


t = int(input())
i = 0
while i < t:
	s = input()
	s = s.split(' ')
	s[0] = int(s[0])
	s[1] = int(s[1])
	if s[0] % s[1] == 0:
		print('0')
	else:
		a = s[0] // s[1] + 1
		a = a * s[1]
		a = a - s[0]
		print(a)
	i += 1


import math
for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	if b > a:
		print(b - a)
	else:
		nextMultiple = math.ceil(a / b)
		print(b * nextMultiple - a)


t = int(input())
for i in range(t):
	temp = input()
	(a, b) = temp.split(' ')
	a = int(a)
	b = int(b)
	if a % b == 0:
		print(0)
	else:
		print(b - a % b, '\n')


from sys import stdin, stdout
n = int(stdin.readline())
for i in range(n):
	ar = [int(x) for x in stdin.readline().split()]
	if ar[0] % ar[1] == 0:
		ans = 0
	else:
		ans = ar[1] - ar[0] % ar[1]
	stdout.write(str(ans) + '\n')


t = int(input())
for _ in range(t):
	(n, s) = map(int, input().split())
	digits = [int(x) for x in str(n)][::-1] + [0]
	dsum = sum(digits)
	i = 0
	while i < n:
		if dsum <= s:
			break
		dsum -= digits[i]
		digits[i] = 0
		i += 1
		while digits[i] == 9:
			dsum -= 9
			digits[i] = 0
			i += 1
		digits[i] += 1
		dsum += 1
	print(sum((e * 10 ** i for (i, e) in enumerate(digits))) - n)


def sumdigits(n):
	s = 0
	while n > 0:
		s = s + n % 10
		n = n // 10
	return s

def solve(n, s):
	cur_sum = sumdigits(n)
	if sumdigits(n) <= s:
		return 0
	steps = 0
	while n % 10 != 0:
		n += 1
		cur_sum += 1
		steps += 1
	cur_sum = -8
	return solve(n // 10, s) * 10 + steps
for i in range(int(input())):
	(n, s) = map(int, input().split())
	print(solve(n, s))


def solve(n, s, ans):
	total = 0
	n = list(str(n))
	for i in range(len(n)):
		n[i] = int(n[i])
		total += n[i]
	if total <= s:
		ans.append('0')
		return
	moves = 0
	index = 0
	while n and total > s:
		last = n.pop()
		total -= last
		moves += (10 - last) * pow(10, index)
		index += 1
		total += 1
		if n:
			i2 = len(n) - 1
			while i2 >= 0:
				if n[i2] == 9:
					total -= 9
					n[i2] = 0
					i2 -= 1
				else:
					n[i2] += 1
					break
			if i2 == -1:
				n.insert(0, 1)
		else:
			n.append(1)
	ans.append(str(moves))

def main():
	t = int(input())
	ans = []
	for i in range(t):
		(n, s) = map(int, input().split())
		solve(n, s, ans)
	print('\n'.join(ans))
main()


import sys

def solve(n, s):
	digits = [int(x) for x in str(n)]
	if sum(digits) <= s:
		return 0
	if digits[0] > s:
		targ = int('1' + '0' * len(digits))
		return targ - n
	lft = [0]
	nd = 0
	while sum(lft) < s:
		lft.append(digits[nd])
		nd += 1
	if True:
		ith = nd - 1
		while lft[ith] == 9:
			ith -= 1
		lft[ith] += 1
		lft = lft[:ith + 1]
		lft.extend([0] * (len(digits) - ith))
		targ = int(''.join([str(x) for x in lft]))
	return targ - n
IN = [x.strip() for x in sys.stdin.readlines()]
T = int(IN[0])
cur = 0
for ti in range(T):
	(n, s) = [int(x) for x in IN[cur + 1].split(' ')]
	res = solve(n, s)
	print(res)
	cur += 1


import sys
import math, bisect
sys.setrecursionlimit(10 ** 5)
from collections import defaultdict
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, OrderedDict

def I():
	return int(sys.stdin.readline())

def neo():
	return map(int, sys.stdin.readline().split())

def Neo():
	return list(map(int, sys.stdin.readline().split()))
for _ in range(I()):
	(n, s) = input().split()
	w = n
	p = int(n)
	(n, s) = (list(map(int, n)), int(s))
	if sum(n) <= s:
		print(0)
		continue
	(q, i) = (0, 0)
	while q + n[i] < s:
		q += n[i]
		i += 1
	(t, r) = (10 ** (len(n) - i), 0)
	if i > 0:
		r = int(w[:i]) * t
	print(r + t - p)


def check(n, b):
	(s, x) = (str(n), 0)
	for i in s:
		x += int(i)
	if x <= b:
		return 1
	else:
		return 0
for p in range(int(input())):
	(a, b) = map(int, input().split())
	if check(a, b):
		print(0)
	elif int(str(a)[0]) < b:
		s = int(str(a)[0])
		for i in range(len(str(a)) - 1):
			s += int(str(a)[i + 1])
			if s >= b:
				print(10 ** (len(str(a)) - i - 1) - a % 10 ** (len(str(a)) - i - 1))
				break
		else:
			print(0)
	else:
		print(10 ** len(str(a)) - a)


import math
import sys
input = sys.stdin.readline

def inp():
	return int(input())

def invr():
	return list(map(int, input().split()))
t = inp()
while t > 0:
	(a, b) = invr()
	print(0 if a % b == 0 else (int(a / b) + 1) * b - a)
	t -= 1


from sys import stdin
input = stdin.readline
import bisect
import math
for xoxo in range(1):
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		p = math.ceil(n / k)
		print(k * p - n)


debug = False
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	rem = a % b
	print((b - rem) % b)


t = int(input())
for query in range(t):
	ab = input().split()
	a = int(ab[0])
	b = int(ab[1])
	counter = 0
	if a < b:
		print(b - a)
	elif a % b == 0:
		print(0)
	else:
		print(b - a % b)


import math
from collections import defaultdict
for _ in range(int(input())):

	def ans(n):
		co = 0
		while True:
			if n == 0:
				break
			co += n % 10
			n = n // 10
		return co
	(n, s) = list(map(int, input().split()))
	temp = n
	ln = list(str(n))
	an = 0
	for i in range(len(ln)):
		if ans(temp + an) <= s:
			break
		ln.reverse()
		if ln[i] != '0':
			k = 10 - int(ln[i])
			k = k * 10 ** i
			an += k
			if i != len(ln) - 1:
				ln[i + 1] = str(int(ln[i + 1]) + 1)
		ln.reverse()
	print(an)


for i in range(int(input())):
	(b, c) = map(int, input().split())
	g = b // c
	if b % c == 0:
		print('0')
	else:
		f = g + 1
		print(c * f - b)


import math
from decimal import Decimal
import heapq
import copy
import heapq
from collections import deque
from collections import defaultdict
MOD = 1000000007

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = map(int, input().split())
	return (n, m)

def da():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	return (n, m, a)

def dva():
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	return (n, m, b)

def eratosthenes(n):
	sieve = list(range(n + 1))
	for i in sieve:
		if i > 1:
			for j in range(i + i, len(sieve), i):
				sieve[j] = 0
	return sorted(set(sieve))

def lol(lst, k):
	k = k % len(lst)
	ret = [0] * len(lst)
	for i in range(len(lst)):
		if i + k < len(lst) and i + k >= 0:
			ret[i] = lst[i + k]
		if i + k >= len(lst):
			ret[i] = lst[i + k - len(lst)]
		if i + k < 0:
			ret[i] = lst[i + k + len(lst)]
	return ret

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

def dvs():
	n = int(input())
	m = int(input())
	return (n, m)

def fact(n):
	tc = []
	ans = {}
	d = 2
	while d * d <= n:
		if n % d == 0:
			tc.append(d)
			n //= d
		else:
			d += 1
	if n > 1:
		tc.append(n)
	for i in tc:
		ans[i] = ans.get(i, 0) + 1
	return ans

def to_zero(n, s):
	lst = s[0]
	ans = []
	for i in range(n):
		if lst == s[i]:
			continue
		elif lst == '0':
			lst = '1'
			ans.append(i)
		else:
			lst = '0'
			ans.append(i)
	if lst == '1':
		ans.append(n)
	return ans

def divs(n):
	ans = 0
	while n:
		ans += n % 10
		n = n // 10
	return ans
for i in range(int(input())):
	(n, s) = map(int, input().split())
	k = 0
	p = 10
	while divs(n) > s:
		k += p - n % p
		n += p - n % p
		p *= 10
	print(k)


def solve(a, b):
	move = 0
	if a <= b:
		move = b - a
		return print(move)
	elif a % b == 0:
		return print(move)
	else:
		yu = a % b
		move = b - yu
		return print(move)
t = int(input())
for _n in range(0, t):
	(a, b) = map(int, input().split(' '))
	solve(a, b)


import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
for case in range(int(input())):
	(n, s) = [int(x) for x in input().split()]
	if sum((int(x) for x in str(n))) > s:
		sum_ = 0
		for (i, c) in enumerate(str(n)):
			x = int(c)
			if sum_ + x + 1 > s:
				ans = 10 ** (len(str(n)) - i) - int(str(n)[i:])
				print(ans)
				break
			sum_ += x
	else:
		ans = 0
		print(ans)


from sys import stdin
import math
inp = lambda : stdin.readline().strip()
t = int(inp())
for i in range(t):
	(a, b) = [int(x) for x in input().split()]
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


for _ in range(int(input())):
	(n, s) = input().split()
	nstr = '0' + n
	n = int(n)
	s = int(s)
	sumo = 0
	ans = ''
	ct = 0
	sn = 0
	for i in nstr:
		sn += int(i)
	if sn <= s:
		print(0)
		continue
	for i in nstr:
		ct += 1
		if sumo + int(i) < s:
			ans += i
			sumo += int(i)
		else:
			break
	ans = str(int(ans) + 1)
	ans = ans + '0' * (len(nstr) - ct + 1)
	print(int(ans) - n)


n = int(input())
l = []
for i in range(n):
	(a, b) = map(int, input().split())
	k = 0
	if b == 0:
		l.append(k)
	elif a % b == 0:
		l.append(k)
	else:
		k = (a // b + 1) * b - a
		l.append(k)
for i in range(n):
	print(l[i])


n = int(input())
matrix = []
for i in range(n):
	matrix.append([int(i) for i in input().split()])
for i in range(len(matrix)):
	if int(matrix[i][0] % matrix[i][1]) == 0:
		print(0)
	else:
		print((int(matrix[i][0] / matrix[i][1]) + 1) * matrix[i][1] - matrix[i][0])


for _ in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	if a % b == 0:
		print(0)
	else:
		div = a // b
		print(b * (div + 1) - a)


from sys import stdin
input = lambda : stdin.readline()
from math import ceil
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	k = a // b
	if a % b == 0:
		print(0)
	else:
		print((k + 1) * b - a)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	sum1 = 0
	nd1 = 0
	nd2 = 0
	stop = 0
	sum2 = 0
	rev = int(str(a)[::-1])
	sa = a
	while a != 0:
		sum1 += a % 10
		a = a // 10
		nd1 = nd1 + 1
		if sum2 + rev % 10 < b:
			sum2 += rev % 10
			stop = rev % 10 + stop * 10
			rev = rev // 10
			nd2 += 1
	if sum1 <= b:
		print(0)
	else:
		stop += 1
		stop = stop * 10 ** (nd1 - nd2)
		print(stop - sa)


def soma_total(n):
	result = 0
	while n != 0:
		result += n % 10
		n //= 10
	return result
numTestes = int(input())
for x in range(numTestes):
	(numero, s) = [int(i) for i in input().split()]
	contUnidade = 1
	result = 0
	atual = 0
	for count in range(len(str(numero))):
		if soma_total(numero) <= s:
			break
		aux = (10 - numero // contUnidade % 10) * contUnidade
		numeroAt = numero + aux
		result += aux
		contUnidade *= 10
		numero = numeroAt
	print(int(result))


from sys import stdin
r = stdin.readline

def main():
	cases = int(r())
	for case in range(cases):
		(a, b) = map(int, r().strip().split())
		print(b - a % b if a % b != 0 else 0)
main()


def get_divisor(first, second):
	if first % second != 0:
		return second - first % second
	return 0
queries = int(input())
for _ in range(queries):
	(a, b) = map(int, input().split())
	print(get_divisor(a, b))


def sumn(n):
	cnt = 0
	while n != 0:
		cnt += n % 10
		n //= 10
	return cnt
t = int(input())
for i in range(t):
	(n, s) = map(int, input().split())
	diff = sumn(n) - s
	if sumn(n) <= s:
		print(0)
	else:
		k = 10
		val = 1
		cnt = 0
		np = n + 0
		for x in range(18):
			n += 1 * k - n % k
			if sumn(n) <= s:
				print(n - np)
				break
			k *= 10


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	new = list(str(n))
	sm = 0
	ans = 0
	for i in new:
		sm += int(i)
	if sm > s:
		step = 0
		for i in range(len(new) - 1, -1, -1):
			if sm > s:
				step += (10 - int(new[i])) * pow(10, len(new) - 1 - i)
				sm -= int(new[i]) - 1
				new[i - 1] = str(int(new[i - 1]) + 1)
			else:
				ans = step
				break
		if ans == 0:
			if sm > s:
				step += (10 - int(new[0])) * pow(10, len(new) - 1)
				ans = step
			else:
				ans = step
	print(ans)


x = int(input())
for i in range(0, x):
	(start, end) = map(int, input().split())
	if start % end == 0:
		print(0)
	else:
		print(start - start % end + end - start)


l_del = []
kol = int(input())
for i in range(kol):
	(a, b) = map(int, input().split())
	if a % b != 0:
		l_del.append(b - a % b)
	else:
		l_del.append(0)
for i in range(kol):
	print(l_del[i])


def fun2(s, n):
	ans = 0
	for i in range(n):
		ans += ord(s[i]) - 48
	return ans

def fun(s, n, x):
	for i in reversed(range(1, n)):
		s2 = s[0:i]
		temp = fun2(s2, i)
		if temp < x:
			temp2 = int(s[i:n])
			return 10 ** (n - i) - temp2
	temp2 = int(s)
	temp3 = 10 ** n
	return temp3 - temp2
t = int(input())
while t > 0:
	t -= 1
	(n, s) = map(int, input().split())
	s2 = str(n)
	l = len(s2)
	n2 = fun2(s2, l)
	if n2 <= s:
		print(0)
	else:
		print(fun(s2, l, s))


from collections import deque
import math
import os
import random
import re
import sys

def main():
	t = int(input())
	for i in range(t):
		(a, b) = map(int, input().split())
		if a % b == 0:
			print('0')
		else:
			print(b - a % b)
	return 0
main()


def main():
	T = int(input())
	for i in range(T):
		(a, b) = list(map(int, input().split()))
		print((b - a % b) % b)
main()


n = int(input())
for _ in range(n):
	(a, b) = map(lambda x: int(x), input().split())
	print((b - a % b) % b)


import sys
from functools import lru_cache
from heapq import merge, heapify, heappop, heappush
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as c
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def outln(var):
	sys.stdout.write(str(var) + '\n')

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	(a, b) = sp()
	temp = ceil(a / b)
	outln(temp * b - a)


for i in range(int(input())):
	(a, b) = list(map(int, input().strip().split()))
	if a % b == 0:
		print('0')
	else:
		s = a // b + 1
		print(s * b - a)


import math
inputs = int(input())
for inp in range(inputs):
	list1 = list(map(int, input().split()))
	a = list1[0]
	b = list1[1]
	if a % b == 0:
		print(0)
	else:
		c = b * math.ceil(a / b)
		print(c - a)


n = int(input(''))
l = []
for i in range(n):
	s = input('')
	(a, b) = s.split(' ')
	a = int(a)
	b = int(b)
	if a % b == 0:
		l.append(0)
	else:
		temp = a % b
		l.append(b - temp)
for i in l:
	print(i)


from math import *
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if sum(map(int, str(a))) <= b:
		print(0)
		continue
	if int(str(a)[0]) < b:
		s = int(str(a)[0])
		for i in range(len(str(a)) - 1):
			s += int(str(a)[i + 1])
			if s >= b:
				print(10 ** (len(str(a)) - i - 1) - a % 10 ** (len(str(a)) - i - 1))
				break
		else:
			print(0)
	else:
		print(10 ** len(str(a)) - a)


from sys import stdin, stdout
from os import path
if path.exists('input.txt'):
	stdin = open('input.txt', 'r')
for _ in range(int(stdin.readline())):
	(x, y) = map(str, stdin.readline().split())
	y = int(y)
	org = int(x)
	sum = 0
	for i in range(len(x)):
		sum += int(x[i])
	if sum > y:
		for i in range(len(x) - 1, -1, -1):
			if sum - int(x[i]) < y:
				x = x[:i] + '0' + x[i + 1:]
				if i == 0:
					x = '1' + x
				else:
					j = i - 1
					while True:
						if x[j] == '9' and j > 0:
							x = x[:j] + '0' + x[j + 1:]
						elif j == 0 and x[j] == '9':
							x = x[:j] + '0' + x[j + 1:]
							x = '1' + x
							break
						elif x[j] != '9':
							x = x[:j] + chr(ord(x[j]) + 1) + x[j + 1:]
							break
						j -= 1
				break
			sum -= int(x[i])
			x = x[:i] + '0' + x[i + 1:]
	print(int(x) - org)


t = int(input())
for d in range(t):
	temp = input().split()
	a = int(temp[0])
	b = int(temp[1])
	if a % b != 0:
		a = (a // b + 1) * b
	print(a - int(temp[0]))


noos = int(input())
for n in range(noos):
	c = str(input())
	c = c.split()
	if int(c[1]) > int(c[0]):
		print(int(c[1]) - int(c[0]))
	else:
		z = int(c[0]) % int(c[1])
		if z != 0:
			print(int(c[1]) - z)
		else:
			print(z)


t = int(input())
while t != 0:
	(a, b) = map(int, input().split())
	k = a % b
	print((b - k) % b)
	t -= 1


import sys
from collections import deque
input = sys.stdin.readline

def digitSum(n):
	ans = 0
	a = n
	while a:
		ans += a % 10
		a = a // 10
	return ans
T = int(input())
for i in range(T):
	(n, s) = map(int, input().split())
	multen = 1
	ans = 0
	while digitSum(n) > s:
		b = n // multen % 10
		b = 0 if b == 0 else 10 - b
		ans += multen * b
		n += multen * b
		multen *= 10
	print(ans)


t = int(input())

def check_sum(n):
	s = 0
	for i in n:
		s += int(i)
	return s
while t:
	a = input().split()
	(n, s) = (int(a[0]), int(a[1]))
	moves = 0
	sumi = check_sum(str(n))
	if sumi <= s:
		print(0)
		t -= 1
		continue
	l = len(str(n))
	cnt = 1
	orig = str(n)
	old_no = str(n)
	while sumi > s:
		new_no = orig[0:l - cnt] + '9' * cnt
		moves = int(new_no) - int(orig)
		sumi = check_sum(orig[0:l - cnt]) + 1
		cnt += 1
	print(moves + 1)
	t -= 1


f = lambda x: sum(map(int, str(x)))
for t in range(int(input())):
	(n, s) = list(map(int, input().split()))
	if f(n) <= s:
		print(0)
		continue
	for i in range(1, 19):
		z = int('1' + '0' * i)
		k = (n + z) // z * z
		if f(k) <= s:
			print(k - n)
			break


n = int(input())
l = [input() for i in range(n)]
for j in l:
	a = int(j.split()[0])
	b = int(j.split()[1])
	print((a // b + 1) * b - a if a % b != 0 else '0')


from sys import stdin, stdout
from math import ceil

def ds(n):
	total = 0
	for i in str(n):
		total += int(i)
	return total

def main():
	t = int(stdin.readline())
	for _ in range(t):
		(n, s) = [int(i) for i in stdin.readline().split()]
		for i in range(0, 25):
			exp = 10 ** i
			pot = 0
			if n % exp == 0:
				pot = n
			else:
				pot = n - n % exp
				pot += exp
			diff = pot - n
			if ds(pot) > s:
				continue
			stdout.write('{}\n'.format(diff))
			break
main()


import math

def main():
	try:
		n = int(input())
		if not 1 <= n <= 10 ** 4:
			exit(1)
		inputList = []
		for i in range(n):
			temp = list(map(int, input().split()))
			if len(temp) != 2 or temp[0] < 1 or temp[1] > 10 ** 9:
				exit(1)
			inputList.append(temp)
		total = []
		for array in inputList:
			if array[0] % array[1] == 0:
				total.append(0)
			else:
				total.append(math.ceil(array[0] / array[1] * 1.0) * array[1] - array[0])
		for item in total:
			print(item)
	except:
		exit(1)
main()


for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	if n % k == 0:
		print(0)
	else:
		print((n // k + 1) * k - n)


N = int(input())
a = []
b = []
for i in range(N):
	vs = input().split()
	a.append(int(vs[0]))
	b.append(int(vs[1]))
for i in range(N):
	o = a[i] % b[i]
	if o == 0:
		print(0)
	else:
		print(b[i] - o)


def get_min(n, s):
	str_n = str(n)
	d = len(str_n)
	count = 0
	sum_digits = sum([int(i) for i in str_n])
	if sum_digits <= s:
		return 0
	for i in range(d):
		count += int(str_n[i])
		if count > s or (count == s and sum_digits > s):
			return 10 ** (d - i) - int(str_n[i:])
t = int(input())
for i in range(t):
	(n, s) = list(map(int, input().split()))
	print(get_min(n, s))


a = int(input())
l = []
while a:
	l.append([int(x) for x in input().split()])
	a -= 1
for i in l:
	if i[0] % i[1] == 0:
		print(0)
	else:
		print((i[1] - i[0]) % i[1])


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, s) = map(int, input().split())
	N = []
	for i in str(n):
		N.append(int(i))
	N.reverse()
	N.append(0)
	ans = 0
	for i in range(len(str(n))):
		if sum(N) <= s:
			break
		if N[i] == 0:
			continue
		ans += (10 - N[i]) * pow(10, i)
		N[i] = 0
		N[i + 1] += 1
	print(ans)


from sys import stdin
for _ in range(int(input())):
	(n, s) = map(str, stdin.readline().split())
	s = int(s)
	a = [0]
	for i in n:
		a.append(int(i))
	b = [0] * len(a)
	i = len(a) - 1
	while sum(a) > s:
		b[i] = 10 - a[i]
		a[i] = 0
		a[i - 1] += 1
		i -= 1
	for i in range(len(b) - 1, 0, -1):
		if b[i] >= 10:
			b[i - 1] += b[i] // 10
			b[i] %= 10
	ind = 0
	for i in range(len(b)):
		if b[i] != 0:
			ind = i
			break
	if sum(b) == 0:
		print('0')
		continue
	for i in range(ind, len(b)):
		print(b[i], end='')
	print()


for _ in range(int(input())):
	(a, b) = [int(i) for i in input().split()]
	if b * (a // b + 2 - 1) - a == b:
		print(0)
	else:
		print(b * (a // b + 2 - 1) - a)


for i in range(int(input())):
	(n, m) = [int(s) for s in input().split()]
	ans = (m - n % m) % m
	print(ans)


def moves(n, k):
	total = 0
	for j in range(len(n)):
		total += int(n[j])
	if total <= k:
		return 0
	total = 0
	n = '0' + n
	i = 1
	while total + int(n[i]) < k:
		total += int(n[i])
		i += 1
	num = (int(n[:i]) + 1) * 10 ** (len(n) - i)
	return num - int(n)
T = int(input())
for t in range(T):
	(n, k) = input().split(' ')
	print(moves(n, int(k)))


test = int(input())
for i in range(test):
	(n1, n2) = list(map(int, input().split()))
	if n1 % n2 != 0:
		x = int(n1 / n2)
		x = x + 1
		y = n2 * x
		z = y - n1
		print(z)
	else:
		print('0')


import math, sys
t = int(sys.stdin.readline())
for _ in range(t):
	(a, b) = map(int, sys.stdin.readline().split())
	x = a % b
	y = a // b
	c = (y + 1) * b - a
	if c == b:
		print(0)
	else:
		print(c)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	t = n
	sm = 0
	q = 1
	while t:
		sm += t % 10
		t //= 10
	ans = 0
	while sm > s:
		ans += q * (10 - n % 10)
		n += 10 - n % 10
		sm = 0
		while n % 10 == 0:
			n //= 10
			q *= 10
		t = n
		while t:
			sm += t % 10
			t //= 10
	print(ans)


import sys

def get_div(a, b):
	if a % b == 0:
		return 0
	else:
		y = 0
		x = a % b
		y = x - b
		return abs(y)

def main():
	n = int(sys.stdin.readline())
	for i in range(n):
		(a, b) = map(int, sys.stdin.readline().split())
		sys.stdout.write(f'{get_div(a, b)}\n')
main()


def main():
	n = int(input())
	for _ in range(n):
		(n, m) = list(map(int, input().split()))
		if n % m == 0:
			print(0)
		else:
			print(m - n % m)
main()


def inp():
	t = int(input())
	G = []
	for i in range(t):
		(a, d) = list(map(int, input().split()))
		G.append([a, d])
	return G

def A(G):
	for (a, b) in G:
		if a % b:
			print(b - a % b)
		else:
			print(0)
A(inp())


for _ in range(int(input())):
	(n, s) = map(str, input().split())
	s = int(s)
	summa = 0
	steps = 0
	for item in n:
		summa += int(item)
	if summa > s:
		steps += 10 - int(n[-1])
		summa -= int(n[-1]) - 1
	counter = -1
	multi = 1
	while summa > s:
		counter -= 1
		multi *= 10
		item = int(n[counter])
		steps += multi * (9 - item)
		summa -= item
	print(steps)


test = int(input())
my_list = []
while test != 0:
	(a, b) = [int(a) for a in input().split()]
	moves = 1
	if a % b == 0:
		moves = 0
	else:
		rem = a % b
		moves = b - rem
	value = str(moves)
	my_list.append(value)
	test -= 1
for i in my_list:
	print(i)


count = int(input())
for i in range(count):
	massiv = input().split(' ')
	a = int(massiv[0])
	b = int(massiv[1])
	result = (b - a % b) % b
	print(result)


def abc(a, b):
	c = a % b
	if c == 0:
		return 0
	else:
		return abs(b - c)
t = int(input())
c = []
for i in range(t):
	(a, b) = list(map(int, input().rstrip().split()))
	result = abc(a, b)
	c.append(result)
for i in c:
	print(i)


from math import *
t = int(input())
lst_count = []
for i in range(t):
	div = int
	pls = int
	(a, b) = list(map(int, input().split()))
	if a % b == 0:
		lst_count.append(0)
	else:
		div = a / b
		pls = (floor(div) + 1) * b
		pls = pls - a
		lst_count.append(pls)
for i in lst_count:
	print(i)


t = int(input())
for _ in range(t):
	(n, s) = list(input().split())
	s = int(s)
	p = len(n)
	ncopy = n[::-1]
	ncopy = ncopy + '000000000000000000'
	ncopy = list(ncopy)
	summ = 0
	for j in n:
		summ += int(j)
	if summ <= s:
		print(0)
		continue
	diff = summ - s
	for i in range(p):
		cur = int(ncopy[i])
		if cur == 0:
			continue
		diff = diff - cur
		ncopy[i] = '0'
		j = 1
		while True:
			nc = int(ncopy[i + j])
			if nc != 9:
				nc = nc + 1
				ncopy[i + j] = str(nc)
				diff = diff + 1
				break
			else:
				ncopy[i + j] = '0'
				diff -= 9
				j += 1
		if diff <= 0:
			break
	ans = []
	ncopy = ncopy[::-1]
	st = 0
	for j in ncopy:
		if st == 1:
			ans.append(j)
			continue
		if int(j) != 0:
			st = 1
			ans.append(j)
	print(int(''.join(ans)) - int(n))


n = int(input())
numbers = []
result = []
for i in range(n):
	line = list(map(int, input().split(' ')))
	numbers.append(line)
for i in numbers:
	real = int(i[0] / i[1])
	res = i[1] * (real + int(1)) - i[0]
	if i[1] == res:
		result.append(0)
	else:
		result.append(res)
print(*result, sep='\n')


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	rem = a % b
	ints = a // b
	num = (ints + 1) * b
	if num - a == b:
		print(0)
	else:
		print(num - a)


def plus(it):
	global f
	if f[it] == 9:
		f[it] = 0
		plus(it + 1)
	else:
		f[it] += 1

def get_int(f):
	j = 0
	for i in range(len(f)):
		j += f[i] * 10 ** i
	return j
t = int(input())
m = 19
for qw in range(t):
	f = [0 for i in range(m)]
	(n, s) = input().split()
	s = int(s)
	for i in range(len(n) - 1, -1, -1):
		f[i] = int(n[len(n) - 1 - i])
	g = f.copy()
	for i in range(m):
		sm = sum(f)
		if sm <= s:
			print(get_int(f) - get_int(g))
			break
		f[i] = 0
		plus(i + 1)


t = int(input())
j = 0
while j < t:
	(a, b) = map(int, input().split())
	if a % b == 0:
		print('0')
	elif a % b != 0:
		if a < b:
			print(b - a)
		elif a > b:
			c = int(a / b) + 1
			print(c * b - a)
	j = j + 1


import math
a = int(input())
i = 0
result = []
for i in range(a):
	(a, b) = map(int, input().split())
	if a % b == 0:
		result.append(0)
	else:
		ost = math.ceil(a / b)
		b = b * ost
		q = b - a
		result.append(q)
print('\n'.join(map(str, result)))


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	n = str(n)
	n = list(n)
	for i in range(0, len(n)):
		n[i] = int(n[i])
	a = sum(n)
	if a <= s:
		print(0)
	else:
		n.reverse()
		ans = 0
		if 9 in n and n.count(9) == len(n):
			print(1)
		else:
			for i in range(0, len(n)):
				if a <= s:
					break
				elif n[i] == 0:
					continue
				elif i == len(n) - 1 and n[i] == 1:
					break
				else:
					ans += 10 ** i * (10 - n[i])
					n[i] = 0
					if i != len(n):
						car = 1
						for j in range(i + 1, len(n)):
							if n[j] == 9:
								n[j] = 0
								car = 1
							else:
								n[j] += 1
								car = 0
								break
						if car == 1:
							n.append(1)
					a = sum(n)
			print(ans)


import sys

def sod(x):
	ans = 0
	while x > 0:
		ans += x % 10
		x //= 10
	return ans

def solve(n, s):
	num = n
	v = len(str(n))
	answer = 0
	ind = 0
	flag = False
	while sod(n) > s:
		d = num % 10
		if flag:
			d += 1
			d %= 10
		if d > 0:
			n += (10 - d) * pow(10, ind)
			answer += (10 - d) * pow(10, ind)
			if sod(n) <= s:
				break
			flag = True
		num //= 10
		ind += 1
	return answer
t = int(sys.stdin.readline())
ans_arr = []
for i in range(t):
	[n, s] = [int(j) for j in sys.stdin.readline().split()]
	ans_arr.append(str(solve(n, s)))
print('\n'.join(ans_arr))


def fun(n):
	p = 0
	while n:
		p += n % 10
		n //= 10
	return p
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	orig = n
	while fun(n) > s:
		mod = 10
		while n % mod == 0:
			mod *= 10
		n += mod - n % mod
	print(n - orig)


t = int(input())
for i in range(t):
	(a, b) = list(map(int, input().split()))
	if a % b == 0:
		print(0)
	elif a < b:
		print(b - a)
	elif a > b:
		d = int(a // b) + 1
		print(d * b - a)


for i in range(int(input())):
	(a, b) = [int(j) for j in input().split()]
	print(b - a % b - b * int(a % b == 0))


def find_moves(lst):
	if lst[0] < lst[1]:
		num_moves = lst[1] - lst[0]
	elif lst[0] % lst[1] == 0:
		num_moves = 0
	else:
		num_moves = lst[1] - lst[0] % lst[1]
	return num_moves
n = int(input())
res = []
for i in range(n):
	(a, b) = map(int, input().split())
	temp = find_moves([a, b])
	res.append(temp)
for i in res:
	print(i)


import sys, os.path
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
sys.setrecursionlimit(10 ** 5)

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def solve():
	(_, __) = MI()
	if _ % __ == 0:
		flag = False
	else:
		flag = True
	if flag:
		print((_ // __ + 1) * __ - _)
	else:
		print(0)
for _ in range(II()):
	solve()


t = int(input())
h = 0
for i in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(h)
	else:
		k = a // b
		l = k + 1
		r = b * l
		s = r - a
		print(s)


def solve(a, b):
	divided = a / b
	if divided != int(divided):
		remainder = b * (int(divided) + 1) - a
	else:
		remainder = 0
	return remainder
count = int(input())
for i in range(count):
	(a, b) = list(map(int, input().split()))
	answer = solve(a, b)
	print(answer)


for kafkshka in range(int(input())):
	(n, q) = map(int, input().split())
	if n > q:
		x = n % q
		if n % q == 0:
			print('0')
		else:
			print(q - n % q)
	else:
		print(q - n)


n = int(input())
ar = list()
for i in range(n):
	(a, b) = [int(s) for s in input().split()]
	if a % b == 0:
		ar.append(0)
	else:
		ar.append(int((a // b + 1) * b - a))
for i in ar:
	print(i)


case = input()
for i in range(int(case)):
	data = input()
	data = data.split()
	(a, b) = [int(x) for x in data]
	if a % b == 0:
		print(0)
		continue
	print(b - a % b)


n = int(input())
res = []
for i in range(n):
	(a, b) = map(int, input().split())
	res.append(str((0, b - a % b)[a % b != 0]))
print('\n'.join(res))


T = int(input())
for testcase in range(T):
	[n, s] = [int(i) for i in input().split()]
	digits = [n // 10 ** i % 10 for i in range(19)]
	newdigits = [0] * 19
	if sum(digits) <= s:
		print(0)
		continue
	count = 0
	for i in range(18, -1, -1):
		if digits[i] < s:
			newdigits[i] = digits[i]
			s -= digits[i]
		elif digits[i] == s:
			if sum(digits[:i]) > 0:
				newdigits[i + 1] += 1
			else:
				newdigits[i] = digits[i]
			break
		else:
			newdigits[i + 1] += 1
			break
	for i in range(18):
		if newdigits[i] >= 10:
			newdigits[i] = 0
			newdigits[i + 1] += 1
	newn = 0
	for i in range(18, -1, -1):
		newn *= 10
		newn += newdigits[i]
	print(newn - n)


t = int(input())
for _ in range(t):
	(n, s) = map(int, input().split())
	m = str(n)
	if sum([int(i) for i in m]) <= s:
		print(0)
	else:
		lo = 0
		p = 0
		while int(m[lo]) + p < s:
			p += int(m[lo])
			lo += 1
		l = len(m) - lo
		x = m[:lo]
		if x == '':
			x = 0
		else:
			x = int(x)
		n1 = x * 10 ** l + 10 ** l
		print(n1 - n)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def integer():
	return int(inp())

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def solve():
	(n, s) = map(int, input().split())
	digsum = lambda x: sum(map(int, str(x)))
	t = n
	while digsum(t) > s:
		for (i, j) in enumerate(str(t)[::-1]):
			if int(j) > 0:
				t += (10 - int(j)) * 10 ** i
				break
	print(t - n)
testcase(int(inp()))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math
testcases = int(input())
for j in range(testcases):
	values = list(map(int, input().split()))
	t1 = math.ceil(values[0] / values[1])
	print(values[1] * t1 - values[0])


import sys
max = sys.maxsize
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	ans = (b - a) % b
	print(ans)


T = int(input())
for i in range(T):
	(N, K) = list(map(int, input().split()))
	if N % K == 0:
		print(0)
	else:
		print(K - N % K)


t = int(input())
for _ in range(t):
	line = input()
	line = list(map(int, line.split()))
	(a, b) = line
	if a >= b:
		c = (b - a % b) % b
		print(c)
	else:
		print(b - a)


digitsum = lambda a: sum(map(int, list(str(a))))

def list_to_int(arr):
	ret = 0
	for (pow, a) in enumerate(arr):
		ret += a * 10 ** pow
	return ret
for TC in range(int(input())):
	(n, s) = map(int, input().split())
	orglen = len(str(n))
	moves = idx = 0
	while 1:
		list_num = list(map(int, list(str(n))))
		if digitsum(n) <= s:
			break
		tlist = []
		for i in range(idx + 1):
			tlist.append(list_num[len(list_num) - i - 1])
		if tlist.count(0) == len(tlist):
			idx += 1
			continue
		tmp = 10 ** (idx + 1) - list_to_int(tlist)
		n += tmp
		moves += tmp
		idx += 1
		if idx + 1 > orglen:
			break
	print(moves)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	c = a % b
	if c > 0:
		print(b - c)
		continue
	print('0')


def solve(arr):
	if arr[0] % arr[1] == 0:
		return 0
	else:
		return abs(arr[0] % arr[1] - arr[1])
for i in range(int(input())):
	print(solve(list(map(int, input().split(' ')))))


t = int(input())
for ii in range(t):
	(n, s) = map(int, input().split())
	num = [int(i) for i in str(n)]
	if sum(num) <= s:
		print(0)
	else:
		(i, k) = (len(num) - 1, 0)
		while i > -1:
			if num[i] != 0:
				num[i] = 0
				k = i
			l = -2
			for l in range(k - 1, -1, -1):
				if num[l] != 9:
					num[l] += 1
					break
				else:
					num[l] = 0
			if l > -2:
				i = l
			else:
				i -= 1
			if sum(num) <= s and set(num) != {0} and (int(''.join(map(str, num))) >= n):
				tmp = int(''.join(map(str, num)))
				print(tmp - n)
				break
		else:
			num.insert(0, 1)
			tmp = int(''.join(map(str, num)))
			print(tmp - n)


t = int(input())
for i in range(t):
	inp = input().split()
	a = int(inp[0])
	b = int(inp[1])
	if a % b == 0:
		print(0)
	elif a < b:
		print(b - a)
	else:
		d = a // b
		temp = b * (d + 1)
		ans = temp - a
		print(ans)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a > b and a % b != 0:
		d = a % b
		print(b - d)
	elif a < b:
		print(b - a)
	else:
		print('0')


t = int(input())
for i in range(t):
	(a, b) = list((int(x) for x in input().split()))
	c = 0
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


import sys
input = sys.stdin.readline
import heapq
import copy
import math
import decimal

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def insr2():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
ans = 0

def pr_list(a):
	print(*a, sep=' ')

def swap(a, b):
	temp = a
	a = b
	b = temp
	return [a, b]

def main():
	tests = inp()
	mod = 1000000007
	limit = 10 ** 18
	ans = 0
	stack = []
	hashm = {}
	arr = []
	heapq.heapify(arr)

	def summer(aa):
		ans = 0
		a = copy.deepcopy(aa)
		while a != 0:
			ans = ans + a % 10
			a = a // 10
		return ans
	for test in range(tests):
		[n, s] = inlt()
		arr = []
		while n != 0:
			arr.append(n % 10)
			n = n // 10
		if sum(arr) <= s:
			print(0)
			continue
		arr.reverse()
		i = 0
		sums = 0
		while sums < s:
			sums = sums + arr[i]
			if sums >= s:
				break
			i = i + 1
		f = 0
		r = 1
		while i < len(arr):
			f = f * 10 + arr[i]
			r = r * 10
			i = i + 1
		print(r - f)
main()


no = int(input())
res = []
for i in range(no):
	(a, b) = map(int, input().split())
	cc = a % b
	ss = b - cc
	if cc == 0:
		res.append(0)
	else:
		res.append(ss)
for i in res:
	print(i)


n = input()
arr = []
arr1 = []
arr2 = []
for i in range(int(n)):
	arr.append(list(map(int, input().split())))
for j in range(int(n)):
	arr1.append(int(arr[j][0]) % int(arr[j][1]))
	arr2.append(int(arr[j][1]) - int(arr1[j]))
	if arr2[j] == arr[j][1]:
		arr2[j] = 0
	print(arr2[j])


t = int(input())
for j in range(t):
	(n, s) = [int(k) for k in input().split()]
	digs = []
	while n > 0:
		digs.append(n % 10)
		n = n // 10
	digs.append(0)
	sm = sum(digs)
	i = 0
	if sm <= s:
		print('0')
		continue
	while sm + 1 > s:
		sm = sm - digs[i]
		i += 1
	ans = ''
	for k in digs[:i][::-1]:
		ans += str(k)
	if ans == '':
		ans = '1'
	print(10 ** i - int(ans))


n = int(input())
for t in range(0, n):
	inp = input().split()
	a = int(inp[0])
	b = int(inp[1])
	if a % b == 0:
		print(0)
	else:
		rem = a % b
		print(b - rem)


from sys import stdin
from math import ceil
n = int(input())
alist = []
blist = []
for i in range(n):
	vals = stdin.readline()
	(a, b) = [int(x) for x in vals.split()]
	alist.append(a)
	blist.append(b)
for (i, j) in zip(alist, blist):
	print(ceil(i / j) * j - i)


import math
t = int(input())
for i in range(t):
	(n, s) = map(int, input().split())
	buto = len(str(n))
	start = str(n)
	lst = []
	lstsu = [n]
	sm = 0
	for k in str(n):
		sm += int(k)
	lst.append(sm)
	for j in range(buto - 1, 0, -1):
		hello = int(start[j:])
		cha = 10 ** (buto - j) - hello
		su = str(n + cha)
		sm = 0
		for k in su:
			sm += int(k)
		lst.append(sm)
		lstsu.append(n + cha)
	lst.append(1)
	lstsu.append(10 ** buto)
	for k in range(len(lst)):
		if lst[k] <= s:
			print(lstsu[k] - n)
			break


t = int(input())
l = []
for i in range(t):
	l.append(list(map(int, input().split())))
for ll in l:
	print((ll[1] - ll[0] % ll[1]) % ll[1])


import math
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	copyb = b
	if b < a:
		b *= math.ceil(a / b)
	while b < a:
		b += copyb
	else:
		print(b - a)


from math import *
n = int(input())
for i in range(n):
	(x, y) = list(map(int, input().split()))
	ans = y * ceil(x / y)
	print(ans - x)


def main_function():
	t = int(input())
	for i in range(t):
		(a, b) = list(map(int, input().split(' ')))
		print(b - a % b if a % b != 0 else 0)
main_function()


t = int(input())
while t > 0:
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	c = a % b
	if c == 0:
		print(f'{c}')
	else:
		ans = b - c
		print(f'{ans}')
	t -= 1


import math
import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlst():
	return list(map(int, input().split()))

def instr():
	s = input()
	return list(s[:len(s) - 1])

def invar():
	return map(int, input().split())

def sumd(n):
	if n < 10:
		return n
	return n % 10 + sumd(n // 10)

def pbd(n, s):
	sn = sumd(n)
	res = 0
	i = 1
	while sn > s:
		res += i * (10 - n % 10)
		n += 10 - n % 10
		n //= 10
		sn = sumd(n)
		i *= 10
	return res
for _ in range(inp()):
	(n, s) = invar()
	print(pbd(n, s))


t = int(input())
for _ in range(t):
	count = 0
	(x, y) = input().split()
	(x, y) = (int(x), int(y))
	if x % y == 0:
		print(0)
		continue
	else:
		print(y - x % y)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	k = a % b
	l = b - k
	if k == 0:
		print('0')
	else:
		print(l)


t = int(input())
out = []
for i in range(0, t):
	(a, b) = map(int, input().split(' '))
	if a < b:
		out.append(b - a)
	elif a > b and a % b != 0:
		c = int(a / b) + 1
		c = c * b
		out.append(c - a)
	else:
		out.append(0)
for i in out:
	print(i)


import sys
n = int(sys.stdin.readline().rstrip())
l = []
answer = []
for i in range(0, n):
	k = list(map(int, input().split()))
	l.append(k)
for i in range(0, n):
	if l[i][0] % l[i][1] == 0:
		count = 0
		answer.append(count)
	else:
		temp = l[i][0] // l[i][1]
		temp = temp + 1
		count = temp * l[i][1] - l[i][0]
		answer.append(count)
for i in range(0, n):
	print(answer[i])


for u in range(int(input())):
	(x, y) = map(int, input().split())
	z = x % y
	q = y - z
	if z == 0:
		print(0)
	else:
		print(q)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	modu = a % b
	if modu == 0:
		print(0)
	else:
		div = int(a / b)
		ans = (div + 1) * b - a
		print(ans)


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	(a, b) = inputnums()
	if a % b == 0:
		print(0)
	else:
		print((a // b + 1) * b - a)


from bisect import bisect_left
for x in range(int(input())):
	(num, sUm) = map(int, input().split())
	s = list(str(num))
	leng = len(s)
	summa = [0]
	for i in s:
		summa.append(summa[-1] + int(i))
	val = 0
	if summa[-1] <= sUm:
		print(val)
		continue
	index = bisect_left(summa, sUm)
	s = ['0'] + s
	val = (int(''.join(s[:index + 1])) + 1) * pow(10, leng - index) if summa[index] < sUm else (int(''.join(s[:index])) + 1) * pow(10, leng - index + 1)
	print(val - num)


t = int(input())
for _ in range(t):
	lst = input().split()
	s = int(lst[1])
	n = int(lst[0])
	st = lst[0]
	sum1 = 0
	pos = -1
	sum2 = 0
	for i in st:
		sum2 += int(i)
	if sum2 <= s:
		print(0)
		continue
	for i in range(len(st)):
		sum1 += int(st[i])
		if sum1 >= s:
			pos = i
			break
	if pos == -1:
		print(0)
		continue
	str2 = ''
	str2 = st[0:pos]
	str2 = str2 + '0' * (len(st) - pos)
	if pos == 0:
		str2 = '1' + str2
	elif str2[pos - 1] == '9':
		str3 = '1'
		str3 = str3 + '0' * (len(st) - pos)
		str2 = int(str2) + int(str3)
	else:
		temp = str(int(st[pos - 1]) + 1)
		str2 = str2[0:pos - 1] + temp + str2[pos:]
	print(int(str2) - n)


def codeforces(a, b):
	if a % b == 0:
		return 0
	else:
		return b - a % b
a = int(input())
for _ in range(a):
	(a, b) = map(int, input().split())
	print(codeforces(a, b))


from datetime import datetime
instanteInicial = datetime.now()
instanteFinal = datetime.now()
testcases = input()
testcases = int(testcases)
for i in range(testcases):
	entrada = input().split(' ')
	a = int(entrada[0])
	b = int(entrada[1])
	if a % b == 0:
		print(0)
		continue
	moves = 0
	first = True
	status = (a // b + 1) * b
	print(status - a)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	(temp, d) = (n, 1)
	while sum(map(int, str(n))) > s:
		n += -(n // d % 10) % 10 * d
		d *= 10
	print(n - temp)


n = int(input())
for x in range(n):
	(a, b) = map(int, input().split(' '))
	r = a % b
	if r == 0:
		print(0)
	elif a < b:
		print(b - a)
	elif a > b:
		print(b - r)


def run_case():
	(n, s) = input().split()
	nn = list(n)
	s = int(s)
	if sum(map(int, nn)) <= s:
		print(0)
	else:
		temp = 0
		pre = 0
		for i in nn:
			temp += int(i)
			pre += 1
			if temp >= s:
				pre -= 1
				break
		if pre == 0:
			print(pow(10, len(nn)) - int(n))
		else:
			num = int(n[:pre])
			num += 1
			print(num * pow(10, len(nn) - pre) - int(n))
flag = 1
if flag:
	t = int(input())
	for i in range(t):
		run_case()
else:
	run_case()


def I():
	return list(map(int, input().split()))
for __ in range(int(input())):
	(a, b) = I()
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	ans = None
	if a % b != 0:
		ans = b - a % b
	else:
		ans = a % b
	print(ans)


import os
import heapq
import sys, threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10 ** 5)
from io import BytesIO, IOBase

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def power(x, p, m):
	res = 1
	while p:
		if p & 1:
			res = res * x % m
		x = x * x % m
		p >>= 1
	return res

def inar():
	return [int(k) for k in input().split()]

def lcm(num1, num2):
	return num1 * num2 // gcd(num1, num2)

def main():
	for _ in range(int(input())):
		(n, s) = inar()
		ar = []
		res = 0
		while True:
			val = str(n)
			md = 10 ** len(val)
			ans = 0
			ok = True
			dif = 0
			for i in val:
				ans += int(i)
				if ans > s:
					ok = False
					dif = md - n % md
					break
				md //= 10
			if not ok:
				res += dif
				n += dif
			if ok:
				print(res)
				break
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


results = []
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b:
		results.append(str(b - a % b))
	else:
		results.append('0')
print('\n'.join(results))


from math import *
sInt = lambda : int(input())
mInt = lambda : map(int, input().split())
lInt = lambda : list(map(int, input().split()))
t = sInt()
for _ in range(t):
	(a, b) = mInt()
	print(int(ceil(a / b)) * b - a)


cases = int(input())
while cases > 0:
	(a, b) = map(int, input().split())
	res = a % b
	if b - res == b:
		print(0)
	else:
		print(b - res)
	cases -= 1


t = int(input())
while t != 0:
	(n1, n2) = map(str, input().split())
	n2 = int(n2)
	s = 0
	ans = 0
	for i in range(len(n1)):
		if int(n1[i]) + s > n2:
			t1 = int('1' + '0' * (len(n1) - i)) - int(n1[i:])
			ans = t1
			break
		elif int(n1[i]) + s < n2:
			s += int(n1[i])
		else:
			temp1 = '0' * (len(n1) - i - 1)
			temp2 = n1[i + 1:]
			if temp1 == temp2:
				ans = 0
				break
			else:
				t1 = int('1' + '0' * (len(n1) - i)) - int(n1[i:])
				ans = t1
				break
	print(ans)
	t -= 1


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	str1 = str(n)
	s1 = 0
	s2 = 0
	for j in str1:
		s2 = s2 + int(j)
	if s2 <= s:
		print(0)
		continue
	for i in range(len(str1)):
		s1 += int(str1[i])
		if s1 < s:
			continue
		else:
			ans = str1[i:]
			print(10 ** len(ans) - int(ans))
			break


import math
t = int(input())
c = []
for i in range(0, t):
	(a, b) = map(int, input().split())
	count = math.ceil(a / b) * b - a
	c.append(count)
for i in c:
	print(i)


n = int(input())
while n:
	l = list(map(int, input().rstrip().split()))
	a = l[0]
	b = l[1]
	x = a % b
	if x != 0:
		y = b - x
		print(y)
	else:
		print(x)
	n -= 1


import sys
try:
	sys.stdin = open('input.in', 'r')
	sys.stdout = open('output.out', 'w')
except:
	pass
finally:
	for i in range(int(input())):
		(a, b) = map(int, input().split(' '))
		if a % b == 0:
			print(0)
		else:
			print(b - a % b)


from sys import stdin
N = int(stdin.readline())
for case in range(N):
	(num, maxsum) = map(int, stdin.readline().split())
	power = 0
	sol = 0
	ds = 0
	idx = 0
	for i in str(num):
		ds += int(i)
	for count in range(18):
		if ds <= maxsum:
			break
		digit = int(str(num)[-1 - power])
		if digit == 0:
			power += 1
			continue
		ds -= digit
		sol += 10 ** power * ((10 - digit) % 10)
		num += 10 ** power * ((10 - digit) % 10)
		power += 1
		while int(str(num)[-1 - power]) == 0:
			power += 1
			ds -= 9
		ds += 1
	print(sol)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	c = 0
	if a % b == 0:
		print(c)
	else:
		k = a // b
		diff = (k + 1) * b - a
		print(diff)


n = int(input())
ans = list()
for i in range(n):
	(a, b) = map(int, input().split())
	if a < b:
		moves = b - a
		ans.append(moves)
	elif a % b == 0:
		moves = 0
		ans.append(moves)
	else:
		x = a % b
		moves = b - x
		ans.append(moves)
for i in ans:
	print(i)


t = int(input())
for _ in range(t):
	(n1, n2) = map(int, input().split())
	if n1 % n2 == 0:
		print('0')
	else:
		n = n1 // n2
		n3 = n2 * (n + 1)
		print(n3 - n1)


t = int(input())
z = []
for i in range(t):
	z.append(input())
for i in range(t):
	(n, s) = (z[i].split()[0], z[i].split()[1])
	dsum = 0
	for i in range(len(n)):
		dsum += int(n[i])
	if dsum <= int(s):
		print(0)
	else:
		i = 0
		isum = 0
		while i < len(n):
			isum += int(n[i])
			if isum < int(s):
				i += 1
			else:
				break
		no = pow(10, len(n) - i) - int(n[i:len(n)])
		print(no)


op = []
for i in range(int(input())):
	aa = list(map(int, input().split()))
	a = aa[0]
	b = aa[1]
	if a % b == 0:
		op.append(0)
	else:
		op.append(b - a % b)
for i in op:
	print(i)


def get_x(n):
	x = 0
	while n > 0:
		x += n % 10
		n = n // 10
	return x

def find(k, s):
	pos = 1
	init = get_x(k)
	n = 0
	while init > s:
		n += pos * (10 - k % 10)
		pos *= 10
		k = k // 10 + 1
		init = get_x(k)
	return n
for i in range(int(input())):
	(k, s) = [int(j) for j in input().split()]
	print(find(k, s))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	moves = 0
	rem = a % b
	if rem != 0:
		moves += b - rem
	print(moves)


t = int(input())
outputList = []
i = 0
while i < t:
	x = str(input()).split(' ')
	a = int(x[0])
	b = int(x[1])
	steps = outputList.append((b - a % b) % b)
	i += 1
for item in range(len(outputList)):
	print(outputList[item])


def solver(n, x):
	m = list(map(lambda x: int(x), str(n)))
	res = 0
	pw = 1
	if sum(m) <= x:
		return res
	for i in range(18):
		dig = n // pw % 10
		add = (10 - dig) % 10 * pw
		n += add
		res += add
		m = list(map(lambda x: int(x), str(n)))
		if sum(m) <= x:
			break
		pw *= 10
	return res
for i in range(int(input())):
	(n, x) = map(int, input().split())
	print(solver(n, x))


def make_div(a, b):
	if a % b == 0:
		return 0
	return b * (a // b + 1) - a
for i in range(int(input())):
	(a, b) = map(int, input().split())
	print(make_div(a, b))


import sys
import math
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	print((b - a % b) % b)


import sys
import math
import bisect
import itertools

def main():
	for _ in range(int(input())):
		(a, b) = map(int, input().split())
		ans = (b - a % b) % b
		print(ans)
main()


t = int(input())
for _ in range(t):
	(n, s) = list(map(int, input().split()))
	num = [0] + list(map(int, str(n)))
	ans = 0
	while sum(num) > s:
		for i in range(len(num) - 1, -1, -1):
			if num[i] != 0:
				ans = ans + (10 - num[i]) * 10 ** (len(num) - 1 - i)
				num[i] = 0
				if num[i - 1] + 1 == 10:
					j = i - 1
					while num[j] + 1 == 10:
						num[j] = 0
						j = j - 1
					num[j] = num[j] + 1
				else:
					num[i - 1] = num[i - 1] + 1
				break
	print(ans)


n = int(input())
for i in range(n):
	case = [int(n) for n in input().split()]
	a = case[0]
	b = case[1]
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def LS():
	return [list(x) for x in sys.stdin.readline().split()]

def S():
	res = list(sys.stdin.readline())
	if res[-1] == '\n':
		return res[:-1]
	return res

def IR(n):
	return [I() for i in range(n)]

def LIR(n):
	return [LI() for i in range(n)]

def SR(n):
	return [S() for i in range(n)]

def LSR(n):
	return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
	t = I()
	for _ in range(t):
		(a, b) = LI()
		print(-a % b)
	return
solve()


import sys
input = sys.stdin.readline
t = int(input())

def d_sum(x):
	y = str(x)
	ans = 0
	for char in y:
		ans += int(char)
	return ans
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	c = a
	mul = 1
	if d_sum(c) > b:
		while True:
			c += mul
			if c % (mul * 10) == 0:
				mul *= 10
				if d_sum(c) <= b:
					break
	print(c - a)


testCases = int(input())
for i in range(testCases):
	strNumbers = input()
	numbers = list(map(int, strNumbers.split(' ')))
	knt = 0
	while 1:
		if numbers[0] % numbers[1] == 0:
			print(knt)
			break
		else:
			if numbers[0] < numbers[1]:
				knt = numbers[1] - numbers[0]
				print(knt)
			else:
				i = int(numbers[0] / numbers[1])
				while 1:
					if numbers[0] > i * numbers[1]:
						i += 1
						continue
					else:
						knt = i * numbers[1] - numbers[0]
						print(knt)
						break
			break


n = int(input())
k = []
for i in range(n):
	st = input()
	spl = st.split()
	fs = int(spl[0])
	ls = int(spl[1])
	if fs % ls == 0:
		k.append(0)
	else:
		d = fs // ls
		w = ls * (d + 1)
		k.append(w - fs)
for i in k:
	print(i)


for t in range(int(input())):
	(a, b) = map(int, input().strip().split())
	r = a % b
	if r == 0:
		print(0)
	else:
		print(b - r)


import sys
from itertools import permutations
from itertools import combinations
from itertools import combinations_with_replacement
for _ in range(int(input())):
	liStr = input().split()
	n = int(liStr[0])
	s = int(liStr[1])
	sInitial = 0
	nStrOK = str(n)
	for i in nStrOK:
		sInitial += int(i)
	if sInitial <= s:
		print('0')
		continue
	nStr = str(n)
	nLen = len(nStr)
	ans = pow(10, nLen) - n
	ctr = 0
	while ctr < nLen:
		p1 = nStr[0:ctr + 1]
		intP1 = int(p1) + 1
		p2 = nStr[ctr + 1:]
		comp = intP1 * pow(10, len(p2))
		strComp = str(comp)
		sCur = 0
		for i in strComp:
			sCur += int(i)
		if sCur <= s:
			ans = comp - n
		ctr += 1
	print(ans)


from math import *
import sys, random

def nextInt():
	return int(input())

def nextStrs():
	return input().split()

def nextInts():
	return list(map(int, nextStrs()))

def main():
	t = nextInt()
	for _ in range(t):
		(a, b) = nextInts()
		if a % b == 0:
			a = b
		print(b - a if a <= b else (a // b + 1) * b - a)
exit(main())


q = int(input())
for i in range(q):
	(a, b) = map(int, input().split())
	s = 0
	if a % b != 0:
		print(b - a % b)
	else:
		print('0')


ncases = int(input())
for i in range(ncases):
	pair = input().split()
	if int(pair[0]) % int(pair[1]) == 0:
		print('0')
	else:
		print(str(int(int(pair[1]) - int(pair[0]) % int(pair[1]))))


n = int(input())
for k in range(n):
	entrada = list(map(int, input().split(' ')))
	a = entrada[0]
	b = entrada[1]
	if a % b == 0:
		print(0)
	elif a < b:
		print(b - a)
	else:
		d = a // b
		d += 1
		print(d * b - a)


import sys
import heapq
si = sys.stdin.readline

def digitSum(n):
	n = str(n)
	ret = 0
	for e in n:
		ret += int(e)
	return ret

def main():
	t = int(si())
	while t:
		t -= 1
		(n, s) = [int(e) for e in si().split()]
		if digitSum(n) < s:
			print(0)
		else:
			(i, temp) = (10, n)
			while digitSum(n) > s:
				n = n // i * i + i
				i *= 10
			print(n - temp)
main()


def main():
	d = int(input())
	for i in range(d):
		(a, b) = [int(v) for v in input().split()]
		print((a // b + (0 if a % b == 0 else 1)) * b - a)
main()


t = int(input())
for test in range(t):
	(a, b) = [int(i) for i in input().split()]
	print(-a % b)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	ans = ''
	strn = str(n)
	sumn = 0
	for i in strn:
		sumn += int(i)
	if sumn <= s:
		print(0)
	else:
		k = 0
		tot = 0
		for i in strn:
			k += int(i)
			if k + 1 > s:
				break
			tot += 1
			ans += i
		if ans:
			k = int(ans) + 1
		if not tot:
			print(10 ** len(strn) - n)
		else:
			print(k * 10 ** (len(strn) - tot) - n)


import math
import sys
input = sys.stdin.readline

def sum_of_digit(str_n):
	sum = 0
	for i in str_n[:]:
		sum += int(i)
	return sum
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	n = str(n)
	if sum_of_digit(n) <= s:
		print(0)
		continue
	nul = 0
	i = len(n)
	while sum_of_digit(n[:i]) + 1 > s:
		nul += 1
		i -= 1
	rr = 0
	for ch in n[:i]:
		rr = rr * 10 + int(ch)
	rr += 1
	rr *= 10 ** nul
	print(rr - int(n))


def divisibility(a, b):
	if a < b:
		return b - a
	elif a % b == 0:
		return 0
	else:
		return b - a % b
t = int(input())
for t_itr in range(t):
	arr = list(map(int, input().rstrip().split()))
	a = int(arr[0])
	b = int(arr[1])
	result = divisibility(a, b)
	print(result)


t = input()
for i in range(int(t)):
	s = input()
	l = s.split(' ')
	l = list(map(int, l))
	if l[0] % l[1] == 0:
		print(0)
	else:
		k = 0
		print((int(l[0] / l[1]) + 1) * l[1] - l[0])


t = int(input())
out = list()
for item in range(t):
	input_ab = input().split()
	ab = [int(item) for item in input_ab]
	if ab[0] < ab[1]:
		out.append(ab[1] - ab[0])
	elif ab[0] % ab[1] == 0:
		out.append(0)
	else:
		out.append((int(ab[0] / ab[1]) + 1) * ab[1] - ab[0])
for item in range(t):
	print(out[item])


t = int(input())
p = []
for i in range(t):
	h = list(map(int, input().split()))
	p.append(h)
for i in range(t):
	if p[i][0] % p[i][1] != 0:
		print(p[i][1] - p[i][0] % p[i][1])
	else:
		print(p[i][0] % p[i][1])


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	a = [int(i) for i in str(n)]
	cost = 0
	for i in range(-1, -len(a) - 1, -1):
		if sum(a) <= s:
			break
		cost += (10 - a[i]) * 10 ** (abs(i) - 1)
		n += (10 - a[i]) * 10 ** (abs(i) - 1)
		a = [int(i) for i in str(n)]
	print(cost)


t = int(input())
answer = []
for t in range(t):
	(a, b) = list(map(int, input().split(' ')))
	answer.append(str((b - a % b) * (a % b > 0)))
print('\n'.join(answer))


import sys
import math
fileoperation = 0
if fileoperation:
	orig_stdout = sys.stdout
	orig_stdin = sys.stdin
	inputfile = open('W:/Competitive Programming/input.txt', 'r')
	outputfile = open('W:/Competitive Programming/output.txt', 'w')
	sys.stdin = inputfile
	sys.stdout = outputfile
mod = 1000000007

def nospace(l):
	ans = ''.join((str(i) for i in l))
	return ans
t = int(input())
for tt in range(t):
	(a, b) = map(int, sys.stdin.readline().split(' '))
	d = a // b
	if b * d == a:
		print(0)
	else:
		print((d + 1) * b - a)
if fileoperation:
	sys.stdout = orig_stdout
	sys.stdin = orig_stdin
	inputfile.close()
	outputfile.close()


import math
n = int(input())
for i in range(n):
	(a, b) = list(map(int, input().split(' ')))
	print(math.ceil(a / b) * b - a)


T = int(input())
for i in range(T):
	l = list(map(int, input().split()))
	a = l[0]
	b = l[1]
	count = a % b
	if count == 0:
		print('0')
	else:
		check = (a // b + 1) * b - a
		print(check)


x = int(input())
for i in range(x):
	maxi = [int(x) for x in input().split()]
	if maxi[0] <= maxi[1]:
		print(maxi[1] - maxi[0])
	elif maxi[0] % maxi[1] == 0:
		print(0)
	else:
		print(maxi[1] - maxi[0] % maxi[1])


t = int(input())
for _ in range(t):
	(n, s) = list(map(int, input().split()))
	n = str(n)
	arr = [int(n[i]) for i in range(len(n) - 1, -1, -1)]
	count = 0
	checks = sum(arr)
	arr.append(0)
	arr.append(0)
	arr.append(0)
	arr.append(0)
	arr.append(0)
	arr.append(0)
	arr.append(0)
	arr.append(0)
	arr.append(0)
	if checks <= s:
		print(0)
	else:
		for i in range(0, len(n)):
			if checks <= s:
				break
			else:
				if arr[i] == 10:
					arr[i + 1] = arr[i + 1] + 1
					checks = checks - arr[i] + 1
					arr[i] = 0
				if arr[i] != 0:
					x = 10 - arr[i]
					arr[i] = 10
					checks = checks + x
					count += x * 10 ** i
				if arr[i] == 10:
					checks = checks - arr[i] + 1
					arr[i] = 0
					arr[i + 1] = arr[i + 1] + 1
		print(count)


a = int(input())
for i in range(a):
	(z, e) = map(int, input().split())
	if z % e == 0:
		print(0, '\n')
	elif z > e:
		l = z % e
		l = e - l
		print(l)
	else:
		print(abs(e - z))


from math import ceil
n = int(input())
ans = []
for _ in range(n):
	(a, b) = map(int, input().split())
	closest = ceil(a / b) * b
	ans.append(closest - a)
print(*ans, sep='\n')


n = int(input())
for i in range(n):
	z = input().split()
	a = int(z[0])
	b = int(z[1])
	d = a // b
	if a % b == 0:
		print(0)
	else:
		print((d + 1) * b - a)


n = int(input())
for i in range(n):
	x = list(map(int, input().split()))
	if x[0] % x[1] == 0:
		print(0)
		continue
	divide = x[0] // x[1]
	result = (divide + 1) * x[1] - x[0]
	print(result)


def sum_of_digits(n):
	x = 0
	for i in str(n):
		x += int(i)
	return x
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	moves = 0
	for i in range(1, len(str(n)) + 2):
		if sum_of_digits(n) <= s:
			print(moves)
			break
		a = n % 10 ** i
		moves += 10 ** i - a
		n += 10 ** i - a


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
sys.setrecursionlimit(100000000)
ii = lambda : int(input())
si = lambda : input()
jn = lambda x, l: x.join(map(str, l))
sl = lambda : list(map(str, input().strip()))
mi = lambda : map(int, input().split())
mif = lambda : map(float, input().split())
lii = lambda : list(map(int, input().split()))
ceil = lambda x: int(x) if x == int(x) else int(x) + 1
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
mod = 1000000007
n = ii()
for _ in range(n):
	(a, b) = mi()
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
test = int(input())
for i in range(test):
	(n, k) = map(int, input().split())
	if n % k != 0:
		print(k - n % k)
	else:
		print('0')


t = int(input())
for _ in range(t):
	(n, s) = map(str, input().split())
	s = int(s)
	flag = 0
	p = len(n)
	sum = 0
	for i in range(p):
		sum = sum + int(n[i])
		if sum > s:
			flag = 1
			break
		else:
			pass
	if flag == 0:
		print(0)
	elif flag == 1 and int(n[0]) >= s:
		ans = int(str(1) + str(0) * p)
		print(ans - int(n))
	else:
		sum = sum + 1
		while sum > s and i > 0:
			sum = sum - int(n[i])
			i = i - 1
		while n[i] == '9':
			i = i - 1
			if i == -1:
				break
		if i == -1:
			ans = int(str(1) + str(0) * p)
			print(ans - int(n))
		else:
			ans = int(n[:i] + str(int(n[i]) + 1) + str(0) * (p - i - 1))
			print(ans - int(n))


t = int(input())
for _ in range(t):
	(a, b) = input().strip().split()
	(a, b) = (int(a), int(b))
	remain = a % b
	if remain == 0:
		print(remain)
	else:
		print(b - remain)


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	(n, s) = map(int, input().split())
	LIST = [(n, 0)]
	ANS = 0
	for i in range(1, 20):
		x = (10 ** i - n % 10 ** i) % 10 ** i
		n += x
		ANS += x
		LIST.append((n, ANS))
	ANSMIN = 1 << 60
	for (x, ans) in LIST:
		if sum(map(int, list(str(x)))) <= s:
			ANSMIN = min(ANSMIN, ans)
	print(ANSMIN)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	min_inc = a
	if a % b != 0:
		min_inc -= a % b
		min_inc += b
	print(min_inc - a)


import sys
pin = sys.stdin.readline
pout = sys.stdout.write
ran = range
m = int(pin())
mape = map
for i in ran(m):
	(a, b) = mape(int, pin().split())
	if a % b == 0:
		pout('0\n')
	else:
		print(b - a % b)


def cal(x):
	ans = 0
	while x:
		ans += x % 10
		x //= 10
	return ans
T = int(input())
for case in range(T):
	(n, s) = map(int, input().split())
	p = 10
	if cal(n) <= s:
		print(0)
		continue
	while True:
		x = n % p
		y = p - x
		k = n + y
		if cal(k) <= s:
			print(y)
			break
		p = p * 10


def Divisible(a, b):
	return 0 if a % b == 0 else (a // b + 1) * b - a
n = int(input())
for _ in range(n):
	ab = list(map(int, input().split(' ')))
	a = ab[0]
	b = ab[1]
	print(Divisible(a, b))


def solve(x, n):
	sm = 0
	for i in range(n + 1):
		sm += int(x[i])
	return sm
t = int(input())
for _ in range(t):
	(n, s) = map(int, input().split())
	st = str(n)
	i = 0
	sm = 0
	while i < len(st) and sm + int(st[i]) < s:
		sm += int(st[i])
		i += 1
	if i == len(st):
		print(0)
		continue
	new = ''
	x = 10
	for j in range(len(st) - 1, i, -1):
		if x - int(st[j]) == 10:
			new = '0' + new
		else:
			new = str(x - int(st[j])) + new
			x = 9
	j = 0
	while j <= 9:
		sd = solve(str(n + int(str(j) + new)), i)
		if sd <= s:
			print(int(str(j) + new))
			break
		j += 1


from bisect import *
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	strin = list(str(n))
	l = len(strin)
	pref = [0]
	ans = 0
	for i in range(l):
		pref.append(pref[-1] + int(strin[i]))
	if pref[-1] <= s:
		print(0)
	else:
		idx = bisect_left(pref, s)
		strin = ['0'] + strin
		if pref[idx] < s:
			ans = (int(''.join(strin[:idx + 1])) + 1) * 10 ** (l - idx)
		else:
			ans = (int(''.join(strin[:idx])) + 1) * 10 ** (l - idx + 1)
		print(ans - n)


def f():
	t = int(input())
	arr = []
	for _ in range(t):
		arr.append(list(map(int, input().split())))

	def sumdigits(n, digits):
		(res, i, n) = (0, 0, str(n))
		while i < len(n) and i <= digits:
			res += int(n[i])
			i += 1
		return res

	def findnext(n, s):
		i = 0
		while sumdigits(n, i) + 1 <= s:
			i += 1
		i -= 1
		if i == -1:
			return 10 ** len(str(n))
		n = list(map(int, str(n)))
		for ctr in range(i + 1, len(n)):
			n[ctr] = 0
		n[i] += 1
		while i > 0 and n[i] == 10:
			n[i] = 0
			i -= 1
			n[i] += 1
		if i == 0 and n[0] == 10:
			return 10 ** len(n)
		return int(''.join(list(map(str, n))))
	for (n, s) in arr:
		if sumdigits(n, len(str(n)) - 1) <= s:
			print(0)
			continue
		minv = findnext(n, s)
		print(minv - n)
f()


q = int(input())

def solve():
	for i in range(q):
		arr = [int(i) for i in input().split()]
		moves = 0
		if arr[0] % arr[1] == 0:
			print(str(0))
		else:
			print(str(arr[1] - arr[0] % arr[1]))
solve()


testNumb = int(input())
for _ in range(testNumb):
	takeInputs = [int(x) for x in input().split()]
	a = takeInputs[0]
	b = takeInputs[1]
	if a % b == 0:
		print(0)
	elif b > a:
		print(b - a)
	else:
		print(b - a % b)


n = int(input())
c = []
for i in range(n):
	(a, b) = [int(m) for m in input().split()]
	if a % b == 0:
		c.append(0)
	else:
		c.append(b - a % b)
for item in c:
	print(item)


def stepdiv(a, b):
	return (b - a % b) % b
for _ in range(int(input().strip())):
	(a, b) = list(map(int, input().strip().split(' ')))
	print(stepdiv(a, b))


s = int(input())
for i in range(0, s):
	(a, b) = map(int, input().split())
	count = 0
	flag = 0
	d = a % b
	if d == 0:
		print(count)
	else:
		c = a // b
		k = (c + 1) * b
		count = k - a
		print(count)


num = int(input())
for i in range(num):
	(num1, num2) = input().split()
	a = int(num1)
	b = int(num2)
	print((b - a % b) % b)


def count(n_, s_):
	divisor = 10
	result = 0
	while True:
		if sum([int(x) for x in n_]) <= int(s_):
			break
		delta = divisor - int(n_) % divisor
		n_ = str(int(n_) + delta)
		result += delta
		divisor *= 10
	return result
results = []
for _ in range(int(input())):
	(n, s) = input().split()
	results.append(count(n, s))
for result in results:
	print(result)


rounds = int(input())
for i in range(rounds):
	nums = input().split()
	a = int(nums[0])
	b = int(nums[1])
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	nn = n
	n = [0] + list(map(int, str(n)))
	if sum(n) <= s:
		print(0)
		continue
	for i in range(len(n) - 1, 0, -1):
		if sum(n[:i]) < s:
			for j in range(i, len(n) - 1):
				n[j] = 0
			n[i - 1] = (n[i - 1] + 1) % 10
			if n[i - 1] == 0:
				n[i - 2] += 1
			ans = 0
			for i in range(len(n) - 1):
				ans += n[i] * pow(10, len(n) - 1 - i)
			print(ans - nn)
			break


n = int(input())
cases = [0 for j in range(n)]
for i in range(n):
	line = [int(k) for k in input().split()]
	if line[0] % line[1] == 0:
		cases[i] = 0
	else:
		cases[i] = line[1] - line[0] % line[1]
for j in cases:
	print(str(j))


import math
tc = int(input())
for t in range(tc):
	x = input().split()
	a = int(x[0])
	b = int(x[1])
	c = math.ceil(a / b)
	c = c * b
	c = c - a
	print(c)


for i in range(int(input())):
	(a, b) = list(map(int, input().split()))
	(d, e, f) = (0, 0, 0)
	c = a % b
	if c == 0:
		print(0)
	elif a > b:
		d = a // b
		d += 1
		e = b * d
		f = e - a
		print(f)
	else:
		print(b - a)


for _ in range(int(input())):
	(n, s) = list(map(int, input().split()))
	lenN = len(str(n))
	sumDigit = 0
	nCpy = n
	for j in range(lenN):
		sumDigit += nCpy % 10
		nCpy //= 10
	if sumDigit <= s:
		print(0)
	else:
		for j in range(lenN):
			newN = (n // 10 ** (j + 1) + 1) * 10 ** (j + 1)
			nCpy = newN
			sumDigit = 0
			for j in range(lenN):
				sumDigit += nCpy % 10
				nCpy //= 10
			if sumDigit <= s:
				print(newN - n)
				break


import sys

def main():
	t = Iint()
	for _ in range(t):
		(actual_value, max_sum) = Imap()
		s = str(actual_value)
		s = [0] + [int(si) for si in s]
		n = len(s)
		if sum(s) <= max_sum:
			print(0)
			continue
		digit_sum = 0
		actual_sum = 0
		t = 10 ** (n - 1)
		debug(s, c=5)
		for i in range(n):
			digit_sum += s[i]
			if digit_sum >= max_sum:
				actual_sum += t * 10
				break
			actual_sum += s[i] * t
			t //= 10
		debug(actual_sum, actual_value)
		print(actual_sum - actual_value)
en = enumerate
FIO = 10
BUFSIZE = 8 * 1024

def Istr():
	return input()

def Iint():
	return int(input())

def Ilist():
	return list(map(int, input().split()))

def Imap():
	return map(int, input().split())

def Plist(li, s=' '):
	print(s.join(map(str, li)))

def debug(*args, c=6):
	pass
if not FIO:
	if __name__ == '__main__':
		main()
		exit()
else:
	from io import BytesIO, IOBase
	import os

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	m = n
	s1 = sum([int(i) for i in str(n)])
	i = 0
	while s1 > s:
		x = n // 10 ** i % 10
		n += 10 ** i * (10 - x)
		i += 1
		s1 = sum([int(i) for i in str(n // 10 ** i)])
	print(n - m)


t = 1
t = int(input())
for _ in range(t):
	(n, s) = map(int, input().split())
	su = 0
	arr = []
	for i in str(n):
		su += int(i)
		arr.append(int(i))
	if su <= s:
		print(0)
		continue
	else:
		arr = arr[::-1]
		ptr = 0
		while su > s:
			tmp = arr[ptr]
			su -= tmp
			su += 1
			arr[ptr] = 0
			if tmp == 0:
				ptr += 1
				continue
			if ptr > 20:
				break
			if ptr < len(arr) - 1:
				arr[ptr + 1] += 1
				for i in range(len(arr) - 1):
					if arr[i] >= 10:
						arr[i + 1] += arr[i] - 9
						arr[i] = 0
				if arr[-1] >= 10:
					arr.append(arr[-1] - 9)
					arr[-2] = 0
			else:
				arr.append(1)
			su = 0
			for i in arr:
				su += i
			ptr += 1
		ans = ''
		arr = arr[::-1]
		for i in arr:
			ans += str(i)
		print(int(ans) - n)


from math import ceil
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	print(m * ceil(n / m) - n)


t = int(input())

def sumfunc(n):
	res = 0
	while n > 0:
		res += n % 10
		n = n // 10
	return res
for k in range(t):
	(n, s) = map(int, input().split())
	if sumfunc(n) <= s:
		ans = 0
	else:
		n1 = n
		ans = 0
		p = 1
		for i in range(18):
			lastdigit = n // p % 10
			d = (10 - lastdigit) % 10 * p
			n += d
			ans += d
			if sumfunc(n) <= s:
				break
			p *= 10
	print(ans)


def get_output(query):
	divisor = query[1]
	dividend = query[0]
	remainder = dividend % divisor
	add = dividend + remainder
	sub = dividend - remainder
	if add % divisor == 0:
		return add - dividend
	elif sub % divisor == 0:
		return dividend + (divisor - remainder) - dividend
test_cases = int(input())
for i in range(test_cases):
	query = [int(i) for i in input().split()]
	print(get_output(query))


import sys
input = lambda : sys.stdin.readline().strip()
ipnut = input

def main(t=1):
	for i in range(t):
		(n, m) = map(int, input().split())
		print(-n + m * ((n + m - 1) // m))
main(int(input()))


try:
	t = int(input())
	while t:
		(m, n) = map(int, input().split())
		if m % n != 0:
			print(n - m % n)
		else:
			print(0)
		t = t - 1
except:
	pass


t = int(input())
while t > 0:
	l = [int(i) for i in input().split()]
	if l[0] % l[1] == 0:
		print('0')
	else:
		q = l[0] // l[1]
		print((q + 1) * l[1] - l[0])
	t -= 1


n = int(input())
s = 0
for i in range(n):
	(a, b) = map(int, input().split())
	print(abs(a // -b) * b - a)


for i in range(int(input())):
	(a, b) = map(int, input().split(' '))
	if a >= b:
		print(a % b == 0 and '0' or abs(a - (a // b + 1) * b))
	else:
		print(b - a)


def sumd(n):
	return sum([int(x) for x in str(n)])
t = int(input())
for tc in range(t):
	(n, s) = [int(x) for x in input().split()]
	ans = 0
	while sumd(n) > s:
		if n <= 9:
			ans += 10 - n
			n = 10
		else:
			st = str(n)[::-1]
			l = 0
			for i in range(len(st)):
				if st[i] != '0':
					l = i + 1
					break
			x = n % 10 ** l
			ans += 10 ** l - x
			n = n + (10 ** l - x)
	print(ans)


t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().strip().split(' ')))
	if a % b == 0:
		print(0)
		continue
	q = a // b + 1
	print(b * q - a)


t = int(input())
while t != 0:
	(a, b) = [int(x) for x in input().split()]
	if a < b:
		print(b - a)
	elif a % b == 0:
		print(0)
	else:
		print((a // b + 1) * b - a)
	t -= 1


import math
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	print((a // b + (1 if a % b != 0 else 0)) * b - a)


test = int(input())
for i in range(test):
	numbers = list(map(int, input().split()))
	a = numbers[0]
	b = numbers[1]
	if a % b == 0:
		print(0)
	elif a < b:
		print(b - a)
	else:
		print((a // b + 1) * b - a)


n = int(input())
s = []
for i in range(n):
	(a, b) = input().split()
	a = int(a, 10)
	b = int(b, 10)
	if a % b == 0:
		k = 0
		s.append(k)
	else:
		d = int(a / b)
		k = b * (d + 1) - a
		s.append(k)
for i in range(len(s)):
	print(s[i])


from sys import stdin, gettrace
if not gettrace():

	def input():
		return next(stdin)[:-1]

def main():

	def solve():
		(a, b) = map(int, input().split())
		rem = a % b
		if rem == 0:
			print(0)
		else:
			print(b - rem)
	q = int(input())
	for _ in range(q):
		solve()
main()


t = int(input())
for i in range(t):
	(n, s) = map(int, input().split())
	arr = []
	num = []
	sum = 0
	for j in str(n):
		arr.append(int(j))
		num.append(int(j))
		sum += int(j)
	arr.reverse()
	num.reverse()
	if sum <= s:
		print(0)
	else:
		f = 1
		j = 0
		while j < len(arr):
			sum -= num[j]
			if num[j] != 0:
				num[j] = 0
				j += 1
				while j < len(arr):
					if num[j] != 9:
						num[j] += 1
						sum += 1
						break
					else:
						sum -= num[j]
						num[j] = 0
						j += 1
			else:
				j += 1
			if j == len(arr):
				break
			if sum <= s:
				break
		if j == len(arr):
			num = [0] * len(num) + [1]
		num.reverse()
		l = ''
		for k in num:
			l += str(k)
		print(int(l) - n)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	c = 0
	if n % m == 0:
		print(c)
	elif n < m:
		m = m - n
		print(m)
	else:
		k = n // m
		k = k + 1
		k = k * m
		k = k - n
		print(k)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if not a % b:
		print(0)
		continue
	if a < b:
		print(b - a)
		continue
	c = a // b
	print((c + 1) * b - a)


from math import *
from bisect import *
from collections import Counter, defaultdict, deque
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))

def su(n):
	ans = 0
	while n > 0:
		ans += n % 10
		n //= 10
	return ans
for _ in range(I()):
	(n, s) = M()
	c = su(n)
	d = 0
	a = 1
	while c > s:
		e = n // a % 10
		n += a * ((10 - e) % 10)
		d += a * ((10 - e) % 10)
		c = su(n)
		a *= 10
	print(d)


def find_number_of_moves(a, b):
	if a >= b:
		rem = a % b
		a = a - rem
		c = a - rem
		return c % b
	else:
		return b - a
t = int(input())
for i in range(t):
	(a, b) = input().split()
	print(find_number_of_moves(int(a), int(b)))


n = int(input())
for i in range(0, n):
	st = input().split()
	s = int(st[0])
	t = int(st[1])
	x = s % t
	if x == 0:
		print(0)
	else:
		print(t - x)


def isDivisible(a, b):
	if a < b:
		return b - a
	mod = a % b
	if mod == 0:
		return 0
	elif mod != 0:
		return (a // b + 1) * b - a
	else:
		return 'out'
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split(' '))
	print(isDivisible(a, b))


t = int(input())
l = []
for i in range(t):
	l.append([int(x) for x in input().split()])

def xx(a, b):
	if a == b:
		return 0
	elif a > b:
		d = a % b
		if d:
			return b - d
		return d
	return b - a
for i in l:
	print(xx(i[0], i[1]))


import math
t = int(input())
for i in range(t):
	ab = [int(j) for j in input().split()]
	(a, b) = (ab[0], ab[1])
	print(abs(math.ceil(a / b) * b - a))


t = int(input())
for _ in range(t):
	(n, s) = input().split()
	s = int(s)
	n = int(n)
	st = str(n)
	su = 0
	ans = n
	digsum = sum([ord(i) - ord('0') for i in st])
	if digsum <= s:
		print(0)
		continue
	for i in range(len(st)):
		if su + ord(st[i]) - ord('0') < s:
			su += ord(st[i]) - ord('0')
		else:
			left = len(st[i:])
			if len(st[:i]) == 0:
				q = 0
			else:
				q = int(st[:i])
			ans = (q + 1) * 10 ** left
			break
	print(ans - n)


t = int(input())
for z in range(t):
	(a, b) = map(int, input().split())
	print((b - a % b) % b)


t = int(input())
while t:
	l = list(map(int, input().split()))
	(r, q) = (0, 0)
	r = l[0] % l[1]
	if r == 0:
		q = 0
	else:
		q = l[1] - r
	print(q)
	t = t - 1


def solution(n, s):
	x = sum((int(d) for d in str(n)))
	if x <= s:
		return 0
	elif int(str(n)[0]) < s:
		return solution(int(str(n)[1:]), s - int(str(n)[0]))
	else:
		return 10 ** len(str(n)) - n + solution(10 ** len(str(n)), s)
t = int(input())
for _ in range(t):
	(n, s) = map(int, input().split(' '))
	print(solution(n, s))


def cal(x, y):
	print()
	rem = x % y
	if rem == 0:
		return 0
	return y - rem
for i in range(int(input())):
	(X, Y) = map(int, input().split())
	print(cal(X, Y))


t = int(input())
for tt in range(t):
	(xx, y) = [i for i in input().split(' ')]
	x = xx
	while True:
		yy = int(y)
		for i in range(len(x)):
			yy -= int(x[i])
			if yy < 0:
				break
		if i == len(x) - 1 and yy >= 0:
			print(int(x) - int(xx))
			break
		else:
			kk = 10 * 10 ** (len(x) - i - 1)
			s = int(x)
			s = s - s % kk + kk
			x = str(s)


t = int(input())
a1 = [0] * t
b1 = [0] * t
for i in range(t):
	(a, b) = input().split()
	(a1[i], b1[i]) = (int(a), int(b))
for i in range(t):
	mod = a1[i] % b1[i]
	if mod:
		print(b1[i] - a1[i] % b1[i])
	else:
		print(0)


num = int(input())

def increment(n1, n2):
	n1 = int(n1)
	n2 = int(n2)
	if n1 % n2 == 0:
		return 0
	else:
		t = n1 % n2
		return n2 - t
for i in range(num):
	temp = input()
	temp = temp.split(' ')
	print(increment(temp[0], temp[1]))


for i in range(int(input())):
	(n, s) = map(int, input().split())
	l = list(map(int, list(str(n))))
	if sum(l) <= s:
		print(0)
		continue
	i = 0
	q = l[0]
	while q < s:
		i += 1
		q += l[i]
	req = len(l[i:])
	x = ''.join(map(str, l[i:]))
	req_num = int(x)
	mov = 10 ** req - req_num
	print(mov)


def convert_array_to_int(arr):
	for i in range(0, len(arr), 1):
		arr[i] = int(arr[i])
	return arr
testCases = int(input())
while testCases:
	X = input().split()
	X = convert_array_to_int(X)
	a = X[0]
	b = X[1]
	remainder = a % b
	if remainder:
		print(b - remainder)
	else:
		print(remainder)
	testCases -= 1


for t in range(int(input())):
	(n, k) = map(int, input().split())
	n1 = str(n)
	l = len(n1)
	count = 0
	l1 = []
	for i in range(l):
		l1.append(int(n1[i]))
	l1 = [0] + l1
	l += 1
	for i in range(l):
		if sum(l1) <= k:
			break
		if l1[l - i - 1] == 0:
			continue
		r = 10 - l1[l - i - 1]
		l1[l - i - 1] = 0
		l1[l - i - 2] += 1
		count += r * pow(10, i)
	print(count)


import math
cases = int(input())
for i in range(cases):
	data = list(map(int, input().split(' ')))
	if data[0] % data[1] != 0:
		print(data[1] * math.ceil(data[0] / data[1]) - data[0])
	else:
		print(0)


from sys import stdin

def inp():
	return stdin.buffer.readline().rstrip().decode('utf8')

def itg():
	return int(stdin.buffer.readline())

def mpint():
	return map(int, stdin.buffer.readline().split())

def solve():
	(n, s) = mpint()
	arr = list(map(int, str(n)))
	count = sum(arr)
	ans = bit = 0
	while count > s:
		ans += (10 - arr[-1]) * 10 ** bit
		count += -arr[-1] + 1
		del arr[-1]
		if arr:
			arr[-1] += 1
		else:
			arr = [1]
		bit += 1
	return ans
for __ in range(itg()):
	print(solve())


t = int(input())
while t > 0:
	(n, target_sum) = map(int, input().split())
	digits = [int(char) for char in str(n)]
	digits.reverse()
	cur_sum = sum(digits)
	moves = 0
	for index in range(0, len(digits)):
		if cur_sum <= target_sum:
			break
		digit = digits[index]
		cur_sum -= digit
		cur_sum += 1
		if index + 1 < len(digits):
			digits[index + 1] = digits[index + 1] + 1
		moves += (10 - digit) * int(10 ** index)
	print(moves)
	t -= 1


def sum(a):
	ans = 0
	while a > 0:
		ans += a % 10
		a //= 10
	return ans
t_case = int(input())
for _ in range(t_case):
	(a, b) = map(int, input().split())
	if sum(a) <= b:
		print(0)
	else:
		pw = 1
		ans = 0
		for i in range(19):
			t = pw * (10 - a // pw % 10)
			ans += t
			a += t
			if sum(a) <= b:
				break
			pw *= 10
		print(ans)


for j in range(int(input())):
	(n, s) = tuple(map(int, input().split()))
	n1 = str(n)
	l = list(map(int, n1))
	if s >= sum(l):
		print(0)
	else:
		t = sum(l)
		diff = t - s
		z = 0
		for i in reversed(range(len(l))):
			if t <= s:
				break
			elif l[i] != 0:
				t -= l[i]
				z += (10 - l[i]) * pow(10, len(l) - 1 - i)
				if i > 0:
					l[i - 1] += 1
					t += 1
				else:
					t += 1
		print(z)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	count = 0
	if a / b > 1 and a % b != 0:
		temp = a
		a = a + b - a % b
		count = a - temp
	if a < b:
		count = b - a
		a = b
	while True:
		if a % b == 0:
			break
		a += 1
		count += 1
	print(count)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		M = a // b + 1
		Num = b * M
		print(Num - a)


T = int(input())
for i in range(T):
	(n, q) = map(int, input().split())
	if n % q != 0:
		h = n % q
		print(q - h)
	else:
		print(0)


n = int(input())
for i in range(n):
	(x, y) = map(int, input().split())
	print((y - x % y) % y)


t = int(input())
for x in range(t):
	ab = input().rstrip().split()
	a = int(ab[0])
	b = int(ab[1])
	if a % b == 0:
		print('0')
	else:
		r = a % b
		c = b - r
		print(c)


t = int(input())
for h in range(t):
	s = input().split()
	a = int(s[0])
	b = int(s[1])
	if a % b == 0:
		print(0)
	elif a >= b:
		k = b * (a // b + 1)
		print(k - a)
	else:
		print(b - a)


for _ in range(int(input())):
	(i, j) = map(int, input().split())
	if i >= j:
		if i % j == 0:
			print(0)
		else:
			print(j - i % j)
	else:
		print(abs(i - j))


for _ in range(int(input())):
	(n, q) = map(int, input().split(' '))
	if n % q == 0:
		print(0)
	else:
		print(q * (n // q + 1) - n)


def kek():
	string = input()
	(n, s) = list(map(int, string.split()))
	k = 0
	summa = sum(map(int, list(str(n))))
	delitel = 10
	while summa > s:
		shagi = delitel - n % delitel
		k += shagi
		delitel *= 10
		n += shagi
		summa = sum(map(int, list(str(n))))
	print(k)
t = int(input())
for i in range(t):
	kek()


import math
test = int(input())
for i in range(test):
	(a, b) = map(int, input().split())
	f = 0
	if a < b:
		print(b - a)
		f = 1
	if a % b == 0:
		print(0)
		f = 1
	i = 2
	if f == 0:
		x = math.ceil(a / b)
		b = b * x
	if f == 0:
		print(b % a)


from sys import stdin, stdout
nbre = int(stdin.readline())
for loop in range(nbre):
	(n1, n2) = map(int, stdin.readline().strip().split(' '))
	if n1 % n2 == 0:
		print('0')
		continue
	a = n1 // n2 + 1
	resultat = a * n2 - n1
	print(resultat)


def divisibile(a, b):
	if a % b == 0:
		return 0
	count = b - a % b
	return count
n = int(input())
for i in range(n):
	x = list(map(int, input().rstrip().split()))
	a = x[0]
	b = x[1]
	print(divisibile(a, b))


def num_moves(a, b):
	if a % b == 0:
		return 0
	return b - a % b
t = int(input())
ans = []
for i in range(t):
	(a, b) = [int(s) for s in input().split(' ')]
	ans.append(num_moves(a, b))
for i in range(t):
	print(ans[i])


def main():
	result = str()
	for i in range(int(input())):
		(a, b) = map(int, input().split())
		if a == b or a % b == 0:
			r = 0
		else:
			r = (a // b + 1) * b - a
		result += f'{r}\n'
	print(result.strip())
main()


import math

def rMap():
	return map(int, input().split())

def rList():
	return list(map(int, input().split()))
t = int(input())
for i in range(t):
	(a, b) = rMap()
	x = math.ceil(a / b)
	b = b * x
	print(b - a)


def abc(n, m):
	c = 0
	a = '0'
	b = ''
	for j in str(n):
		c += int(j)
		if c >= m:
			b += '0'
		else:
			a += j
	c = ''
	flag = 1
	for j in a[-1::-1]:
		if flag:
			if j == '9':
				c += '0'
			else:
				c += str(int(j) + 1)
				flag = 0
		else:
			c += j
	if flag:
		c += '1'
	return int(c[-1::-1] + b) - n

def sum(n):
	c = 0
	while n > 0:
		c += n % 10
		n = n // 10
	return c
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	if sum(n) <= m:
		print(0)
		continue
	print(abc(n, m))


T = int(input())
for t in range(T):
	(a, b) = map(int, input().split())
	res = 0
	if a % b != 0:
		res = b - a % b
	print(res)


def Check(n, m):
	Sum = 0
	for i in str(n):
		Sum += int(i)
	return Sum <= m

def Solve():
	(n, m) = map(int, input().split())
	x = n
	if Check(n, m):
		print(0)
		return
	else:
		n = str(n)
		Sum = 0
		for i in range(len(n)):
			Sum += int(n[i])
			if Sum >= m and i == 0:
				n = '1' + '0' * len(n)
				print(int(n) - x)
				return
			if Sum >= m:
				if int(n[i - 1]) + 1 < 10:
					n = n[0:i - 1] + str(int(n[i - 1]) + 1) + '0' * (len(n) - i)
					print(int(n) - x)
				else:
					while i >= 1 and int(n[i - 1]) + 1 == 10:
						i -= 1
					if i == 0:
						n = '1' + '0' * len(n)
						print(int(n) - x)
					else:
						n = n[0:i - 1] + str(int(n[i - 1]) + 1) + '0' * (len(n) - i)
						print(int(n) - x)
				return
t = int(input())
for _ in range(t):
	Solve()


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))
t = inp()
for x in range(0, t):
	l = inlt()
	a = l[0]
	b = l[1]
	if a % b == 0:
		print(0)
	elif a > b:
		print(b - (a - b) % b)
	else:
		y = b - a
		print(y % b)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	string_n = str(n)
	string_s = str(s)
	size_n = len(string_n)
	size_s = len(string_n)
	m = size_n - size_s
	mov = 0
	for i in string_n:
		mov += int(i)
	if s >= n or mov <= s:
		print(0)
	else:
		f = string_n[0]
		fs = string_s[0]
		f_plus_1 = str(int(f) + 1)
		(x, y) = (1, int(string_n[0]))
		while y < s:
			y += int(string_n[x])
			x += 1
		if x == 1 and int(f) >= s:
			ans = int('1' + '0' * size_n) - n
		else:
			ans = int(str(int(string_n[:x - 1]) + 1) + '0' * (size_n - x + 1)) - n
		print(ans)


from sys import stdin, stdout

def main():
	t = int(stdin.readline())
	for x in range(t):
		(a, b) = [int(c) for c in input().split()]
		if a % b == 0:
			print(0)
		else:
			print(b - a % b)
main()


t = int(input())
for i in range(t):
	(a, b) = list(map(int, input().split()))
	if a % b == 0:
		print(0)
	else:
		div = a % b
		print(b - div)


import math

def checksum(n):
	return sum([int(x) for x in str(n)])
for _ in range(int(input())):
	(n, s) = [int(p) for p in input().split()]
	moves = 0
	if checksum(n) <= s:
		print(0)
	else:
		pow = 10
		while True:
			closest = pow * ((n + pow - 1) // pow)
			moves += closest - n
			n = closest
			if checksum(n) <= s:
				break
			pow *= 10
		print(moves)


def res(n, s):
	a = str(n)
	b = str(s)
	n_len = len(a)
	s_len = len(b)
	san = n
	sandar = []
	for i in range(n_len):
		sandar.append(san % 10)
		san = san // 10
	sum_n = sum(sandar)
	if sum_n <= s:
		return 0
	else:
		k = s
		total = 0
		for i in range(n_len):
			if sandar[n_len - 1 - i] < k:
				k = k - sandar[n_len - 1 - i]
			elif n_len - i >= n_len:
				return 10 ** (n_len - s_len + 1) - n
			else:
				sandar[n_len - i] += 1
				for j in range(i):
					total += sandar[n_len - 1 - j] * 10 ** (n_len - 1 - j)
				return total - n
n = int(input())
reuslt = []
for i in range(n):
	data = list(map(int, input().split()))
	reuslt.append(res(data[0], data[1]))
for i in range(n):
	print(reuslt[i])


def divisor(a, b):
	if a % b == 0:
		return 0
	r = a % b
	return b - r
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	print(divisor(a, b))


T = int(input())
for _ in range(T):
	line = input()
	(n, s) = line.split()[:2]
	a = [int(c) for c in n]
	s = int(s)
	t = sum(a)
	if t <= s:
		ans = 0
	else:
		for (i, p) in enumerate(range(len(a))[::-1]):
			if p > 0:
				a[p - 1] += 1
				t += 1
			t -= a[p]
			a[p] = 0
			if t <= s:
				ans = 10 ** (i + 1) - int(n[p:])
				break
	print(ans)


t = int(input())
for x in range(t):
	(number, s) = input().split(' ')
	s = int(s)
	sum = 0
	for i in number:
		sum += int(i)
	diff = sum - s
	answer = ''
	number = number[::-1]
	number = list(number)
	for (key, i) in enumerate(number):
		if diff > 0 and int(i) > 0:
			diff -= int(i)
			answer += str(10 - int(i))
			if key != len(number) - 1:
				number[key + 1] = str(int(number[key + 1]) + 1)
				diff += 1
		elif diff > 0 and int(i) == 0:
			answer += i
		else:
			break
	answer = answer[::-1]
	if answer == '':
		print(0)
	else:
		answer = int(answer)
		print(answer)


def solve(a, b):
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)
test = int(input())
for t in range(test):
	ss = input().split()
	a = int(ss[0])
	b = int(ss[1])
	solve(a, b)


t = int(input())
for _ in range(t):
	(n, s) = list(map(int, input().split()))
	nsplit = list(map(int, list(str(n))))

	def listToStr(intList):
		return ''.join(map(str, intList))
	diff = sum(nsplit) - s
	while diff > 0:
		for i in range(len(nsplit)):
			ind = -(i + 1)
			if nsplit[ind] != 0:
				nsplit = nsplit[:ind] + [0] * (i + 1)
				rolledOver = False
				rollInd = ind - 1
				while rolledOver == False:
					if rollInd <= -(len(nsplit) + 1):
						nsplit.insert(0, 1)
						rolledOver = True
					elif nsplit[rollInd] == 9:
						nsplit[rollInd] = 0
						rollInd -= 1
					else:
						nsplit[rollInd] += 1
						rolledOver = True
				break
		diff = sum(nsplit) - s
	print(int(listToStr(nsplit)) - n)


def sum_of_digits(n):
	s = 0
	while n != 0:
		r = n % 10
		s = s + r
		n = n // 10
	return s
t = int(input())
while t > 0:
	(n, s) = map(int, input().split())
	start = n
	cur = 1
	while 1:
		d = n % cur
		if d != 0:
			n += cur - d
		if sum_of_digits(n) <= s:
			print(n - start)
			break
		cur *= 10
	t -= 1


t = int(input())
for case in range(t):
	(a, b) = [int(zax) for zax in input().split()]
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


n = int(input())

def divisible(a, b):
	number = a % b
	if number == 0:
		return 0
	return b - number
for i in range(n):
	a = list(map(int, input().split()))
	print(divisible(a[0], a[1]))


t = int(input())
list_step = []
for i in range(t):
	(a, b) = input().split()
	step = 0
	if int(a) < int(b):
		step = int(b) - int(a)
	elif int(a) % int(b) == 0:
		step = 0
	else:
		factor = int(a) // int(b) + 1
		step = int(b) * factor - int(a)
	list_step.append(step)
for i in range(t):
	print(list_step[i])


output = []
t = int(input())
for i in range(0, t):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if a % b == 0:
		output += [0]
	elif a > b:
		output += [abs(a % b - b)]
	else:
		output += [abs(b - a)]
for x in output:
	print(x)


import math

def dtb(n):
	return bin(n).replace('0b', '')

def btd(n):
	return int(n, 2)

def sumofdigits(n):
	sod = 0
	while n > 0:
		sod += n % 10
		n //= 10
	return sod
t = int(input())
for k in range(t):
	(n, s) = map(int, input().split())
	m = n
	sod = sumofdigits(m)
	if sod <= s:
		print(0)
		continue
	fact = 10
	while 1:
		rem = n % fact
		n += (fact - rem) % fact
		sod = sumofdigits(n)
		if sod <= s:
			break
		fact *= 10
	print(n - m)


for _ in range(int(input())):
	(d, s) = input().split()
	n = [int(i) for i in d]
	s = int(s)
	if sum(n) <= s:
		print(0)
	else:
		c = 0
		t = len(n)
		for i in range(len(n)):
			if c + n[i] < s:
				c += n[i]
			else:
				break
		f = d[i:]
		t = t - i
		g = 10 ** t - int(f)
		print(g)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	j = l = len(str(n))
	lst = [0 for i in range(l + 1)]
	(a, b) = (0, 0)
	while n:
		lst[j] = n % 10
		n //= 10
		a += lst[j]
		b += 1
		j -= 1
	ans = 0
	b += 1
	for i in range(l, 0, -1):
		c = lst[i]
		if a > s:
			b += 1
			ans += (10 - lst[i]) * 10 ** (l - i)
			a -= lst[i]
			j = i - 1
			while j and lst[j] == 9:
				lst[j] = 0
				j -= 1
				a -= 9
			a += 1
			b += 1
			lst[j] += 1
		else:
			break
			b += 1
	print(ans)


def do2(n, s):
	pass

def do():
	q = int(input())
	for _ in range(q):
		a = [0] * 30
		res = [0] * 30
		(n, s) = input().split()
		n = n[::-1]
		for i in range(len(n)):
			a[i] = int(n[i])
		s = int(s)
		i = 0
		while sum(a) > s:
			if a[i] > 9:
				(a[i], a[i + 1]) = (a[i] % 10, a[i + 1] + a[i] // 10)
				continue
			if a[i] == 0:
				i += 1
				continue
			res[i] = 10 - a[i]
			a[i + 1] += 1
			a[i] = 0
			i += 1
		res = int(''.join(map(str, res[::-1])))
		print(res)
do()


from math import ceil
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a < b:
		print(b - a)
	else:
		x = ceil(a / b)
		print(b * x - a)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
t = int(input())
for _ in range(t):
	(n, s) = input().split()
	arr = [int(x) for x in n]
	s = int(s)
	if sum(arr) <= s:
		print(0)
		continue
	temp = 0
	last = 0
	for (ind, val) in enumerate(arr):
		if val + temp >= s:
			last = ind
			break
		temp += val
	zeros = len(n) - last
	ans = 10 ** zeros - int(''.join([str(x) for x in arr[last:]]))
	print(ans)


tests_count = int(input())

def calc_result(a, b):
	mod = a % b
	if mod > 0:
		val = b - mod
	else:
		val = 0
	return val
for i in range(tests_count):
	line = input()
	a = int(line.split(' ')[0])
	b = int(line.split(' ')[1])
	res = calc_result(a, b)
	print(res)


n = int(input())
lst = []
for i in range(n):
	c = 0
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if a % b == 0:
		lst.append(c)
	else:
		c = b - a % b
		lst.append(c)
for i in lst:
	print(i)


t = int(input())
for _ in range(t):
	(n, s) = map(int, input().split())
	a = []
	sm = 0
	while n > 0:
		dg = n % 10
		a.append(dg)
		sm += dg
		n //= 10
	if sm <= s:
		print(0)
		continue
	i = len(a) - 1
	while s > 0:
		s -= a[i]
		i -= 1
	i += 1
	dc = pow(10, i + 1)
	nc = 0
	while i >= 0:
		nc += a[i]
		nc *= 10
		i -= 1
	nc //= 10
	print(dc - nc)


n = int(input())
i = 0
x = []
while i < n:
	p = input()
	x.append(p)
	i = i + 1
for er in x:
	we = er.split()
	if int(we[0]) < int(we[1]):
		print(int(we[1]) - int(we[0]))
	elif int(we[0]) % int(we[1]) == 0:
		print(0)
	elif int(we[0]) > int(we[1]):
		print((int(we[0]) // int(we[1]) + 1) * int(we[1]) - int(we[0]))


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a >= b:
		d = a // b
		if a % b:
			d += 1
		print(d * b - a)
	else:
		print(b - a)


from math import ceil
n = int(input())
answers = []
for i in range(n):
	(a, b) = input().split()
	(a, b) = (int(a), int(b))
	if a < b:
		answers.append(b - a)
	else:
		answers.append(ceil(a / b) * b - a)
for i in answers:
	print(i)


n = int(input())
for i in range(n):
	t = [int(x) for x in input().split()]
	c = t[0] % t[1]
	if c == 0:
		print(0)
	else:
		print(t[1] - c)


from math import ceil

def main():
	t = int(input(''))
	for i in range(t):
		nums = input('').split()
		a = int(nums[0])
		b = int(nums[1])
		division = ceil(a / b)
		minNumber = division * b - a
		print(minNumber)
main()


t = int(input())
for tt in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		aa = (a // b + 1) * b
		print(aa - a)


a = int(input())
p = 0
for b in range(0, a):
	c = input().split()
	d1 = int(c[0])
	d2 = int(c[1])
	if d1 >= d2:
		if d1 % d2 == 0:
			p = 0
		elif d1 % d2 != 0:
			p = int(d1 / d2)
			if d2 * p > d1:
				p = d2 * p - d1
			elif d1 > d2 * p:
				p = d2 * (p + 1) - d1
	elif d2 > d1:
		p = d2 - d1
	print('{}'.format(p))


x = int(input())
for z in range(x):
	(n1, s) = input().split()
	n = n1
	s = int(s)
	sm = 0
	for k in range(len(n)):
		sm = sm + int(n[k])
	if sm <= s:
		print(0)
	else:
		if int(n[0]) >= s or n[0] == '9':
			n = '0' + n
		n = list(n)
		bruh = 0
		i = 0
		while bruh < s and i < len(n):
			bruh += int(n[i])
			i += 1
		i = i - 2
		while n[i] == '9':
			n[i] = '0'
			i = i - 1
		n[i] = str(int(n[i]) + 1)
		for a in range(i + 1, len(n)):
			n[a] = '0'
		c = ''.join(n)
		print(int(c) - int(n1))


import math
from collections import deque
from sys import stdin, stdout
from string import ascii_letters
import sys
letters = ascii_letters
input = stdin.readline
for i in range(int(input())):
	bf = input().strip().split()
	s = int(bf[1])
	arr = list(map(int, bf[0]))
	before = 1
	while arr[-1] == 0:
		arr.pop(-1)
		before *= 10
	have = sum(arr)
	need = 0
	n = len(arr)
	for i in range(n - 1, -1, -1):
		if have <= s:
			break
		if arr[i] <= 0:
			before *= 10
			continue
		need += (10 - arr[i]) * before
		have -= arr[i]
		arr[i] = 0
		ind = i - 1
		while ind >= 0:
			arr[ind] += 1
			have += 1
			if arr[ind] == 10:
				arr[ind] = 0
				have -= 10
				if ind == 0:
					break
			else:
				break
			ind -= 1
		before *= 10
	print(need)


x1 = int(input())
for i in range(x1):
	input_list = [int(a) for a in input().split()]
	x = input_list[0]
	y = input_list[1]
	if x % y == 0:
		print(0)
	else:
		print(y - x % y)


def no_of_moves(a, b):
	moves = 0
	if a % b == 0:
		return 0
	elif a < b:
		moves += b - a
	elif a > b:
		moves += a - a % b + b - a
	return moves

def main():
	t = int(input())
	moves = []
	for i in range(t):
		(a, b) = [int(i) for i in input().split()]
		move_count = no_of_moves(a, b)
		moves.append(move_count)
	for count in moves:
		print(count)
main()


def solve(a, b):
	return (b - a % b) % b
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	print(solve(a, b))
assert solve(10, 4) == 2
assert solve(13, 9) == 5
assert solve(100, 13) == 4
assert solve(123, 456) == 333
assert solve(92, 46) == 0


t = int(input())
for i in range(t):
	inp = input().split(' ')
	remainder = int(inp[0]) % int(inp[1])
	if remainder == 0:
		print(remainder)
	else:
		print(int(inp[1]) - remainder)


def sum(n):
	s = 0
	while n > 0:
		s += n % 10
		n = n // 10
	return s

def solve(n, s):
	ans = 0
	place = 1
	while True:
		currsum = sum(n)
		if currsum <= s:
			return ans
		r = n % (place * 10) // place
		if r == 0:
			place *= 10
			continue
		n += (10 - r) * place
		ans += place * (10 - r)
		place *= 10
	return ans
t = int(input())
while t > 0:
	t -= 1
	inp = input()
	inp = inp.split(' ')
	n = int(inp[0])
	s = int(inp[1])
	ans = solve(n, s)
	print(ans)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	elif a < b:
		print(b - a)
	elif a > b:
		x = a // b + 1
		print(x * b - a)


n = int(input())
for k in range(n):
	test = input().split(' ')
	maxi = int(test[1])
	l = len(test[0])
	suma = 0
	test[0] = list(map(int, test[0]))
	i = 0
	i2 = -1
	for i in range(l):
		suma += test[0][i]
		if suma > maxi:
			break
		if suma == maxi and i2 == -1:
			i2 = i
	zeros = True
	ret = []
	if suma <= maxi:
		ret = [0]
		i += 1
	elif i2 > -1:
		i = i2
	for j in range(1, l - i + 1):
		c = test[0][l - j]
		if zeros:
			if c == 0:
				ret.append(0)
			else:
				zeros = False
				ret.append(10 - c)
		else:
			ret.append(9 - c)
	x = l - i - 1
	if len(ret) > 1:
		while ret[x] == 0:
			x -= 1
	print(''.join(map(str, ret[x::-1])))


def check(a, s):
	l = []
	for i in str(a):
		l.append(int(i))
	if sum(l) <= s:
		return True
	else:
		return False
for _ in range(int(input())):
	(a, s) = map(int, input().split())
	ans = 0
	if check(a, s):
		print(ans)
	else:
		a = str(a)
		c = 0
		for i in range(len(str(a)) - 1, -1, -1):
			if a[i] != '0':
				temp = str(10 - int(a[i]))
				temp += '0' * c
				temp = int(temp)
				ans += temp
				a = str(int(a) + temp)
				if check(int(a), s):
					break
			c += 1
		print(ans)


T = int(input())
while T > 0:
	(n, s) = map(int, input().split())
	x = n
	digits = []
	while x > 0:
		digits.append(x % 10)
		x //= 10
	digits.append(0)
	temp = sum(digits)
	res = 0
	last_digit = 0
	ad = 1
	while temp > s:
		res += (10 - digits[last_digit]) * ad
		temp -= digits[last_digit]
		digits[last_digit] = 0
		last_digit += 1
		digits[last_digit] += 1
		while digits[last_digit] == 10:
			digits[last_digit] = 0
			temp -= 9
			last_digit += 1
			digits[last_digit] += 1
			ad *= 10
		temp += 1
		ad *= 10
	print(res)
	T -= 1


from sys import stdin, stdout
import math

def main():
	t = int(input())
	while t:
		(n, m) = map(int, input().split())
		if n % m != 0:
			print(m - n % m)
		else:
			print(0)
		t -= 1
main()


for j in range(int(input())):
	(n, s) = map(int, input().split())
	arr = [int(k) for k in str(n)]
	length = len(arr)
	cursum = sum(arr)
	cur = 0
	found = False
	ans = []
	if cursum <= s:
		print(0)
	else:
		for i in range(length - 1, -1, -1):
			if arr[i] != 9:
				temp = cursum + 1 - cur
				if temp <= s:
					found = True
					for b in range(length):
						if b < i:
							ans.append(arr[b])
						elif b == i:
							ans.append(arr[b] + 1)
						else:
							ans.append(0)
					break
			cur += arr[i]
		if found == True:
			num2 = ''.join([str(k) for k in ans])
			print(int(num2) - n)
		else:
			print(10 ** length - n)


def func(num1, num2):
	if num1 % num2 == 0:
		return 0
	else:
		k = int((int(num1 / num2) + 1) * num2 - num1)
		return k
n = int(input())
li = []
for i in range(n):
	(num1, num2) = input().split()
	num1 = int(num1)
	num2 = int(num2)
	li.append(func(num1, num2))
for i in li:
	print(i)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
import threading
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def digits(n):
	s = 0
	while n > 0:
		s += n % 10
		n //= 10
	return s
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	copy = n
	n = list('0' + str(n))
	ch = 0
	if digits(copy) <= s:
		ch = 1
	for i in range(len(n) - 1, 0, -1):
		if ch == 1:
			break
		n[i] = '0'
		n[i - 1] = str(int(n[i - 1]) + 1)
		d = 0
		for j in range(len(n)):
			d += int(n[j])
		if d <= s:
			ch = 1
			break
	d = 0
	for j in range(len(n)):
		d = d * 10 + int(n[j])
	print(d - copy)


from sys import stdin, stdout
t = int(stdin.readline())
while t:
	(a, b) = map(int, stdin.readline().split(' '))
	if b > a:
		stdout.write(str(b - a))
		stdout.write('\n')
	elif a % b:
		stdout.write(str(b % a - a % b))
		stdout.write('\n')
	else:
		stdout.write(str(0))
		stdout.write('\n')
	t -= 1


from sys import stdin, stdout, setrecursionlimit
import heapq
from math import gcd, ceil, sqrt
from collections import Counter, deque
from bisect import bisect_left, bisect_right
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
setrecursionlimit(100000)
mod = 1000000007

def get(n):
	tot = 0
	for i in n:
		tot += int(i)
	return tot

def inc(n):
	n = list(str(n))[::-1]
	ext = 1
	for i in range(len(n)):
		if int(n[i]) + ext > 9:
			n[i] = '0'
		else:
			n[i] = str(int(n[i]) + ext)
			ext = 0
	if ext:
		n += ['1']
	return int(''.join(n)[::-1])
tc = ii1()
for _ in range(tc):
	(n, s) = iia()
	t = n
	tot = get(str(n))
	count = 0
	while tot > s:
		cur = n % 10
		t1 = get(str(n // 10))
		t2 = get(str(n))
		n //= 10
		n = inc(n)
		count += 1
		tot = get(str(n))
	n = n * pow(10, count)
	print(n - t)


t = int(input())
result = []
while t:
	(a, b) = list(map(int, input().split()))
	check = a % b
	if check:
		steps = b - a % b
		result.append(steps)
	else:
		result.append(0)
	t -= 1
for res in result:
	print(res)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	nstr = str(n)
	sum = []
	sum.append(int(nstr[0]))
	for i in range(1, len(nstr)):
		lval = sum[-1]
		sum.append(lval + int(nstr[i]))
	ind = 0
	while ind < len(nstr):
		if sum[ind] >= s:
			break
		ind += 1
	res = nstr[:ind] + '0' * (len(nstr) - ind)
	if sum[-1] <= s:
		print(int(nstr) - n)
	else:
		res = res[:ind - 1] + chr(int(res[ind - 1]) + ord('0')) + res[ind:]
		print(int(res) + 10 ** (len(nstr) - ind) - n)


for _ in range(int(input())):
	(n, s) = input().split()
	s = int(s)
	check = 0
	x = len(n)
	ans = n
	for i in range(x):
		check += ord(n[i]) - ord('0')
		if check == s:
			if i == x - 1 or int(n[i + 1:]) == 0:
				ans = n
				break
			else:
				if i != 0:
					if n[i - 1] != '9':
						ans = n[:i - 1] + str(int(n[i - 1]) + 1) + '0' * (x - i)
					else:
						temp = ''
						c = 1
						for g in reversed(range(0, i)):
							if n[g] == '9' and c == 1:
								temp += '0'
							else:
								if c == 1:
									temp += str(int(n[g]) + 1)
								else:
									temp += n[g]
								c = 0
						ans = temp[::-1] + '0' * (x - i)
				else:
					ans = '1' + '0' * x
				break
		elif check > s:
			if i != 0:
				if n[i - 1] != '9':
					ans = n[:i - 1] + str(int(n[i - 1]) + 1) + '0' * (x - i)
				else:
					temp = ''
					c = 1
					for g in reversed(range(0, i)):
						if n[g] == '9' and c == 1:
							temp += '0'
						else:
							if c == 1:
								temp += str(int(n[g]) + 1)
							else:
								temp += n[g]
							c = 0
					ans = temp[::-1] + '0' * (x - i)
			else:
				ans = '1' + '0' * x
			break
	p = int(ans) - int(n)
	if p < 0:
		ans = '1' + ans
		print(int(ans) - int(n))
	else:
		print(p)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	r = a // b
	d = a % b
	if d == 0:
		print(0)
	else:
		res = b * (r + 1)
		print(res - a)


n = int(input())

def ceil(n, k):
	return n // k + (n % k != 0)
for i in range(n):
	(a, b) = map(int, input().split())
	t = ceil(a, b)
	print(b * t - a)


def DivisibilityProb(totalValues, listofaChoices, listofbChoices):
	for index in range(totalValues):
		if listofaChoices[index] < listofbChoices[index]:
			print(listofbChoices[index] - listofaChoices[index])
		elif listofaChoices[index] % listofbChoices[index] == 0:
			print(0)
		else:
			print(listofbChoices[index] - listofaChoices[index] % listofbChoices[index])

def main():
	totalValues = int(input())
	listofaChoices = []
	listofbChoices = []
	for index in range(totalValues):
		inputVals = list(map(int, input().split()))
		listofaChoices.append(inputVals[0])
		listofbChoices.append(inputVals[1])
	DivisibilityProb(totalValues, listofaChoices, listofbChoices)
main()


from pathlib import Path
import sys
import functools
import itertools
import re

def ok(val, s):
	ret = 0
	while val > 0:
		ret += val % 10
		val = val // 10
	return True if ret <= s else False

def solve():
	t = int(input())
	for test in range(t):
		(n, s) = map(int, input().split())
		pw = 1
		ans = 0
		for i in range(0, 18):
			if ok(n, s) == True:
				break
			digit = n // pw % 10
			adds = pw * ((10 - digit) % 10)
			n += adds
			ans += adds
			pw *= 10
		print(ans)

def main():
	if Path('test.inp').exists():
		sys.stdin = open('test.inp', 'r')
	solve()
main()


n = int(input())
for i in range(n):
	(a, b) = input().split(' ')
	(a, b) = (int(a), int(b))
	rem = a % b
	ans = b - rem
	print(ans % b)


x = int(input())
for i in range(x):
	(a, b) = list(map(int, input().split(' ')))
	if a % b == 0:
		print(0)
	else:
		diferenca = b - a % b
		print(diferenca)


n = int(input())
for q in range(n):
	b = []
	for a in input().split():
		b.append(int(a))
	if b[0] % b[1] != 0:
		print(b[1] - b[0] % b[1])
	else:
		print(0)


for _ in range(int(input())):
	n = input().split()
	a = int(n[0])
	b = int(n[1])
	if a < b:
		print(b - a)
	elif a % b == 0:
		print(0)
	else:
		c = int(a / b)
		d = b * (c + 1)
		print(d - a)


t = int(input())
for i in range(t):
	(a, b) = list(map(int, input().split()))
	residue = a % b
	to_add = (b - residue) % b
	print(to_add)


t = int(input())
while t > 0:
	t -= 1
	(a, b) = list(map(int, input().split()))
	if a == b or a % b == 0:
		print('0')
	elif a > b:
		x = int(a % b)
		print(b - x)
	else:
		print(b - a)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	ans = 0
	k = a // b
	if a % b == 0:
		print(0)
	else:
		r = b * (k + 1)
		ans = r - a
		print(ans)


from sys import stdin
inp = stdin.readline
t = int(inp())
for i in range(t):
	(a, b) = [int(x) for x in inp().split()]
	if a < b:
		print(b - a)
	elif a % b == 0:
		print(0)
	else:
		rounded = a // b + 1
		print(abs(a - b * rounded))


def solve(a, b):
	print((b - a % b) % b)
t = int(input())
for i in range(0, t):
	nums = list(map(lambda n: int(n), input().split()))
	solve(nums[0], nums[1])


from sys import exit

def i():
	return input()

def ii():
	return int(input())

def iis():
	return map(int, input().split())

def liis():
	return list(map(int, input().split()))

def print_array(a):
	print(' '.join(map(str, a)))
t = ii()
for _ in range(t):
	(a, b) = iis()
	div = a // b
	if b * div == a:
		print(0)
	else:
		print(b * (div + 1) - a)


import sys
input = sys.stdin.readline
from sys import stdin, stdout

def main():
	for _ in range(int(input())):
		(a, b) = [int(s) for s in input().split()]
		w = a // b
		w1 = a % b
		if w1 == 0:
			print(0)
		else:
			print(b - w1)
main()


for i in range(int(input())):
	(a, b) = (int(j) for j in input().split())
	d1 = int(a / b)
	d2 = int((a + b - 1) / b)
	if d1 * b < a:
		print(d2 * b - a)
	else:
		print(d1 * b - a)


import sys
input = sys.stdin.readline
t = int(input())
for ti in range(1, t + 1):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		print((a + b) // b * b - a)


import sys
import heapq

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def rinput():
	return map(int, input().split())

def rlinput():
	return list(map(int, input().split()))

def main():
	(a, b) = rinput()
	print((b - a % b != b) * (b - a % b))
for i in range(iinput()):
	main()


def main():
	t = int(input())
	for test in range(t):
		raw_in = input()
		ab = raw_in.split(' ')
		a = int(ab[0])
		b = int(ab[1])
		m = b - a % b
		if a % b == 0:
			m = 0
		print(m)
main()


import sys
read = lambda : sys.stdin.readline().strip()
for _ in range(int(read())):
	(s, n) = read().split()
	n = int(n)
	s = list(map(int, list(s)))[::-1]
	s1 = s.copy()
	total = sum(s)
	if total <= n:
		print(0)
		continue
	place = None
	temp_sum = 0
	for (i, digit) in enumerate(s):
		s1[i] = 0
		temp_sum += digit
		if total - temp_sum + 1 <= n:
			break
	i += 1
	while i < len(s1):
		s1[i] += 1
		if s1[i] > 9:
			s1[i] = 0
			i += 1
		else:
			break
	else:
		s1.append(1)
	s1 = int(''.join(map(str, s1[::-1])))
	s = int(''.join(map(str, s[::-1])))
	print(s1 - s)


t = int(input())
for i in range(0, t):
	array = input().split()
	n = int(array[0])
	m = int(array[1])
	ans = n / m
	div = n % m
	print((m - div) % m)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	x1 = a % b
	x2 = b - x1
	if x2 == b:
		x2 = 0
	print(x2)


testcase = int(input())
i = 0
answer = []
while i < testcase:
	(a, b) = map(int, input().split())
	if a % b == 0:
		answer.append(0)
	else:
		answer.append(b - a % b)
	i += 1
for c in answer:
	print(c)


import math

def main():
	q = int(input())
	for x in range(q):
		(a, b) = map(int, input().split())
		if b > a:
			print(b - a)
		else:
			print(math.ceil(a / b) * b - a)
main()


import sys
import math
input = sys.stdin.readline

def inp():
	return int(input())

def inara():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def num(n):
	ans = []
	while n:
		ans.append(n % 10)
		n //= 10
	ans.append(0)
	return ans

def sod(n):
	if n < 10:
		return n
	return n % 10 + sod(n // 10)
t = inp()
for _ in range(t):
	(n, k) = invr()
	number = num(n)
	digit = len(number) - 1
	answer = 10 ** (digit + 1)
	if sod(n) <= k:
		answer = n
	for i in range(digit):
		temp = list(number)
		for j in range(i + 1):
			temp[j] = 0
		for j in range(i + 1, digit + 1):
			if temp[j] == 9:
				temp[j] = 0
			else:
				temp[j] += 1
				break
		temp.reverse()
		curr = 0
		for j in range(digit + 1):
			curr *= 10
			curr += temp[j]
		if sod(curr) <= k and curr <= answer:
			answer = curr
	print(answer - n)


n = int(input())
ans = []
nums = []
for i in range(n):
	temp = input().split()
	temp = [int(l) for l in temp]
	if temp[0] % temp[1] == 0:
		ans.append(str(0))
	else:
		res = (int(temp[0] / temp[1] // 1) + 1) * temp[1] - temp[0]
		ans.append(str(res))
print('\n'.join(ans))


n = int(input())
a = []
b = []
for i in range(n):
	s = list(map(int, input().split()))
	a.append(s[0])
	b.append(s[1])
for i in range(n):
	r1 = int(a[i] % b[i])
	if r1 != 0:
		c = b[i] - r1
	else:
		c = 0
	print(c)


n = int(input())
for i in range(n):
	arr = list(map(int, input().split()))
	sum = 0
	if arr[0] % arr[1] == 0:
		print(sum)
	else:
		x = arr[0] % arr[1]
		sum = arr[1] - x
		print(sum)


import sys
for _ in range(int(sys.stdin.readline())):
	(a, b) = map(int, sys.stdin.readline().split())
	ans = 0
	if a % b == 0:
		print(0)
	else:
		if a > b:
			x = int(a / b) + 1
			ans = b * x - a
		else:
			ans = b - a
		print(ans)


for _ in range(int(input())):
	(n, s) = input().split()
	s = int(s)
	a = [int(i) for i in list(n)[::-1]]
	a.append(0)
	x = sum(a)
	i = 0
	res = 0
	y = len(a) - 1
	while x > s and i < y:
		if a[i] != 0:
			a[i + 1] += 1
			res += (10 - a[i]) * 10 ** i
			x -= a[i] - 1
		i += 1
	print(res)


result = []
t = int(input())
for i in range(0, t):
	(a, b) = [int(x) for x in input().split()]
	if a % b == 0:
		result.append(0)
	else:
		result.append(b * (a // b + 1) - a)
for i in range(0, len(result)):
	print(result[i])


n = int(input())
for x in range(n):
	(a, b) = map(int, input().split())
	bb = a // b
	if a % b != 0:
		bb += 1
	print(abs(b * bb - a))


l = []
n = int(input())
ct = 0
for i in range(n):
	ct = 0
	e = input().split(' ')
	a = int(e[0])
	b = int(e[-1])
	if a % b == 0:
		print(0)
	else:
		c = a // b
		c += 1
		print(b * c - a)


from math import ceil
n = int(input())
for x in range(n):
	(a, b) = [int(x) for x in input().split(' ')]
	highest = ceil(a / b)
	print(b * highest - a)


def solve(a, b):
	if a % b == 0:
		return 0
	return b - a % b
n = int(input().strip())
for i in range(n):
	(x, y) = list(map(int, input().strip().split()))
	print(solve(x, y))


import math

def sumOfDigits(string):
	ans = 0
	for i in range(len(string)):
		ans += int(string[i])
	return ans
t = int(input())
for _ in range(t):
	(n, s) = map(int, input().split())
	n = str(n)
	ans = 0
	index = len(n) - 1
	while sumOfDigits(n) > s:
		while n[index] == '0':
			index -= 1
		add = (10 - int(n[index])) * 10 ** (len(n) - index - 1)
		ans += add
		n = str(int(n) + add)
	print(ans)


def divisibility(a, b):
	if a % b == 0:
		return 0
	elif b > a:
		return b - a
	else:
		return b - a % b
x = int(input())
for i in range(x):
	(a, b) = map(int, input().split())
	print(divisibility(a, b))


t = int(input())
for i in range(t):
	(aa, bb) = map(int, input().split())
	if aa % bb != 0:
		cc = bb - aa % bb
		print(cc)
	else:
		print('0')


tc = int(input())
for _ in range(tc):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		num = a // b
		print(b * (num + 1) - a)


n = int(input())
for i in range(n):
	cmd = input()
	main = map(int, cmd.split())
	lst = list(main)
	a = lst[0]
	b = lst[1]
	if a % b == 0:
		print(0)
	else:
		n = a // b
		nxt = b * (n + 1)
		final = nxt - a
		print(final)


for i in range(int(input())):
	(a, b) = [int(i) for i in input().split()]
	res = (a // b + 1) * b - a
	if res % b:
		print(res)
		continue
	print(0)


def solve(ar, s):
	sumi = sum(ar)
	ans = 0
	for i in range(len(ar) - 1, 0, -1):
		if sumi > s:
			if ar[i] == 0:
				continue
			sumi -= ar[i]
			ans += 10 ** (len(ar) - 1 - i) * (10 - ar[i])
			ar[i] = 0
			ptr = i - 1
			while ar[ptr] == 9:
				sumi -= ar[ptr]
				ar[ptr] = 0
				ptr -= 1
			ar[ptr] = ar[ptr] + 1
			sumi += 1
		else:
			break
	print(ans)
t = int(input())
for _ in range(t):
	(n, s) = map(str, input().split())
	s = int(s)
	ar = [0]
	for i in n:
		ar.append(int(i))
	solve(ar, s)


import math
from sys import stdin
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(t,) = gil()
pow = []
for i in range(19):
	pow.append(10 ** i)

def getSum(n):
	p = math.ceil(math.log10(n))
	ans = 0
	for p in range(p + 1):
		if n:
			dig = n // pow[p] % 10
			ans += dig
			n -= dig * pow[p]
		else:
			break
	return ans
for _ in range(t):
	(n, s) = gil()
	old = n
	cs = sum([int(var) for var in str(n)])
	maxPow = math.ceil(math.log10(n))
	for p in range(maxPow + 1):
		if getSum(n) <= s:
			break
		dig = n // pow[p] % 10
		toAdd = (10 - dig) % 10
		n += toAdd * pow[p]
	print(n - old)


n = int(input())
for _ in range(n):
	q = input().split(' ')
	(a, b) = (int(q[0]), int(q[1]))
	if a % b == 0:
		print(0)
		continue
	x = a // b
	m = (x + 1) * b - a
	print(m)


import math
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a <= b:
		num_moves = b - a
	else:
		c = math.ceil(a / b)
		num_moves = abs(b * c - a)
	print(num_moves)


t = int(input())
for l in range(t):
	(a, b) = map(int, input().split())
	val = a % b
	if val == 0:
		print(0)
	else:
		print(b - val)


t = int(input())
for i in range(t):
	(a, b) = list(map(int, input().split()))
	upper = (a + b - 1) // b * b
	print(upper - a)


t = eval(input())
for case in range(t):
	(n, s) = input().split(' ')
	s = int(s)
	sumx = 0
	sum1 = 0
	ans = [0]
	flag = 0
	for i in n:
		sum1 += int(i)
	if sum1 <= s:
		print(0)
		continue
	for i in n:
		sumx += int(i)
		if sumx >= s and flag == 0:
			ans[-1] = ans[-1] + 1
			flag = 1
		if flag:
			ans.append(0)
		else:
			ans.append(int(i))
	k = 0
	for i in ans:
		k = k * 10 + i
	print(k - int(n))


import sys, math
input = sys.stdin.readline
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	cur = math.ceil(a / b)
	ans = b * cur
	ans -= a
	print(ans)


import sys
import bisect as bi
import math
from collections import defaultdict as dd
import heapq
import itertools
input = sys.stdin.readline
mo = 10 ** 9 + 7

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
for _ in range(inin()):
	(g, s) = cin()
	n = str(g)
	c = 0
	k = -1
	for i in range(len(n)):
		c += int(n[i])
		if c > s:
			k = i
			break
		elif c == s and n[i + 1:] != '0' * (len(n) - 1 - i):
			k = i
			break
	if k != -1:
		if i == 0:
			form = int('1' + '0' * (len(n) - k))
		else:
			form = int(str(int(n[:i]) + 1) + '0' * (len(n) - k))
		print(form - g)
	else:
		print(0)


(T, a, b) = (0, 0, 0)
T = int(input())
while T:
	(a, b) = map(int, input().split())
	print(int(((a - 1) // b + 1) * b - a))
	T -= 1


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict

def L():
	return list(map(int, stdin.readline().split()))

def In():
	return map(int, stdin.readline().split())

def I():
	return int(stdin.readline())
P = 1000000007
for t in range(I()):
	(a, b) = In()
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


kl = int(input())
for l in range(kl):
	(n, m) = map(int, input().split())
	print((m - n % m) % m)


import sys
input = sys.stdin.readline
from bisect import bisect_left
from bisect import bisect_right
from math import ceil, factorial

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')

def check(x):
	this = 1
	for i in range(40):
		if this == x:
			return True
		this *= 10
	return False
for _ in range(int(input())):
	(n, s) = int_array()
	array = []
	num = list(map(int, list(str(n))[::-1]))
	i = 0
	this = 1
	while sum(num) > s:
		if num[i]:
			number = int(''.join(map(str, num))[::-1])
			if check(number):
				break
			initial = num[i]
			add = this * (10 - num[i])
			number += add
			num = list(map(int, list(str(number))[::-1]))
			array.append((add, initial))
		this *= 10
		i += 1
	ans = 0
	current = sum(num)
	array.sort(reverse=1)
	for i in array:
		if i[1] <= current - s:
			current -= i[1]
		else:
			ans += i[0]
	print(ans)


import math
test = int(input())
while test > 0:
	(a, b) = [int(x) for x in input().split()]
	if a % b != 0:
		temp = math.ceil(a / b)
		print(b * temp - a)
	else:
		print(0)
	test -= 1


user = int(input())
userData = []
for i in range(0, user):
	data = input()
	data = data.split(' ')
	userData.append(data)
for i in range(0, len(userData)):
	a = int(userData[i][0])
	b = int(userData[i][1])
	if a % b == 0:
		print(0)
	else:
		print(b * (1 + int(a / b)) - a)


tc = int(input())
for t in range(tc):
	x = input().split()
	a = int(x[0])
	b = int(x[1])
	c = a % b
	c = b - c
	c = c % b
	print(c)


def solve():
	(a, b) = map(int, input().split())
	x = a // b
	if b * x < a:
		x += 1
	print(x * b - a)
t = int(input())
for _ in range(t):
	solve()
	t -= 1


t = int(input())
num = [list(map(int, input().split())) for _ in range(t)]
answer = []
for (a, b) in num:
	k = 0
	multi = b
	if a % b != 0:
		k = b - a % b
	answer.append(k)
for i in answer:
	print(i)


for _ in [0] * int(input()):
	(a, b) = map(int, input().split())
	print((b - a % b) % b)


import math
for _ in range(int(input())):
	y = list(map(int, input().split()))
	a = int(y[0])
	b = int(y[1])
	if a % b != 0:
		s = a // b + 1
		o = s * b - a
		print(o)
	else:
		print(0)


def solve():
	(a, b) = map(int, input().split())
	print((b - a % b) % b)
for i in range(int(input())):
	solve()


import sys
input = sys.stdin.readline
cases = int(input())
for tt in range(cases):
	(n, need) = map(int, input().split())
	i = 9
	ans = 0
	was = n
	(i, j, temp) = (9, 1, 0)
	while True:
		k = str(n)
		s = 0
		for c in range(len(k)):
			s += int(k[c])
		if s <= need:
			break
		temp += i * j
		n = (n + temp) // (temp + 1)
		n *= temp + 1
		j *= 10
		ans = n - was
	print(ans)


n = int(input())
for i in range(n):
	(p, q) = map(int, input().split())
	print(0 if p % q == 0 else q - p % q)


n = int(input())
output = []
for i in range(n):
	numbers = list(map(int, input().split(' ')))
	if numbers[0] % numbers[1] == 0:
		output.append(0)
	else:
		output.append(numbers[1] - numbers[0] % numbers[1])
for i in output:
	print(i)


def sum_of(x):
	cnt = 0
	while x:
		cnt += x % 10
		x //= 10
	return cnt
from collections import Counter
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	if sum_of(n) <= s:
		print(0)
	else:
		dd = sum_of(n)
		cnt = 0
		ans = 0
		n = list(str(n))[::-1]
		carry = 0
		for i in n:
			if int(i) + carry == 0:
				cnt += 1
				continue
			else:
				ans += (10 - (int(i) + carry)) * 10 ** cnt
				dd -= int(i) + carry
				dd += 1
				carry = 1
				cnt += 1
			if dd <= s:
				break
		print(ans)


p1 = int(input())
for p in range(p1):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	d = b
	i = 0
	e = None
	c = 0
	len_a = len(str(a))
	while i < len_a:
		d -= int(str(a)[i])
		if d <= 0 and e is None:
			e = i
		if d < 0:
			c = len_a - e
			c = 10 ** c
			c = c - int(str(a)[e:])
			break
		else:
			i += 1
	print(c)


test = int(input())
ar = []
br = []
for i in range(test):
	(a, b) = list(map(int, input().strip().split()))
	ar.append(a)
	br.append(b)
for i in range(test):
	if ar[i] % br[i] == 0:
		print(0)
	else:
		print(br[i] * (ar[i] // br[i] + 1) - ar[i])


import sys
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	N = n
	nn = n
	Sum = 0
	while N > 0:
		Sum += N % 10
		N //= 10
	N = n
	c = 1
	ans = 0
	while Sum > s and n > 9:
		ans += (10 - n % 10) * c
		c *= 10
		n //= 10
		n += 1
		N = n
		Sum = 0
		while N > 0:
			Sum += N % 10
			N //= 10
	n = nn
	if Sum > s:
		ans = 1
		while n > 0:
			ans *= 10
			n //= 10
		ans = ans - nn
	print(ans)


import sys
sysinput = sys.stdin.readline
import time
start_time = time.time()

def inp():
	return int(sysinput())

def inlt():
	return list(map(int, sysinput().split()))

def insr():
	s = sysinput()
	return list(s[:len(s) - 1])

def invr():
	return map(int, sysinput().split())
t = inp()
while t > 0:
	t -= 1
	(n, s) = inlt()
	k = n
	number = []
	order = 0
	suma = 0
	while True:
		suma += k - 10 * (k // 10)
		number.append(k - 10 * (k // 10))
		order += 1
		if k // 10 == 0:
			break
		k = k // 10
	number.append(0)
	inc = 0
	for i in range(order):
		if suma > s and number[i] != 0:
			inc += (10 - number[i]) * 10 ** i
			number[i] = 0
			j = i + 1
			while True:
				if j >= order:
					break
				if number[j] + 1 == 10:
					number[j] = 0
					j += 1
				else:
					number[j] += 1
					break
		elif suma <= s:
			break
		suma = sum(number)
	print(inc)


def ab():
	(a, b) = map(int, input().split())
	t = a % b
	if t == 0:
		print(0)
		return
	print(b - t)
for i in range(0, int(input())):
	ab()


s = int(input())

def fun(a, b):
	if a % b == 0:
		return a
	else:
		return b * (a // b + 1)
ans = [0] * s
for i in range(s):
	string = input()
	f = string.split(' ')
	ans[i] = fun(int(f[0]), int(f[1])) - int(f[0])
for i in range(s):
	print(ans[i])


def inc(a, b):
	i = 0
	if a > b:
		if a % b != 0:
			r = a // b + 1
			i = b * r - a
			return i
		else:
			return i
	else:
		i = b - a
		return i
n = int(input())
for i in range(n):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	print(inc(a, b))


def input_int():
	return int(input())

def input_int_list():
	return list(map(int, input().split()))

def input_input_map():
	return map(int, input().split())

def run():
	q_num = input_int()
	for i in range(q_num):
		(base_num, target_sum) = input_input_map()
		base_num_sum = 0
		for num in str(base_num):
			base_num_sum += int(num)
		if base_num_sum <= target_sum:
			print(0)
			continue
		base_num_str = str(base_num)
		num_len = len(base_num_str)
		sum_from_top = 0
		from_top_i = 0
		for i_from_top in range(num_len):
			sum_from_top += int(base_num_str[i_from_top])
			if sum_from_top >= target_sum:
				from_top_i = i_from_top
				break
		a = 10 ** (num_len - from_top_i)
		b = int(base_num_str[from_top_i:])
		result = a - b
		print(result)
run()


def sum_digit_func(x):
	sum_digit = 0
	while x != 0:
		sum_digit += x % 10
		x = x // 10
	return sum_digit

def count_digit_less_func(x, s):
	sum_digit = 0
	x = str(x)
	count_digit = len(x)
	while sum_digit < s:
		sum_digit += int(x[0])
		x = x[1:]
		count_digit -= 1
	return count_digit + 1

def task_D():
	t = int(input())
	for _ in range(t):
		(n, s) = map(int, input().split())
		sum_digit = sum_digit_func(n)
		if sum_digit <= s:
			print(0)
		else:
			count_digit = count_digit_less_func(n, s)
			print(10 ** count_digit - n % 10 ** count_digit)

def main():
	task_D()
main()


import sys
sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline

def solve():
	t = int(rl())
	ans = []
	for _ in range(t):
		(a, b) = map(int, rl().split())
		ans.append(b - a % b if a % b != 0 else 0)
	print(*ans, sep='\n')
solve()


t = int(input())
for j in range(t):
	(a, b) = map(int, input().split())
	res = b - a % b
	if res != b:
		print(res)
	else:
		print(0)


T = int(input())
for k in range(T):
	(n, s) = map(int, input().split())
	a = [0] + [int(i) for i in str(n)]
	ds = sum(a)
	cost = 0
	idx = len(a) - 1
	radix = 1
	while ds > s:
		if a[idx] > 0:
			cost += (10 - a[idx]) * radix
			ds -= a[idx]
			a[idx] = 0
			ds += 1
			a[idx - 1] += 1
			i = idx - 1
			while a[i] >= 10:
				a[i - 1] += 1
				a[i] -= 10
				ds -= 9
				i -= 1
		radix *= 10
		idx -= 1
	print(cost)


n = int(input())
for i in range(n):
	(a1, a2) = input().split()
	b = int(a1)
	a2 = int(a2)
	a1 = int(a1)
	if a1 < a2:
		print(a2 - a1)
	elif a1 % a2 == 0:
		print(0)
	else:
		print(a2 - a1 % a2)


t = input()
t = int(t)

def solve(n, s):

	def digit_sum(n):
		rev_n = str(n)
		a = 0
		for x in rev_n:
			a += int(x)
		return a
	current_sum = digit_sum(str(n))
	if current_sum <= s:
		print(0)
		return
	rev_n = str(n)[::-1]
	limit = len(rev_n)
	for i in range(limit):
		tmp_current_sum = current_sum
		if rev_n[i] != '0':
			ans = 10 ** (i + 1) - n % 10 ** (i + 1)
			tmp_current_sum -= digit_sum(n % 10 ** (i + 1))
			if i + 1 < limit and rev_n[i + 1] == '9':
				tmp_current_sum -= 9
			tmp_current_sum += 1
			if tmp_current_sum <= s:
				current_sum = tmp_current_sum
				break
	if current_sum > s:
		ans = 10 ** limit - n % 10 ** limit
	print(ans)
for i in range(t):
	(n, s) = map(int, input().split())
	solve(n, s)


T = int(input())
for _ in range(0, T):
	(a, b) = map(int, input().split())
	print((b - a % b) % b)


t = int(input())

def inc(x):
	pos = 0
	for i in range(len(x)):
		if x[i] != 0:
			pos = i
	while x[pos] == 9:
		x[pos] = 0
		pos -= 1
		if pos < 0:
			break
	if pos < 0:
		return [1] + x
	else:
		x[pos] += 1
		return x
for i in range(t):
	(n, s) = map(int, input().split())
	arr = list(map(int, list(str(n))))
	while sum(arr) > s:
		arr = inc(arr)
	print(int(''.join(map(str, arr))) - n)


t = int(input())
while t:
	s = input()
	l = list(map(int, s.split()))
	(n, k) = (l[0], l[1])
	a = n % k
	if a == 0:
		print('0')
	else:
		b = k - a
		print(b)
	t -= 1


import collections

def solve(a, b):
	if a % b == 0:
		return 0
	elif a <= b:
		return b - a
	else:
		return b - a % b
n = int(input().strip())
for i in range(n):
	[a, b] = list(map(int, input().strip().split()))
	print(solve(a, b))


import sys, collections
tc = int(sys.stdin.readline())
for _ in range(tc):
	(n, s) = map(int, sys.stdin.readline().split())
	ans = []
	self = 0
	for i in range(len(str(n))):
		self += int(str(n)[i])
	if self <= s:
		ans.append(n)
	ans.append(int('1' + '0' * len(str(n))))
	for i in range(len(str(n))):
		if i == 0:
			temp = str(int(str(n)[i]) + 1) + '0' * (len(str(n)) - 1)
			cnt = 0
			for i in temp:
				cnt += int(i)
			if cnt <= s:
				ans.append(int(temp))
		else:
			temp = int(str(n)[:i + 1])
			temp += 1
			temp = str(temp)
			for j in range(i + 1, len(str(n))):
				temp += '0'
			cnt = 0
			for i in temp:
				cnt += int(i)
			if cnt <= s:
				ans.append(int(temp))
	res = []
	for i in ans:
		res.append(i - n)
	res.sort()
	print(res[0])


n = int(input())
for i in range(n):
	inp = input().split()
	inp[0] = int(inp[0])
	inp[1] = int(inp[1])
	ans = inp[0] // inp[1]
	if inp[0] % inp[1] != 0:
		ans += 1
	print(ans * inp[1] - inp[0])


res = []
num = int(input())
for i in range(0, num):
	string = input()
	ls = string.split()
	a = int(ls[0])
	b = int(ls[1])
	if a % b == 0:
		res.append(0)
	else:
		n = a % b
		res.append(b - n)
for i in res:
	print(i)


t = int(input())
for _ in range(t):
	args = [int(x) for x in input().split(' ')]
	m = args[0] % args[1]
	if m == 0:
		print('0')
	else:
		print(str(args[1] - m))


from sys import stdin
import math
size = input()
for l in stdin.readlines():
	(a, b) = map(int, l.split())
	if a < b:
		print(b - a)
	elif a % b == 0:
		print(0)
	else:
		print(b * math.ceil(a / b) - a)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	ans = 0
	x = n
	l = 0
	while x:
		x = x // 10
		l += 1
	a = [0] * (l + 1)
	j = l
	x = n
	while x:
		a[j] = x % 10
		x = x // 10
		ans += a[j]
		j -= 1
	res = 0
	for i in range(l, 0, -1):
		if ans > s:
			res = res + (10 - a[i]) * pow(10, l - i)
			j = i - 1
			ans = ans - a[i]
			while j > 0 and a[j] == 9:
				a[j] = 0
				j -= 1
				ans -= 9
			a[j] += 1
			ans += 1
		else:
			break
	print(res)


from math import *
from bisect import *
from collections import *
from decimal import *

def inp():
	return int(input())

def st():
	return input().rstrip('\n')

def lis():
	return list(map(int, input().split()))

def ma():
	return map(int, input().split())
t = inp()
while t:
	t -= 1
	(n, s) = ma()
	x = str(n)
	s1 = 0
	for i in x:
		s1 += int(i)
	if s >= s1:
		print(0)
		continue
	pre = 0
	po = 0
	for i in x:
		po += 1
		pre += int(i)
		if pre < s:
			continue
		if pre == int(x[0]):
			ref = '1' + '0' * len(x)
			ref = int(ref)
			print(ref - n)
			break
		else:
			pre = x[:po - 2]
			if x[po - 2] != '9':
				pre += str(int(x[po - 2]) + 1)
			else:
				pre1 = 0
				po -= 2
				while po >= 0:
					if x[po] == '9':
						pre1 += 1
						po -= 1
						continue
					break
				if po == -1:
					ref = '1' + '0' * len(x)
					ref = int(ref)
					print(ref - n)
					break
				else:
					pre = x[:po] + str(int(x[po]) + 1)
					pre += '0' * pre1
			for j in range(len(x) - len(pre)):
				pre += '0'
			pre = int(pre)
			print(pre - n)
			break


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
		continue
	else:
		quo = a // b
		res = (quo + 1) * b
		ans = res - a
		print(ans)


ncases = int(input())
for i in range(ncases):
	a = input().split(' ')
	move = 0
	n1 = int(a[0])
	n2 = int(a[1])
	if n1 > n2:
		if n1 % n2 == 0:
			print(0)
		else:
			r = n1 % n2
			q = int(n1 / n2)
			move = (q + 1) * n2 - n1
			print(move)
	else:
		print(n2 - n1)


ans = []
for _ in range(int(input())):
	(N, M) = map(int, input().split())
	if N % M == 0:
		i = 0
	elif N <= M:
		i = M - N
	else:
		i = M - N % M
	ans.append(i)
for i in ans:
	print(i)


count = int(input())
for i in range(count):
	number = input().split(' ')
	a = int(number[0])
	b = int(number[1])
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


def is_div(a, b):
	if a % b == 0:
		return 0
	else:
		return b - a % b
test_cases = [list(map(int, input().split())) for _ in range(int(input()))]
for t in test_cases:
	print(is_div(t[0], t[1]))


for _ in range(int(input())):
	(n, s) = input().split()
	s = int(s)
	c = 0
	for i in n:
		c += int(i)
	if c <= s:
		print(0)
	else:
		for j in reversed(range(len(n))):
			c -= int(n[j])
			if c + 1 <= s:
				break
		m = 10 ** (len(n) - j)
		x = int(n[j:])
		print(m - x)


n = int(input())
for _ in range(n):
	(a, b) = [int(_) for _ in input().split()]
	if a % b == 0:
		print(0)
		continue
	c = b * (a // b + 1) - a
	print(c)


t = int(input())
output = []
for i in range(0, t):
	(a, b) = list(map(int, input().split()))
	if a < b:
		output.append(str(b - a))
	elif a % b == 0:
		output.append('0')
	else:
		output.append(str(b - a % b))
for i in output:
	print(i)


import sys
import math
t = int(sys.stdin.readline())
for x in range(t):
	[a, b] = [int(i) for i in sys.stdin.readline().split()]
	if a % b == 0:
		print(0)
	elif a > b:
		print(math.ceil(a / b) * b - a)
	else:
		print(b - a)


def find_moves(a, b):
	return b - a % b
cases = int(input())
for i in range(cases):
	numbers = input().split()
	if int(numbers[0]) % int(numbers[1]) == 0:
		print(0)
	else:
		print(find_moves(int(numbers[0]), int(numbers[1])))


for i in range(int(input())):
	(a, b) = map(int, input().split())
	if b > a:
		print(b - a)
	elif b == a or a % b == 0:
		print(0)
	else:
		y = a % b
		print(b - y)


t = int(input())
for case in range(t):
	(p, q) = input().split(' ')
	p = int(p)
	q = int(q)
	r = q - p % q
	if r == q:
		r = 0
	print(r)


import math
t = int(input())
for _ in range(t):
	(n, s) = input().split()
	sdsum = int(s)
	ndsum = sum(map(int, list(n)))
	if ndsum <= sdsum:
		print(0)
		continue
	diff = ndsum - sdsum
	c = 0
	for i in range(len(n) - 1, -1, -1):
		c += int(n[i])
		if ndsum - c + 1 <= sdsum:
			p = 10 ** (len(n) - i)
			if p > int(n):
				print(p - int(n))
				break
			print((int(n) // p + 1) * p - int(n))
			break


def process(n, s):
	n = '0' + n
	n1 = list(n)
	n = list(n)
	t = 0
	while sum([int(i) for i in n]) > s:
		t = 0
		for i in range(1, len(n)):
			t += int(n[i])
			if t <= s:
				continue
			else:
				n2 = '0' + str(int(''.join(n[:i - 0])) + 1)
				for i1 in range(i, len(n)):
					n2 += '0'
				n = list(n2)
				break
	return int(''.join(n)) - int(''.join(n1))

def brute(n, s):
	n = '0' + n
	ans = 0
	while sum([int(i) for i in n]) > s:
		n = str(int(n) + 1)
		ans += 1
	return ans
import random
tests = int(input())
for i in range(tests):
	(n, s) = input().split()
	s = int(s)
	t1 = process(n, s)
	print(t1)


t = int(input())
while t > 0:
	l = input().split()
	a = int(l[0])
	b = int(l[1])
	p = a % b
	if p == 0:
		print(p)
	else:
		print(b - p)
	t -= 1


from math import ceil
t = int(input())
while t:
	t -= 1
	(a, b) = list(map(int, input().split()))
	c = ceil(a / b)
	if b * c == a:
		print(0)
	else:
		print(c * b - a)


from sys import stdin, stdout
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	n = a % b
	if n == 0:
		print(0)
	else:
		print(b - n)


t = int(input())
for _ in range(t):
	(n, s) = map(int, input().split())
	dig = [int(c) for c in str(n)]
	if sum(dig) <= s:
		print(0)
		continue
	cntup = 10
	x = 0
	for i in range(len(dig) - 1, -1, -1):
		dig[i] = 0
		x = int(''.join([str(x) for x in dig])) + cntup
		cntup *= 10
		if sum([int(c) for c in str(x)]) <= s:
			break
	print(x - n)


import sys

def get_sum(a):
	now_sum = 0
	while a:
		now_sum += a % 10
		a //= 10
	return now_sum
T = int(sys.stdin.readline())
for _ in range(T):
	(n, x) = map(int, sys.stdin.readline().split())
	res_n = n
	digit = 0
	while get_sum(res_n) > x:
		res_n += (10 - res_n // 10 ** digit % 10) * 10 ** digit
		digit += 1
	print(res_n - n)


def comp(lis, i, s):
	ans = ''
	carry = 0
	k = len(lis) - 1
	while k >= i and lis[k] == 0:
		ans = '0' + ans
		k -= 1
	if k < i:
		return int(2e+18)
	ans = str(10 - lis[k]) + ans
	lis[k] = 0
	for j in range(k - 1, i - 1, -1):
		ans = str(9 - lis[j]) + ans
		lis[j] = 0
	ans = int(ans)
	(lis[i - 1], carry) = ((lis[i - 1] + 1) % 10, (lis[i - 1] + 1) // 10)
	for j in range(i - 2, -1, -1):
		(lis[j], carry1) = ((lis[j] + carry) % 10, (lis[j] + carry) // 10)
		carry = carry1
	if sum(lis) <= s:
		return ans
	else:
		return int(2e+18)
for vishal in range(int(input())):
	(n, s) = list(map(int, input().split()))
	(su, nn) = (0, n)
	lis = []
	while nn:
		su += nn % 10
		lis.append(nn % 10)
		nn //= 10
	lis.append(0)
	lis.append(0)
	lis.reverse()
	if su <= s:
		print('0')
		continue
	ans = int(2e+18)
	for i in range(len(lis) - 1, 0, -1):
		ans = min(ans, comp(lis[:], i, s))
	print(ans)


import sys
input = sys.stdin.read()
data = list(map(int, input.split()))
T = int(data[0])
it = 1
while T > 0:
	a = data[it]
	b = data[it + 1]
	if a % b == 0:
		print(0)
	else:
		next_num = b * (a // b + 1)
		print(next_num - a)
	it += 2
	T -= 1


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	sol1 = a % b
	if sol1 != 0:
		sol2 = b - sol1
	else:
		sol2 = 0
	print(sol2)


from sys import stdin, stdout

def fn(s, n):
	p = 0
	for i in range(n - 1, -1, -1):
		if s[i] != '0':
			p = i
			break
	if p == 0:
		return '1' + '0' * n
	num = int(s[:p]) + 1
	return str(num) + '0' * (n - p)

def SOD(s):
	return sum([int(v) for v in s])
n = 0
for _ in range(int(stdin.readline())):
	(s, sm) = list(map(int, stdin.readline().split()))
	s = str(s)
	ori_s = s
	n = len(s)
	sod = SOD(s)
	ns = s
	while sod > sm:
		ns = fn(ns, n)
		sod = SOD(ns)
	print(int(ns) - int(ori_s))


for _ in range(int(input())):
	(l, r) = map(int, input().split())
	if l % r == 0:
		print(0)
	else:
		a = l % r
		print(r - a)


f = int(input())
while f:
	(a, b) = input().split(' ')
	if int(a) % int(b):
		print(int(b) - int(a) % int(b))
	else:
		print(0)
	f -= 1


def main():
	num = int(input())
	for i in range(0, num):
		(a, b) = map(int, input().split())
		div(a, b)
	return

def div(n1, n2):
	if n1 % n2 == 0:
		print('0')
		return 0
	numb = int(n1 // n2)
	print(n2 * (numb + 1) - n1)
	return 0
main()


for _ in range(int(input())):
	(n, s) = input().split()
	s = int(s)
	t1 = sum([int(i) for i in n])
	if t1 <= s:
		print(0)
	else:
		(t, k, m) = ('', 0, len(n))
		for i in range(m):
			k += int(n[i])
			if k >= s:
				for j in range(i, m):
					t += str(10 - int(n[j]) - 1)
				break
		print(int(t) + 1)


n = int(input())
for i in range(n):
	(m, d) = map(int, input().split())
	a = m % d
	if a:
		print(d - a)
	else:
		print(0)


def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def func():
	t = ii()
	for _ in range(t):
		(n, m) = mi()
		if n >= m:
			print(m - n % m if n % m else 0)
		else:
			print(m - n)
func()


t = int(input())
for k in range(t):
	(n, s) = map(int, input().split())
	sN = str(n)
	sum = 0
	total = 0
	i = 0
	while i < len(sN):
		sum += int(sN[i])
		i += 1
	if sum <= s:
		total = 0
	else:
		sum = 1
		i = -1
		while sum <= s:
			i += 1
			sum += int(sN[i])
		total = pow(10, len(sN) - i) - int(sN[i:])
	print(total)


t = int(input())
for _ in range(t):
	(a, b) = input().split(' ')
	a = int(a)
	b = int(b)
	if a % b == 0:
		print(0)
	else:
		x_mod = a % b
		if x_mod != 0:
			a += b - x_mod
		print(b - x_mod)


test_cases = int(input())
for _ in range(test_cases):
	(a, b) = map(int, input().strip().split())
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


from math import ceil, log
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	i = a
	print(b * ceil(a / b) - a)


def find_min_number_of_moves(a, b):
	if a % b == 0:
		return 0
	else:
		return b - a % b
t = int(input())
for i in range(t):
	(num1, num2) = map(int, input().split())
	print(find_min_number_of_moves(num1, num2))


n = int(input())
for i in range(n):
	l = 0
	(a, b) = map(int, input().split())
	l = a % b
	if l == 0 and a < b:
		l = b - a
	elif l != 0:
		l = b - a % b
	print(l)


a = int(input())
for a in range(a):
	(b, c) = map(int, input().split())
	print((c - b % c) % c)


DEBUG = False
if DEBUG:
	import sys
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def solve():
	(a, b) = map(int, input().split())
	if a % b == 0:
		return 0
	tmp = a // b + 1
	return b * tmp - a
t = int(input())
for _ in range(t):
	print(solve())


t = int(input())
for q in range(t):
	(a, b) = [int(i) for i in input().split()]
	g = a // b
	if a % b:
		g += 1
	print(g * b - a)


import math
i = int(input())
for n in range(0, i):
	x = input().split(' ')
	count = 0
	for y in range(0, len(x)):
		x[y] = int(x[y])
	if x[1] >= x[0]:
		count = count + (x[1] - x[0])
	else:
		a = math.ceil(x[0] / x[1])
		count = count + (x[1] * a - x[0])
	print(count)


num = int(input())
for i in range(0, num):
	inp = list(map(int, input().split()))
	a = inp[0]
	b = inp[1]
	k = 0
	c = 1
	if a < b:
		print(b - a)
	else:
		k = a % b
		if k == 0:
			print(k)
		else:
			k = b - k
			print(k)


def divisible(a, b):
	if a % b != 0:
		return b - a % b
	return 0
a = int(input())
for i in range(a):
	z = input()
	z = z.split()
	w = []
	for i in z:
		w.append(int(i))
	ans = divisible(w[0], w[1])
	print(ans)


n = int(input())

def check(n, s):
	suma = 0
	for i in range(len(n)):
		suma += int(n[i])
	return True if suma <= s else False
for i in range(n):
	(n, s) = map(int, input().split())
	n = str(n)
	ans = '0'
	suma = 0
	curlen = len(n)
	if not check(n, s):
		for i1 in range(len(n)):
			if int(n[i1]) + suma < s:
				suma += int(n[i1])
				ans += n[i1]
				curlen -= 1
			else:
				start = 0
				for i2 in range(len(ans) - 1, -1, -1):
					if ans[i2] != '9':
						start = i2
						break
					else:
						curlen += 1
				ans = ans[:start] + str(int(ans[start]) + 1) + '0' * curlen
				break
		print(int(ans) - int(n))
	else:
		print(0)


def check(n, s):
	sm = 0
	while n > 0:
		sm += n % 10
		n = n // 10
	return sm <= s
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	if check(n, s):
		print(0)
	else:
		steps = 0
		while not check(n, s):
			nm = str(n)
			i = len(nm) - 1
			while i >= 0:
				if nm[i] != '0':
					break
				i -= 1
			sk = len(nm) - i
			temp = 10 - int(nm[i])
			n += temp * 10 ** (sk - 1)
			steps += temp * 10 ** (sk - 1)
		print(steps)


T = int(input())
for _ in range(T):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if a % b == 0:
		print(0)
	else:
		v = a // b
		val = b * (v + 1)
		res = val - a
		print(res)


def sum_digits(n):
	s = 0
	while n:
		s += n % 10
		n //= 10
	return s
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	d = sum_digits(n)
	ans = 0
	if d <= s:
		print('0')
		continue
	pw = 1
	for i in range(18):
		d = n // pw % 10
		inc = pw * ((10 - d) % 10)
		n += inc
		ans += inc
		if sum_digits(n) <= s:
			break
		pw *= 10
	print(ans)


import math

def dp(a, b):
	if a <= b:
		return b - a
	if a % b == 0:
		return 0
	fl = math.ceil(a / b)
	return fl * b - a
ts = int(input())
for t in range(ts):
	(a, b) = list(map(int, input().split()))
	print(dp(a, b))


def summ(n):
	s = 0
	x = n
	while x:
		s += x % 10
		x //= 10
	return s
import math
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	if summ(n) <= s:
		print(0)
	else:
		t = 10
		x = n
		while summ(n) > s:
			n = n - n % t
			n += t
			t *= 10
		print(n - x)


t = int(input())

def solve():
	(a, b) = map(int, input().split())
	steps = 0
	r = a % b
	if r == 0:
		print(0)
	else:
		print(b - r)
while t > 0:
	solve()
	t -= 1


TC = int(input())
for tc in range(TC):
	(N, S) = map(int, input().split())
	digits = []
	x = N
	while x > 0:
		digits.append(x % 10)
		x //= 10
	digits.append(0)
	C = sum(digits)
	if C <= S:
		print(0)
		continue
	result = 0
	for i in range(len(digits) - 1):
		d = digits[i]
		if d == 0:
			continue
		C -= d - 1
		result += (10 - d) * 10 ** i
		digits[i + 1] += 1
		if C <= S:
			break
	print(result)


import math
n = int(input())
sets = []
output = []
for i in range(n):
	sets.append(list(map(int, input().split())))
for sett in sets:
	output.append(sett[1] * math.ceil(sett[0] / sett[1]) - sett[0])
for out in output:
	print(out)


from math import ceil
qtd = int(input())
for _ in range(qtd):
	(a, b) = map(int, input().split())
	r = b * ceil(a / b) - a
	print(r)


t = int(input())
for i in range(t):
	(a, b) = [int(x) for x in input().split()]
	print((b - a % b) % b)


import math
t = int(input())

def summa(arr):
	e = 0
	for i in range(len(arr)):
		e += int(arr[i])
	return e

def number(arr):
	e = 0
	for i in range(len(arr)):
		e *= 10
		e += int(arr[i])
	return e
for _ in range(t):
	(n, s) = map(str, input().split())
	answer = 0
	s = int(s)
	f = list(n)
	f.insert(0, '0')
	digit = len(f) - 1
	while summa(f) > s:
		answer += (10 - int(f[digit])) * 10 ** (len(f) - 1 - digit)
		f[digit] = '0'
		f[digit - 1] = str(int(f[digit - 1]) + 1)
		digit -= 1
		while f[digit] == '10':
			f[digit] = '0'
			f[digit - 1] = str(int(f[digit - 1]) + 1)
			digit -= 1
	print(answer)


from sys import stdin, stdout
input = stdin.buffer.readline

def rec(a, i, c):
	res = 10 ** 20
	if c < 0:
		return res
	if i >= len(a):
		return int(a)
	if a[i] != '9' and c - int(a[i]) - 1 >= 0:
		res = int(a[:i] + str(int(a[i]) + 1) + '0' * len(a[i + 1:]))
	return min(res, rec(a, i + 1, c - int(a[i])))
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	x = rec(str(n), 0, s)
	if x == 10 ** 20:
		print(10 ** len(str(n)) - n)
	else:
		print(x - n)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	n = str(n)
	l = 10
	ct = 0
	i = -1
	while sum(map(int, list(n))) > s:
		k = l - int(n[i:])
		if k != 0:
			ct += k
			n = str(int(n) + k)
			l *= 10
		i -= 1
	print(ct)


def divisibility(list1):
	a = list1[0]
	b = list1[1]
	if a < b:
		print(b - a)
	elif a > b and a % b == 0:
		print(0)
	elif a > b:
		print(b - a % b)
	elif a == b:
		print(0)
t = int(input())
for i in range(t):
	list1 = list(map(int, input().rstrip().split()))
	divisibility(list1)


t = int(input())

def int_to_arr(n, s):
	arr = []
	n_copy = n
	while n_copy > 0:
		arr.append(n_copy % 10)
		n_copy = n_copy // 10
	return trying(arr, n, s)

def trying(arr, n, s):
	summa = 0
	for i in range(len(arr) - 1, -1, -1):
		summa += arr[i]
		if summa > s:
			need = 10 ** (i + 1) - n % 10 ** (i + 1)
			to_add[0] += need
			n += need
			int_to_arr(n, s)
			return
	print(to_add[0])
for _ in range(t):
	to_add = [0]
	(n, s) = map(int, input().split())
	int_to_arr(n, s)


def aux(n, s):
	if sum((int(x) for x in str(n))) <= s:
		return 0
	a = 10
	while n % a == 0:
		a *= 10
	d = a - n % a
	return d + aux(n + d, s)
for t in range(int(input())):
	(n, s) = map(int, input().split())
	print(aux(n, s))


for t in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		q = a // b + 1
		n = q * b
		print(n - a)


for _ in range(int(input())):
	(s, n) = input().split()
	n = int(n)
	s = '0' + s
	sm = 0
	for i in range(len(s)):
		sm += int(s[i])
	if sm <= n:
		print(0)
		continue
	acm = 0
	i = 0
	prev = 0
	while i < len(s):
		acm += int(s[i])
		if s[i] != '0':
			prev = i
		if acm >= n:
			break
		i += 1
	print((int(s[:prev]) + 1) * 10 ** (len(s) - prev) - int(s))


for t in range(int(input())):
	(a, b) = list(map(int, input().split()))
	mod = a % b
	print(b - mod if bool(mod) else mod)


for tc in range(int(input())):
	(a, b) = map(int, input().split())
	print((b - a % b) % b)


for _ in range(int(input())):
	(a, b) = [int(i) for i in input().split()]
	if a < b:
		ans = b - a
	else:
		ans = (b - a % b) % b
	print(ans)


def get_result(a, b):
	print((b - a % b) % b)
t = int(input())
for i in range(t):
	(a, b) = input().split()
	(a, b) = (int(a), int(b))
	get_result(a, b)


def checkSum(num, s):
	temp = str(num)
	c = 0
	for i in temp:
		c += int(i)
	if c <= s:
		return True
	return False

def solve(num, s):
	temp = num
	c = 0
	while num != 0:
		num = num // 10
		c += 1
		num += 1
		if checkSum(num, s):
			break
	num = num * 10 ** c
	val = num - temp
	return val
for _ in range(int(input())):
	(num, s) = list(map(int, input().split()))
	if checkSum(num, s):
		print(0)
	else:
		print(solve(num, s))


ans = []
n = int(input())

def check(a, b):
	if a % b == 0:
		return 0
	else:
		return b - a % b
for i in range(n):
	s = [int(i) for i in input().split(' ')]
	ans.append(check(s[0], s[1]))
for i in ans:
	print(i)


N = int(input())
for i in range(N):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		div = 1 + a // b
		inc = div * b - a
		print(inc)


def getInts():
	return list(map(int, input().split()))
[T] = getInts()
for case in range(T):
	[a, b] = getInts()
	if a % b == 0:
		print(0)
		continue
	if a < b:
		print(b - a)
	else:
		print(b - a % b)


for i in range(int(input())):
	(a1, a2) = map(int, input().split())
	if a1 % a2 == 0:
		print(0)
	else:
		tempmin = a1 // a2 + 1
		ans = a2 * tempmin - a1
		print(ans)


def digits_sum(num):
	s = 0
	while num != 0:
		s = s + num % 10
		num = num // 10
	return s
a = int(input())
i = 0
while i < a:
	inputs = input().split(' ')
	num = int(inputs[0])
	num2 = int(inputs[1])
	temp = num
	iterator = 0
	while iterator < 19:
		temp2 = (10 ** iterator - num % 10 ** iterator) % 10 ** iterator
		num = num + temp2
		if digits_sum(num) <= num2:
			print(num - temp)
			break
		iterator = iterator + 1
	i = i + 1


num = int(input())
while num:
	lst = list(map(int, input().rstrip().split()))
	a = lst[0]
	b = lst[1]
	x = a % b
	if x != 0:
		y = b - x
		print(y)
	else:
		print(x)
	num -= 1


tests = []
ans = 0

def sumofD(num) -> int:
	sum = 0
	while num > 0:
		last = num % 10
		sum += last
		num = num // 10
	return sum
for i in range(int(input())):
	tests.append([int(j) for j in input().split()])
for i in tests:
	n = i[0]
	s = i[1]
	if sumofD(n) <= s:
		print('0')
		continue
	p = 1
	for i in range(18):
		dig = n // p % 10
		add = p * ((10 - dig) % 10)
		n += add
		ans += add
		if sumofD(n) <= s:
			break
		p = p * 10
	print(ans)
	ans = 0


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, s) = input().rstrip().split()
	s = int(s)
	N = list(map(int, reversed(list(n)))) + [0]
	ans = 0
	S = sum(N)
	for i in range(len(str(n))):
		if S <= s:
			break
		if N[i] == 0:
			continue
		S -= N[i] - 1
		ans += (10 - N[i]) * pow(10, i)
		N[i] = 0
		N[i + 1] += 1
	print(ans)


tc = int(input().strip())
for t in range(tc):
	(a, b) = map(int, input().strip().split())
	if a % b == 0 and a >= b:
		print(0)
	else:
		print(b - a % b)


for _ in range(int(input())):
	li = list(map(int, input().split()))
	a = li[0]
	b = li[1]
	if a % b == 0:
		print(0)
	elif b > a:
		print(b - a)
	else:
		remainder = a % b
		ans = b - remainder
		print(ans)


for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	if a % b == 0:
		print(0)
	else:
		reminder = a % b
		steps = b - reminder
		print(steps)


import math
t = int(input())
while t:
	t -= 1
	(a, b) = list(map(int, input().split()))
	if a == b or a % b == 0:
		print(0)
	elif a < b:
		print(b - a)
	else:
		k = math.ceil(a / b)
		print(k * b - a)


def find(a, b):
	if a < b:
		return b - a
	if a >= b:
		q = a / b
		if q == int(q):
			return 0
		else:
			cq = int(q) + 1
			return b * cq - a
for i in range(int(input())):
	(a, b) = map(int, input().split())
	print(find(a, b))


n = int(input())
for _ in range(n):
	(a, b) = map(int, input().split())
	if a > b and a % b != 0:
		print(b - a % b)
	elif a > b and a % b == 0:
		print(0)
	else:
		print(b - a)


test = int(input())
while test:
	count = 0
	(a, b) = map(int, input().split())
	if a % b == 0:
		count = 0
	else:
		c = a // b
		count = a
		a = b * (c + 1)
		count = a - count
	print(count)
	test -= 1


for _ in range(int(input())):
	(a, b) = [int(i) for i in input().split()]
	print((b - a % b) * (a % b > 0))


n = int(input())
count = 0
l = []
while count < n:
	s = input()
	s = s.split(' ')
	l.append(s)
	count += 1
for x in l:
	move = 0
	if int(x[0]) % int(x[1]) != 0:
		a = int(x[0]) // int(x[1])
		target = (a + 1) * int(x[1])
		move += target - int(x[0])
		print(move)
	else:
		print(move)


def bfs(n, s):
	for i in range(0, 10 ** 18):
		var = n + i
		sum = 0
		for i in str(var):
			sum += int(i)
		if sum <= s:
			return var - n
t = int(input())
for _ in range(t):
	(n, s) = map(int, input().split())
	no = str(n)
	sum = 0
	for i in no:
		sum += int(i)
	if sum <= s:
		print(0)
		continue
	temp = no[::-1]
	for i in range(len(temp) - 1):
		if temp[i] == '0':
			continue
		new = temp[:i] + '0' + temp[i + 1:]
		for j in range(i + 1, len(new)):
			if new[j] != '9':
				pivot = j
				break
		else:
			pivot = len(new) - 1
		var = ''
		for j in range(len(new)):
			if j < pivot:
				var += '0'
			elif j == pivot:
				if len(str(int(new[j]) + 1)) == 1:
					var += str(int(new[j]) + 1)
				else:
					var += str(int(new[j]) + 1)[::-1]
			else:
				var += new[j]
		c = 0
		for j in var:
			c += int(j)
		if c <= s:
			print(-n + int(var[::-1]))
			break
		temp = var
	else:
		var = len(temp)
		print(-n + 10 ** var)


import math
L = lambda : list(map(int, input().split()))
M = lambda : map(int, input().split())
I = lambda : int(input())
t = I()
for i in range(t):
	(a, b) = M()
	x = math.ceil(a / b)
	print(b * x - a)


t = int(input())
while t > 0:
	t = t - 1
	(n, m) = map(int, input().split())
	if n % m == 0:
		print(0)
	else:
		p = int(n / m)
		p = p + 1
		m = p * m
		print(m - n)


(t, k, f) = (int(input()), 0, 0)
for _ in range(t):
	k = 0
	z = [int(s) for s in input().split()]
	(a, b) = (z[0], z[1])
	if b >= a:
		print(b - a)
	elif a % b == 0:
		print(0)
	else:
		f = a // b
		f = f + 1
		print(b * f - a)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split(' '))
	if a % b == 0:
		print(0)
		continue
	if a > b:
		num = a
		num = num // b + 1
		print(b * num - a)
	else:
		print(b - a)


from math import ceil
n = int(input())
for x in range(n):
	(a, b) = map(int, input().split())
	if b > a:
		print(b - a)
	elif a % b == 0:
		print(0)
	elif a % b != 0:
		print(ceil(a / b) * b - a)


t = int(input())
ans = []
for _ in range(t):
	(a, b) = map(int, input().split())
	if not a % b:
		ans.append(0)
	elif a < b:
		ans.append(b - a)
	else:
		ans.append(a + b - a % b - a)
print(*ans, end='')


test_cases = int(input())
for i in range(test_cases):
	(a, b) = map(int, input().split())
	if a < b:
		print(b - a)
	elif a % b == 0:
		print(0)
	else:
		p = a // b + 1
		print(p * b - a)


import math
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split(' '))
	s = math.ceil(a / b)
	print(str(s * b - a))


for i in range(int(input())):
	(n, m) = list(map(int, input().split()))
	ch = n % m
	if ch == 0:
		ch = m
	print(m - ch)


for _ in range(int(input())):
	(n, s) = input().split()
	s = int(s)
	length = n.__len__()
	summa = 0
	for i in range(length):
		summa += int(n[i])
	if summa <= s:
		print(0)
		continue
	summa = 0
	cnt = 0
	elem = 0
	for i in range(length):
		if summa + int(n[i]) >= s:
			break
		summa += int(n[i])
		cnt += 1
		elem = int(n[i])
	start = str(elem)
	res = str(elem + 1)
	for i in range(cnt, length):
		start += n[i]
		res += '0'
	print(int(res) - int(start))


j = int(input())
ar = []
for i in range(0, j):
	y = input().split(' ')
	a = int(y[0])
	b = int(y[1])
	if a % b == 0:
		ar.append(0)
	else:
		if a < b:
			ar.append(b - a)
			continue
		tjk = int(a / b)
		tjk += 1
		ar.append(b * tjk - a)
for i in ar:
	print(i)


def getno(l):
	return int(''.join(list(map(str, l))))
for _ in range(int(input())):
	(n, s) = [int(x) for x in input().split()]
	cs = 0
	for i in str(n):
		cs += int(i)
	if cs <= s:
		print(0)
		continue
	cs -= s
	no = list(map(int, str(n)))
	for j in range(len(no) - 1, -1, -1):
		if no[j] == 0:
			continue
		if cs + 1 <= no[j]:
			no[j] = 0
			if j:
				ind = j - 1
				while ind >= 0 and no[ind] == 9:
					no[ind] = 0
					ind -= 1
				if ind >= 0:
					no[ind] += 1
				else:
					no.insert(0, 1)
			else:
				no.insert(0, 1)
			break
		else:
			cs -= no[j]
			no[j] = 0
	print(getno(no) - n)


for _ in range(int(input())):
	l = list(map(int, input().split()))
	a = l[0]
	b = l[1]
	k = 0
	if a % b == 0:
		k = 0
	if a < b and a % b != 0:
		k = b - a
	if a > b and a % b != 0:
		k = b - a % b
	print(k)


number = int(input())
data = list(map(int, input().split()))
for index in range(1, number, 1):
	current = list(map(int, input().split()))
	data.append(current[0])
	data.append(current[1])

def devide(number):
	array = []
	while number > 0:
		array.append(number % 10)
		number = (number - number % 10) // 10
	return array

def massiv(array):
	sum = 0
	for (pos, element) in enumerate(array):
		sum += 10 ** (len(array) - pos - 1) * element
	return sum

def partial(array):
	num = massiv(array)
	num = 10 ** len(array) - num
	return num

def check(array):
	sum = 0
	for (pos, element) in enumerate(array):
		sum += element
	return sum

def func(number1, number2):
	if number1 == number2:
		print(0)
	else:
		array = devide(number1)
		array.reverse()
		if check(array) > number2:
			counter = 0
			value = 0
			for (pos, element) in enumerate(array):
				if element < number2:
					number2 -= element
				elif counter == 0 and pos != 0:
					counter = 1
					array[pos - 1] = array[pos - 1] + 1
				elif pos == 0 and element >= number2:
					value = 1
					answer = partial(array)
				if counter == 1:
					array[pos] = 0
			if value == 0:
				answer = massiv(array)
				print(answer - number1)
			else:
				print(answer)
		else:
			print(0)
for element in range(0, len(data), 2):
	func(data[element], data[element + 1])


t = int(input())
while t:
	(n, s) = input().split()
	s = int(s)
	l = len(n)
	u = 0
	f = 0
	flag = 0
	index = 0
	for x in range(l):
		u += int(n[x])
		if u == s and flag != 1:
			flag = 1
			index = x
		if u > s:
			f = 1
			break
	if f:
		if flag:
			x = index
		print(abs(10 ** (l - x) - int(n[x:])))
	else:
		print(0)
	t -= 1


def f(n):
	ans = 0
	for i in n:
		ans += int(i)
	return ans
for i in range(int(input())):
	(n, s) = input().split(' ')
	s = int(s)
	if f(n) <= s:
		print(0)
	else:
		store = 0
		ind = 0
		while store + int(n[ind]) < s:
			store += int(n[ind])
			ind += 1
		a = ''
		for i in range(ind):
			a += n[i]
		if ind == 0:
			print(10 ** len(n) - int(n))
		else:
			a = int(a) + 1
			a = a * 10 ** (len(n) - ind)
			print(a - int(n))


t = int(input())
for i in range(t):
	inps = list(map(int, input().split()))
	a = inps[0]
	b = inps[1]
	if a % b != 0:
		ans = b - a % b
		print(ans)
	else:
		print(0)


def fun(a, b):
	if a % b == 0:
		print('0')
	else:
		rem = (a + b) % b
		if rem == 0:
			print(a)
		else:
			print(b - rem)
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	fun(a, b)


from math import factorial
from math import log, ceil
from collections import defaultdict
from math import *
from sys import stdin, stdout
import itertools
import os
import sys
import threading
from collections import deque, Counter, OrderedDict, defaultdict
from heapq import *
from fractions import Fraction
mod = int(pow(10, 9) + 7)

def ii():
	return int(input())

def si():
	return str(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def fii():
	return int(stdin.readline())

def fsi():
	return str(stdin.readline())

def fmi():
	return map(int, stdin.readline().split())

def fli():
	return list(fmi())
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)

def make_graph(e):
	d = {}
	for i in range(e):
		(x, y) = mi()
		if x not in d:
			d[x] = [y]
		else:
			d[x].append(y)
		if y not in d:
			d[y] = [x]
		else:
			d[y].append(x)
	return d

def gr2(n):
	d = defaultdict(list)
	for i in range(n):
		(x, y) = mi()
		d[x].append(y)
	return d

def connected_components(graph):
	seen = set()

	def dfs(v):
		vs = set([v])
		component = []
		while vs:
			v = vs.pop()
			seen.add(v)
			vs |= set(graph[v]) - seen
			component.append(v)
		return component
	ans = []
	for v in graph:
		if v not in seen:
			d = dfs(v)
			ans.append(d)
	return ans

def primeFactors(n):
	s = set()
	while n % 2 == 0:
		s.add(2)
		n = n // 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			s.add(i)
			n = n // i
	if n > 2:
		s.add(n)
	return s

def find_all(a_str, sub):
	start = 0
	while True:
		start = a_str.find(sub, start)
		if start == -1:
			return
		yield start
		start += len(sub)

def SieveOfEratosthenes(n, isPrime):
	isPrime[0] = isPrime[1] = False
	for i in range(2, n):
		isPrime[i] = True
	p = 2
	while p * p <= n:
		if isPrime[p] == True:
			i = p * p
			while i <= n:
				isPrime[i] = False
				i += p
		p += 1
	return isPrime

def dijkstra(edges, f, t):
	g = defaultdict(list)
	for (l, r, c) in edges:
		g[l].append((c, r))
	(q, seen, mins) = ([(0, f, ())], set(), {f: 0})
	while q:
		(cost, v1, path) = heappop(q)
		if v1 not in seen:
			seen.add(v1)
			path = (v1, path)
			if v1 == t:
				return (cost, path)
			for (c, v2) in g.get(v1, ()):
				if v2 in seen:
					continue
				prev = mins.get(v2, None)
				next = cost + c
				if prev is None or next < prev:
					mins[v2] = next
					heappush(q, (next, v2, path))
	return float('inf')

def binsearch(a, l, r, x):
	while l <= r:
		mid = l + (r - 1) // 2
		if a[mid]:
			return mid
		elif a[mid] > x:
			l = mid - 1
		else:
			r = mid + 1
	return -1
for _ in range(ii()):
	(a, b) = mi()
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	if s >= n:
		print(0)
		continue
	stringno = str(n)
	temp_sum = 0
	cnt = 0
	for q in stringno:
		temp_sum += int(q)
		if temp_sum >= s:
			break
		cnt += 1
	ord_sum = 0
	for q in stringno:
		ord_sum += int(q)
	if ord_sum <= s:
		print(0)
		continue
	elif ord_sum == temp_sum and temp_sum == s:
		print(0)
		continue
	if cnt == 0:
		temp = 10 ** len(stringno)
		print(temp - n)
	else:
		temp = int(stringno[cnt])
		temp = 10 - temp
		temp = int(stringno[:cnt + 1]) + temp
		temp = temp * 10 ** (len(stringno) - cnt - 1)
		print(temp - n)


te = int(input())
while te > 0:
	te -= 1
	(a, b) = list(map(int, input().split()))
	x = a % b
	if x == 0:
		print(x)
	else:
		print(b - x)


n = int(input())
count = 0
while n != 0:
	n -= 1
	(x, y) = map(int, input().split())
	if x % y == 0:
		print(count)
	else:
		s = x % y
		print(y - s)


t = int(input())
for t in range(t):
	(p, q) = map(int, input().split())
	if p % q == 0:
		print(0)
	else:
		print(q - p % q)


t = int(input())
for i in range(t):
	(n, s) = map(int, input().split())
	digits = [int(x) for x in str(n)]
	sum = 0
	for j in range(len(digits)):
		sum += digits[j]
	if sum <= s:
		print('0')
		continue
	elif digits[0] > s or digits[0] + 1 > s:
		ans = [0] * len(digits)
		ans.insert(0, 1)
		newans = ''.join([str(x) for x in ans])
		newans = int(newans)
		newdigits = ''.join([str(x) for x in digits])
		newdigits = int(newdigits)
		newans = newans - newdigits
	else:
		current = digits[0]
		put = 0
		for j in range(1, len(digits)):
			if digits[j] + 1 + current > s:
				put = j
				break
			else:
				current += digits[j]
		ans = [0] * (len(digits) - put)
		ans.insert(0, 1)
		newans = ''.join([str(x) for x in ans])
		newans = int(newans)
		newdigits = ''.join([str(digits[x]) for x in range(put, len(digits))])
		newdigits = int(newdigits)
		newans = newans - newdigits
	print(newans)


num_cases = int(input())
case_list = []
for i in range(num_cases):
	case = input()
	case_list.append(case)
for case in case_list:
	num_list = case.split()
	num1 = int(num_list[0])
	num2 = int(num_list[1])
	if num1 >= num2:
		if num1 % num2 != 0:
			remainder = num1 % num2
			print(num2 - remainder)
		else:
			print(0)
	else:
		print(num2 - num1)


t = int(input())
x = []
for i in range(t):
	(a, b) = input().split()
	(a, b) = (int(a), int(b))
	if a < b:
		x.append(str(b - a))
	elif a % b == 0:
		x.append('0')
	else:
		x.append(str((a // b + 1) * b - a))
print('\n'.join(x))


import sys
input = sys.stdin.readline
sm = lambda x: sum(map(int, str(x)))
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	res = 0
	while sm(n) > s:
		t = 0
		while n % pow(10, t) == 0:
			t += 1
		d = -n % pow(10, t)
		res += d
		n += d
	print(res)


from sys import stdin

def f(b, x):
	return b * x

def binarySearch(a, b):
	(lo, hi, mid) = (0, 10 ** 9 + 1, 0)
	while lo + 1 != hi:
		mid = lo + hi >> 1
		if f(b, mid) <= a:
			lo = mid
		else:
			hi = mid
	return hi

def solve(a, b):
	ans = None
	if a % b == 0:
		ans = 0
	elif b > a:
		ans = b - a
	else:
		x = binarySearch(a, b)
		ans = abs(b * x - a)
	return ans

def main():
	t = int(stdin.readline().strip())
	for _ in range(t):
		(a, b) = map(int, stdin.readline().strip().split())
		print(solve(a, b))
main()


for _ in range(int(input())):
	(A, B) = map(int, input().split())
	if B > A:
		print(B - A)
	else:
		print((B - A % B) % B)


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	(n, s) = stdin.readline().split()
	s = int(s)
	sum = 0
	movs = 0
	for i in range(len(n)):
		sum += int(n[i])
		if sum >= s:
			p = int(n[min(i + 1, len(n) - 1):])
			if sum != s or (p != 0 and i != len(n) - 1):
				movs = 10 ** (len(n) - i) - int(n[i:])
			break
	print(movs)


n = int(input())
l1 = []
while n > 0:
	l = list(map(int, input().split()))
	if l[0] % l[1] == 0:
		l1.append(0)
	else:
		l1.append(l[1] - l[0] % l[1])
	n = n - 1
for i in range(len(l1)):
	print(l1[i])


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	temp = str(a)
	c = b
	i = 0
	if sum([int(x) for x in temp]) <= b:
		print(0)
		continue
	while c > int(temp[i]):
		c -= int(temp[i])
		i += 1
	if i > 0:
		no = str(int(temp[:i]) + 1) + (len(temp) - i) * '0'
	else:
		no = '1' + len(temp) * '0'
	print(int(no) - a)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for i in range(t):
	(n, s) = list(map(int, input().split()))
	m = str(n)
	p = 0
	lis = []
	l = len(m)
	for j in m:
		p += int(j)
		lis.append(int(j))
	if p <= s:
		print(0)
	else:
		j = l - 1
		ans = 0
		while p > s and j >= 0:
			if lis[j] != 0:
				p -= lis[j]
				ans += 10 ** (l - j - 1) * (10 - lis[j])
				lis[j] = 0
				j -= 1
				while j >= 0 and p + 1 > s:
					if lis[j] != 9:
						p += 1
						lis[j] += 1
						break
					else:
						p -= 9
						lis[j] = 0
						j -= 1
			else:
				j -= 1
		print(ans)


n = int(input())
test = []
for i in range(n):
	test.append(list(map(int, input().split())))
for i in range(n):
	count = 0
	(a, b) = (test[i][0], test[i][1])
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


from sys import stdin, stdout, exit as sys_ret
(f_input, f_print, f_flush) = (stdin.readline, stdout.write, stdout.flush)
for _ in range(int(f_input())):
	(a, b) = map(int, f_input().split())
	if a == b or a % b == 0:
		f_print('0\n')
		continue
	if a < b:
		f_print(str(b - a) + '\n')
		continue
	new = a // b * b + b
	f_print(str(new - a) + '\n')


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import time, random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def main():
	t = I()
	ab = [LI() for _ in range(t)]
	rr = []
	for (a, b) in ab:
		k = a % b
		if k == 0:
			rr.append(0)
		else:
			rr.append(b - k)
	return JA(rr, '\n')
print(main())


T = int(input())
ret = []
for t in range(T):
	(n, s) = input().split()
	s = int(s)
	raw = int(n)
	n = list(n)
	n = list(map(int, n))
	score = sum(n)
	ans = 0
	keta = 0
	while score > s:
		if n[len(n) - 1 - keta] == 0:
			keta += 1
			continue
		if n[len(n) - 1 - keta] == 10:
			n[max(0, len(n) - 1 - keta - 1)] += 1
			keta += 1
			score += -9
			continue
		score += 1 - n[len(n) - 1 - keta]
		ans += 10 ** keta * (10 - n[len(n) - 1 - keta])
		n[max(0, len(n) - 1 - keta - 1)] += 1
		keta += 1
	ret.append(ans)
for i in range(T):
	print(ret[i])


import math
t = int(input())
for _ in range(t):
	(n, s) = map(int, input().split())
	v = 0
	n1 = n
	cnt = 0
	while n > 0:
		r = n % 10
		v += r
		cnt += 1
		n = n // 10
	if v <= s:
		print(0)
	else:
		n2 = list(str(n1))
		n2.reverse()
		n2 = ''.join(n2)
		n2 = int(n2)
		c = 0
		cnt1 = 0
		while c < s:
			r = n2 % 10
			c += r
			n2 = n2 // 10
			cnt1 += 1
		if c >= s:
			cnt1 -= 1
		cnt = cnt - cnt1
		val = n1 // 10 ** cnt
		val += 1
		val = val * 10 ** cnt
		print(val - n1)


import math
t = int(input())
for i in range(t):
	(a, b) = list(map(int, input().split()))
	ma = math.ceil(a / b)
	print(abs(a - b * ma))


import math
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		temp = a / b
		temp1 = temp % 1
		temp2 = 1 - temp1
		print(math.floor(b * temp2 + 0.5))


t = int(input())
L = []
for i in range(t):
	s = input()
	(a, b) = s.split(' ')
	a = int(a)
	b = int(b)
	if a % b == 0:
		L.append(0)
	else:
		k = a // b
		L.append((k + 1) * b - a)
for i in range(t):
	print(L[i])


n = int(input())
ans = []
for i in range(n):
	(a, b) = map(int, input().split(' '))
	d = int(a / b)
	r = a % b
	if r == 0:
		ans.append(0)
	else:
		t = (d + 1) * b
		ans.append(t - a)
for i in range(n):
	print(int(ans[i]))


x = int(input())
for i in range(x):
	(n, m) = map(int, input().split())
	import math
	print(math.ceil(n / m) * m - n)


def problem(a, b):
	count = 0
	if a % b == 0:
		return count
	else:
		res = a % b
		count = b - res
	return count
for i in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	print(problem(a, b))


def divProb(a, b):
	if a % b == 0:
		return 0
	return b - a % b
tc = int(input())
for i in range(tc):
	inp = list(map(int, input().split()))
	print(divProb(inp[0], inp[1]))


def digit_sum(x):
	sum = 0
	while x != 0:
		sum += x % 10
		x //= 10
	return sum
t = int(input())
for i in range(t):
	nums = [int(i) for i in input().split()]
	n = nums[0]
	s = nums[1]
	pluses = 0
	ind = 0
	while digit_sum(n) > s:
		pluses += (10 - n % 10) * 10 ** ind
		n += 10 - n % 10
		n //= 10
		ind += 1
	print(pluses)


x = int(input())
for _ in range(x):
	(w, y) = map(int, input().split())
	if w >= y:
		thing = w // y
		if w % y == 0:
			print(0)
		else:
			print((thing + 1) * y - w)
	else:
		print(y - w)


import sys
import collections, itertools, bisect, heapq, math, string

def input():
	return sys.stdin.readline().strip()

def main():
	t = int(input())
	nums = [list(map(int, input().split())) for x in range(t)]
	i = 0
	for n in nums:
		(a, b) = (n[0], n[1])
		if a % b != 0:
			print((a // b + 1) * b - a)
		else:
			print(0)
main()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
from math import ceil, floor, sqrt, pow

def digit(n):
	res = 0
	while n:
		res += n % 10
		n //= 10
	return res
t = int(input())
for _ in range(t):
	(n, s) = map(int, sys.stdin.readline().rstrip().split())
	if digit(n) <= s:
		print(0)
	else:
		ns = str(n)
		if int(ns[0]) >= s:
			print(10 ** len(ns) - n)
		else:
			now = 0
			for i in range(len(ns)):
				now += int(ns[i])
				if now >= s:
					nn = int(ns[:i]) + 1
					nn = int(str(nn) + '0' * (len(ns) - i))
					print(nn - n)
					break


t = int(input())
powers_of_ten = [10 ** i for i in range(163)]
for i in range(t):
	string = input()
	(n, s) = (string.split()[0], int(string.split()[1]))
	n_int = int(n)
	start = n_int
	index = len(n) - 1
	while True:
		sum = 0
		for j in n:
			sum += int(j)
		if sum <= s:
			print(n_int - start)
			break
		while n[index] == str(0):
			index -= 1
		rest = 10 - int(n[index])
		n_int += rest * powers_of_ten[len(n) - 1 - index]
		n = str(n_int)


n = int(input())
for i in range(0, n):
	p = [int(a) for a in input().split(' ')]
	rem = p[0] % p[1]
	if rem != 0 and rem != p[1]:
		print(p[1] - rem)
	else:
		print(0)


t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	if n % k == 0:
		co = 0
	else:
		co = k - n % k
	print(co)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	n = str(n)
	curr = 0
	for i in range(len(n)):
		curr += int(n[i])
	if curr <= s:
		print(0)
	elif int(n[0]) >= s:
		print(10 ** len(n) - int(n))
	else:
		x = 0
		ans = []
		for i in range(len(n)):
			st = list(n)
			x += int(n[i])
			if x < s:
				st[i] = str(int(st[i]) + 1)
				for j in range(i + 1, len(st)):
					st[j] = '0'
				ans.append(int(''.join(st)) - int(n))
		print(min(ans))


def divme(a, b):
	return (b - a % b) % b
temp = []
for _ in range(int(input())):
	(a, b) = list(map(int, input().split(' ')))
	temp.append(divme(a, b))
print(*temp, sep='\n')


def sumdigits(x):
	sumi = 0
	while x > 0:
		sumi += x % 10
		x = x // 10
	return sumi

def closest(x, s):
	if sumdigits(x) <= s:
		return x
	if x % 10 == 0:
		return closest(x // 10, s) * 10
	else:
		return closest(x // 10 + 1, s) * 10
t = int(input())
for you in range(t):
	l = input().split()
	n = int(l[0])
	s = int(l[1])
	z = closest(n, s)
	print(z - n)


T = int(input())
for _ in range(T):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		ans = abs(a % b - b)
		print(ans)


import sys
T = int(sys.stdin.readline())
for _ in range(T):
	(a, b) = map(int, sys.stdin.readline().split())
	print(b - a % b if a % b else 0)


def solve():
	(n, s) = [str(i) for i in input().split(' ')]
	s = int(s)
	count = 0
	ans = ''
	cum = sum((int(i) for i in n))
	if cum <= s:
		print(0)
		return
	if int(n[0]) >= s:
		if int(n[0]) == s and len(n) == 1:
			print(0)
			return
		ans = '10' + '0' * len(n[1:])
		print(int(ans) - int(n))
		return
	for (idx, i) in enumerate(n):
		count += int(i)
		if idx == len(n) - 1 and count <= s:
			print(0)
			return
		if count >= s:
			ans = str(int(n[:idx]) + 1) + '0' * (len(n) - idx)
			print(int(ans) - int(n))
			return
	print(0)

def main():
	tc = int(input().strip())
	for c in range(tc):
		solve()
main()


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	div = a // b
	div += 1
	num = b * div - a
	if num == b:
		num = 0
	print(num)


def aux(n, s):
	if sum((ord(x) - 48 for x in str(n))) <= s:
		return 0
	if n % 10 == 0:
		return 10 * aux(n // 10, s)
	d = 10 - n % 10
	return d + 10 * aux(n // 10 + 1, s)
for t in range(int(input())):
	(n, s) = map(int, input().split())
	print(aux(n, s))


num_tests = int(input())
for _ in range(num_tests):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		div = a // b
		next_multiple = b * (div + 1)
		print(next_multiple - a)


def min_moves_divisibility(a, b):
	return (b - a % b) % b

def run_alg():
	num_cases = int(input())
	for _ in range(num_cases):
		line_data = input().split(' ')
		a = int(line_data[0])
		b = int(line_data[1])
		print(min_moves_divisibility(a, b))
run_alg()


import math
t = int(input())
for _t in range(t):
	(a, b) = [int(x) for x in input().strip().split()]
	print(int(b * math.ceil(a / b) - a))


def solve(n, s):
	n_str = str(n)
	digits = map(int, n_str)
	curr_sum = 0
	ans = 0
	for (i, d) in enumerate(digits):
		curr_sum += d
		if curr_sum > s:
			sup_i = i
			tail = int(n_str[i:])
			ten_p = 10 ** (len(n_str) - i)
			ans = ten_p - tail
			return ans + solve(n + ans, s)
	return 0
t = int(input())
for _ in range(t):
	(n, s) = map(int, input().split())
	print(solve(n, s))


def findNum(N, K):
	rem = (N + K) % K
	if rem == 0:
		return N
	else:
		return N + K - rem
testCases = int(input())
for i1 in range(testCases):
	parameter = list(map(int, input().split()))
	a = parameter[0]
	b = parameter[1]
	temp = findNum(a, b)
	print(temp - a)


t = int(input())
x = [list(map(int, input().split())) for _ in range(t)]
for (a, b) in x:
	print(abs(b * -(-a // b) - a))


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	q = a // b
	if a % b == 0:
		print(0)
	else:
		q = q + 1
		f = q * b
		ans = f - a
		print(ans)


def ab(a, b):
	return (b - a % b) % b
for i in range(int(input())):
	(a, b) = map(int, input().split())
	print(ab(a, b))


import sys
stdin = sys.stdin
stdout = sys.stdout

def getCount(n):
	ans = 0
	while n:
		ans += n % 10
		n = n // 10
	return ans

def getLastSetBit(n):
	ans = 0
	power = 1
	while n:
		ans = n % 10
		if ans != 0:
			return (ans, power)
		n = n // 10
		power = power * 10
test = int(stdin.readline())
for t in range(test):
	(n, s) = [int(_) for _ in stdin.readline().split()]
	ans = 0
	while getCount(n) > s:
		(setBit, power) = getLastSetBit(n)
		temp = (10 - setBit) * power
		ans += temp
		n += temp
	stdout.write(f'{ans}\n')


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
		continue
	q = a // b + 1
	num = q * b
	res = num - a
	print(res)


def to_int(digits):
	return int(''.join(map(str, digits)))

def solve(cur, target_sum):
	cur = [ord(ch) - ord('0') for ch in str(cur)]
	cur = [0] + cur
	copied = cur.copy()
	if sum(cur) <= target_sum:
		return 0
	for i in range(len(cur) - 1, -1, -1):
		copied[i] = 0
		if copied[i - 1] == 9:
			continue
		copied[i - 1] = cur[i - 1] + 1
		if sum(copied) <= target_sum:
			return to_int(copied) - to_int(cur)
for _ in range(int(input())):
	(cur, target_sum) = map(int, input().split())
	print(solve(cur, target_sum))


import math
T = int(input())
for _ in range(T):
	(N, M) = map(int, input().split())
	x = math.ceil(N / M)
	print(M * x - N)


t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	if n % k == 0:
		print(0)
		continue
	print((int(n / k) + 1) * k - n)


t = int(input())
for _ in range(t):
	(n1, n2) = map(int, input().split())
	print(n2 - (n1 % n2 if n1 % n2 != 0 else n2))


for i in range(int(input())):
	a = input().split(' ')
	a = list(map(int, a))
	if a[0] < a[1]:
		print(a[1] - a[0])
	elif a[0] % a[1] == 0:
		print(0)
	else:
		print(abs(a[0] % a[1] - a[1]))


z = int(input())
for i in range(z):
	(a, b) = map(int, input().split())
	c = a % b
	c = b - c
	print(c % b)


def cal(n):
	ret = 0
	while n > 0:
		ret += n % 10
		n //= 10
	return ret
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	if cal(n) <= s:
		print(0)
		continue
	p = 1
	ans = 0
	for i in range(18):
		d = n // p % 10
		v = p * ((10 - d) % 10)
		n += v
		ans += v
		if cal(n) <= s:
			break
		p *= 10
	print(ans)


import sys
t = int(input())
for x in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print('0')
	else:
		d = a // b
		m = b * (d + 1)
		dif = m - a
		print(dif)


import math
n = int(input())
i = 0
while i < n:
	i += 1
	(a, b) = map(int, input().split())
	div = math.ceil(a / b)
	ans = max(a, div * b) - min(a, div * b)
	print(ans)


import math as m
from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	(n, d) = map(int, stdin.readline().split())
	if n % d == 0:
		print(0)
	else:
		q = n // d + 1
		print(q * d - n)


t = int(input())
ans = []
while t:
	(a, b) = map(int, input().split())
	if a % b == 0:
		ans.append(0)
	else:
		ans.append(b - a % b)
	t -= 1
for i in range(len(ans)):
	print(ans[i])


t = int(input())
while t:
	t -= 1
	nums = list((int(x) for x in input().split()))
	(a, b) = (nums[0], nums[1])
	rem = a % b
	if not rem:
		print(0)
	else:
		print(b - rem)


t = int(input())

def dfs(num, s):
	if sum([int(d) for d in str(num)]) <= s:
		return 0
	partial = 10 - num % 10
	return dfs(num // 10 + 1, s) * 10 + partial
for _ in range(t):
	(n, s) = map(int, input().split())
	print(dfs(n, s))


t = int(input())
moves = []
count = 0
rem = 0
for i in range(t):
	(a, b) = map(int, input().split())
	rem = a % b
	if rem == 0:
		moves.insert(i, 0)
	else:
		moves.insert(i, b - rem)
	print(moves[i])


def ProcessInputs():
	(A, B) = map(int, input().strip().split())
	if A % B == 0:
		print(0)
		return
	else:
		print(B - A % B)
		return
T = int(input())
for _ in range(T):
	ProcessInputs()


from sys import stdin, stdout

def decrease_the_sum_of_digits(n, s):
	n_s = str(n)
	v = 0
	ans = 0
	for i in range(len(n_s)):
		v += ord(n_s[i]) - ord('0')
		if v >= s and ans == 0:
			ans = 10 ** (len(n_s) - i) - int(n_s[i:])
	if v == s:
		return 0
	else:
		return ans
t = int(stdin.readline())
for _ in range(t):
	(n, s) = map(int, stdin.readline().split())
	ans = decrease_the_sum_of_digits(n, s)
	stdout.write(str(ans) + '\n')


t = input()
t = int(t)
for i in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	c = n % k
	if n % k == 0:
		print('0')
	else:
		print(k - c)


import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

def line():
	return map(int, input().split())

def num():
	return int(input())
from itertools import repeat
t = num()
for _ in repeat(None, t):
	(a, b) = line()
	print((b - a % b) % b)


t = int(input())
for _ in range(t):
	l = input().split()
	n = l[0]
	s = int(l[1])
	summ = sum(list(map(int, l[0])))
	if summ <= s:
		print(0)
		continue
	now = 0
	ind = 0
	while ind < len(n) and now + int(n[ind]) < s:
		now += int(n[ind])
		ind += 1
	if ind == len(n):
		print(0)
	else:
		r = int(n[ind:])
		need = int('1' + '0' * len(n[ind:]))
		print(need - r)


import math
t = int(input())
for q in range(t):
	(a, b) = map(int, input().split())
	if a <= b:
		print(b - a)
	else:
		print(b * math.ceil(a / b) - a)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	if n > k:
		if n % k != 0:
			print((n // k + 1) * k - n)
		else:
			print(0)
	else:
		print(abs(n - k))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print('0')
	else:
		quo = a // b
		up = b * (quo + 1)
		print(up - a)


x = int(input())
lyst = []
for i in range(x):
	(a, b) = [int(i) for i in input().split(' ')]
	y = a % b
	if y == 0:
		lyst.append(y)
	else:
		lyst.append(b - y)
for j in lyst:
	print(j)


def isSum(n, k):
	sumi = 0
	for i in range(0, len(n)):
		sumi += int(n[i])
	if sumi <= k:
		return True
	else:
		return False
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	n = list(str(n))
	sumi = 0
	for i in range(0, len(n)):
		sumi += int(n[i])
	if sumi <= k:
		print(0)
	elif len(n) == 1:
		if sumi > k:
			print(10 - int(n[0]))
	else:
		j = 1
		count = 0
		for i in range(len(n) - 1, -1, -1):
			if i != 0:
				count += 10 ** j - int(n[i]) * 10 ** (j - 1)
				n[i] = str(0)
				n[i - 1] = str(int(n[i - 1]) + 1)
				j += 1
				if isSum(n, k) == True:
					break
			else:
				count += 10 ** j - int(n[i]) * 10 ** (j - 1)
		print(count)


t = int(input())
for q in range(t):
	(a, b) = map(int, input().split())
	print((b - a % b) % b)


import heapq

def one():
	return int(input())

def more():
	return map(int, input().split())
for _ in range(one()):
	(a, b) = more()
	if a % b == 0:
		print(0)
	else:
		print((a // b + 1) * b - a)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
		continue
	tr = a // b * b
	tr1 = (a // b + 1) * b
	print(abs(tr1 - a))


n = int(input())
for i in range(n):
	mk = input().split()
	m = int(mk[0])
	k = int(mk[1])
	if m % k == 0:
		print(m % k)
	else:
		print(k - m % k)


import sys
input = sys.stdin.readline
from math import ceil

def sumdig(n):
	n = str(n)
	ans = 0
	for i in n:
		ans += int(i)
	return ans
t = int(input())
while t != 0:
	t -= 1
	(n, s) = map(int, input().split())
	ans = 0
	if sumdig(n) <= s:
		print(0)
		continue
	i = 1
	ans = 0
	nn = n
	while sumdig(nn) > s:
		nn = 10 ** i * (nn // 10 ** i) + 10 ** i
		i += 1
	print(nn - n)


t = int(input())
for i in range(t):
	(a, b) = [int(s) for s in input().split(' ')]
	if a % b != 0:
		div = a // b
		mul = b * (div + 1)
		print(mul - a)
	else:
		print(0)


def construct(s, index):
	if index == 0:
		return '1' + '0' * len(s)
	mid = str(int(s[index - 1]) + 1)
	if len(mid) < 2:
		return s[:index - 1] + str(int(s[index - 1]) + 1) + '0' * (len(s) - index)
	can = s[:index - 1] + '0' + '0' * (len(s) - index)
	p = len(s) - index + 1
	return str(int(can) + 10 ** p)

def num_dec(s, target):
	tot = 0
	for i in s:
		tot += int(i)
	amount = tot - target
	if amount <= 0:
		return 0
	for i in range(len(s) - 1, -1, -1):
		if amount <= -1:
			j = int(construct(s, i))
			return j - int(s)
		amount -= int(s[i])
		if amount <= -1:
			j = int(construct(s, i))
			return j - int(s)
for _ in range(int(input())):
	x_t = input().split()
	s = x_t[0]
	tar = int(x_t[1])
	print(num_dec(s, tar))


n = int(input())
ansl = []
for i in range(n):
	(a, b) = map(int, input().split())
	m = 0
	if a < b:
		m = b - a
	elif a % b == 0:
		m = 0
	else:
		m = b - a % b
	ansl += [m]
for r in ansl:
	print(r)


n = int(input(''))
count = 1
while count <= n:
	(a, b) = [int(x) for x in input('').split()]
	if a % b == 0:
		print('0')
	elif a < b:
		out = b - a
		print(out)
	else:
		c = b - a % b
		print(c)
	count = count + 1


t = int(input())
i = 0
y = []
while i < t:
	(a, b) = map(int, input().split())
	a = int(a)
	b = int(b)
	i += 1
	if a % b == 0:
		y.append(a % b)
	else:
		y.append((a // b + 1) * b - a)
for i in y:
	print(i)


n = int(input())
for i in range(n):
	(a, b) = input().split()
	a1 = int(a)
	b1 = int(b)
	if a1 % b1 != 0:
		c = a1 // b1
		d = b1 * (c + 1) - a1
		print(d)
	else:
		print(0)


from itertools import permutations
from collections import defaultdict
from math import *
import os
import sys
from io import BytesIO, IOBase
from heapq import nlargest
from bisect import *
import copy
import itertools
BUFSIZE = 8192

def sum(s1):
	ans = 0
	for i in range(len(s1)):
		ans += int(s1[i])
	return ans
t = int(input())
while t:
	t -= 1
	(n, s) = map(int, input().split())
	s1 = str(n)
	if sum(s1) <= s:
		print('0')
	else:
		n = len(s1)
		arr = []
		val = 0
		for i in range(n):
			val += int(s1[i])
			arr.append(val)
		ns = ''
		pos = -1
		for i in range(n - 1, -1, -1):
			ns += '0'
			nss = ns
			for j in range(i - 1, -1, -1):
				if s1[j] != 9:
					summ = arr[j]
					if summ + 1 <= s:
						pos = j
					break
			if pos != -1:
				break
		position = 0 if pos == -1 else pos
		num = ''
		if position == 0:
			num = '1'
			for i in range(n):
				num += '0'
			val = int(num) - int(s1)
			temp = str(int(s1[0]) + 1)
			for i in range(n - 1):
				temp += '0'
			val2 = int(temp) - int(s1)
			ans = 0
			if sum(temp) <= s:
				ans = min(val, val2)
			else:
				ans = val
			print(ans)
		else:
			for i in range(position + 1):
				num += s1[i]
			num = str(int(num) + 1)
			for i in range(n - position - 1):
				num += '0'
			ans = int(num) - int(s1)
			print(ans)


tests = int(input())
for i in range(tests):
	(a, b) = map(int, input().split())
	if a % b != 0:
		c = a % b
		d = b - c
	else:
		d = 0
	print(d)


import sys
from math import sqrt
inp = sys.stdin.readline
read = lambda : list(map(int, inp().split()))

def a():
	ans = ''
	for _ in range(int(inp())):
		(a, b) = read()
		if a % b == 0:
			ans += '0\n'
		else:
			ans += str((a // b + 1) * b - a) + '\n'
	print(ans)
a()


def main():
	test = int(input())
	for t in range(test):
		l = [int(i) for i in input().split(' ')]
		a = l[0]
		b = l[1]
		if a % b == 0:
			print(0)
		else:
			temp = (a // b + 1) * b - a
			print(temp)
main()


n = int(input())
cases = []
for i in range(n):
	cases.append(list(map(int, input().split())))
for j in range(len(cases)):
	if cases[j][0] % cases[j][1] == 0:
		print(0)
	else:
		print(cases[j][1] - cases[j][0] % cases[j][1])


def algo(n, s):
	cur = -1
	total = 0
	sn = str(n)
	for i in range(len(sn)):
		total += int(sn[i])
		if total < s:
			cur = i
	if total <= s:
		return 0
	res = 0
	substr = sn[cur + 1:]
	return int('1' + '0' * len(substr)) - int(substr)
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	ans = algo(n, s)
	print(ans)


for i in range(int(input())):
	(x, y) = map(int, input().split())
	if y > x:
		print(y - x)
	elif x % y == 0:
		print(0)
	elif x // y * y < x:
		print(y * (x // y + 1) - x)


for _ in range(int(input())):
	(n, s) = input().split()
	s = int(s)
	n = '0' + n
	c = d = 0
	while c <= s:
		c += int(n[d])
		d += 1
		if d == len(n):
			if c <= s:
				d = -1
			break
	if d < 0:
		print(0)
		continue
	d -= 1
	c -= int(n[d])
	while sum(map(int, str(int(n[:d]) + 1))) > s:
		d -= 1
	print(int(str(int(n[:d]) + 1) + '0' * (len(n) - d)) - int(n))


a = int(input())
h = []
for i in range(0, a):
	(x, y) = list(map(int, input().split()))
	res = 0
	if x % y == 0:
		res = 0
	else:
		d = int(x // y) + 1
		res = y * d - x
	h.append(res)
print(*h, sep='\n')


from sys import stdin, stdout
import math, sys
from itertools import permutations, combinations
from collections import defaultdict, deque
import bisect as bi
import heapq as hq

def I():
	return int(input())

def In():
	return map(int, input().split())

def main():
	try:
		for _ in range(int(input())):
			(a, b) = In()
			if a % b == 0:
				print(0)
			else:
				t = a // b
				t += 1
				print(t * b - a)
	except:
		pass
M = 998244353
P = 1000000007
main()


t = int(input())
for _ in range(t):
	inp = input().split(' ')
	a = int(inp[0])
	b = int(inp[1])
	move = 0
	if a % b == 0:
		print(move)
	else:
		g = a % b
		move = b - g
		print(move)


from sys import stdin, stdout

def rem(a, b):
	if a < b:
		return b - a
	elif a % b != 0:
		return b - a % b
	else:
		return 0

def main():
	n = 0
	for line in stdin:
		x = [int(i) for i in line.split()]
		if len(x) == 2:
			stdout.write(str(rem(x[0], x[1])) + '\n')
main()


from math import ceil

def solve(a, b):
	if a >= b:
		wholeNumber = ceil(a / b) * b
		return wholeNumber - a
	return b - a
for a in range(int(input())):
	(x, y) = input().split(' ')
	print(solve(int(x), int(y)))


import math
case = int(input())
moves = 0
for x in range(case):
	entra = input().split()
	a = int(entra[0])
	b = int(entra[1])
	if a % b == 0:
		moves = 0
	else:
		moves = b - abs(a % b)
	print(moves)


t = int(input())
for ts in range(t):
	(a, b) = [int(i) for i in input().split()]
	print((b - a % b) % b)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
mod = 10 ** 9 + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var, end='\n'):
	sys.stdout.write(str(var) + end)

def outa(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	(n, s) = sp()
	arr = list(map(int, str(n)))
	arr.insert(0, 0)
	sod = sum(arr)
	if sod <= s:
		out(0)
		continue
	temp = 0
	index = -1
	for i in range(len(arr) - 1, 0, -1):
		temp += arr[i]
		arr[i] = 0
		if sod - temp <= s:
			index = i
			break
	if sod - temp == s:
		while arr[index] == 0:
			index -= 1
		arr[index] = 0
	for i in range(index - 1, -1, -1):
		temp = 1 + arr[i]
		arr[i] = temp % 10
		if temp <= 9:
			break
	out(int(''.join(map(str, arr))) - n)


hm = int(input())
for i in range(hm):
	(a, b) = map(int, input().split())
	print((b - a % b) % b)


t = int(input())
out = 0
mylist = []
for i in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		out = 0
		mylist.append(out)
	else:
		out = b - a % b
		mylist.append(out)
res = '\n'.join((str(i) for i in mylist))
print(res)


t = int(input())
for l in range(t):
	inp1 = str(input())
	inp = inp1.split()
	a = int(inp[0])
	b = int(inp[1])
	if a % b == 0:
		print('0')
	else:
		r = a % b
		c = b - r
		print(c)


T = int(input())
while T:
	T -= 1
	(a, b) = [int(x) for x in input().split()]
	f = a % b
	if f == 0:
		print(f)
	else:
		print(b - f)


import sys
input = sys.stdin.buffer.readline

def print(val):
	sys.stdout.write(str(val) + '\n')

def prog():
	for _ in range(int(input())):
		(n, s) = map(int, input().split())
		n = str(n)[::-1]
		prefix = [0]
		for i in range(len(n)):
			prefix.append(prefix[-1] + int(n[i]))
		if prefix[len(n)] <= s:
			print(0)
			continue
		finished = False
		for i in range(len(n)):
			if n[i] == '9':
				continue
			best = 1 + prefix[len(n)] - prefix[i]
			if best <= s:
				added_to = n[:i][::-1]
				print(10 ** len(added_to) - int(added_to))
				finished = True
				break
		if not finished:
			print(10 ** len(n) - int(n[::-1]))
prog()


def function(a, b):
	if a == b:
		return 0
	elif a > b:
		if a % b == 0:
			return 0
		moves = a % b
		return b - moves
	else:
		moves = b - a
		return moves
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	print(function(a, b))


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().rstrip().split())
	k = a // b
	k += 1
	ans = b * k - a
	print(ans) if b != ans else print(0)


n = int(input())

def moves(a):
	s = int(a[0]) % int(a[1])
	if (int(a[0]) + s) % int(a[1]) != 0:
		print(int(a[1]) - s)
	else:
		print(s)
for i in range(0, n):
	a = input().split(' ')
	moves(a)


def is_good(n, s):
	return sum((int(i) for i in str(n))) <= s
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	count = 0
	m = 1
	while True:
		m *= 10
		if sum((int(i) for i in str(n))) <= s:
			break
		num = n % m
		count += m - num
		n += m - num
	print(count)


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	b1 = 0
	if a > b:
		if a % b != 0:
			b1 = a // b + 1
			b2 = b * b1
			print(b2 - a)
		else:
			print(0)
	else:
		print(b - a)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a < b:
		print(b - a)
		continue
	elif a % b == 0:
		print(0)
		continue
	else:
		rem = a % b
		steps = b - rem
		print(steps)


n = int(input())
h = []
for i in range(n):
	t = list(map(int, input().rstrip().split()))
	k = 0
	k = t[0] % t[1]
	if k != 0:
		k = t[1] - k
	h.append(k)
for a in range(n):
	print(h[a])


from sys import stdin
t = int(stdin.readline())
for _ in range(t):
	(a, b) = map(int, stdin.readline().split())
	if a % b == 0:
		print(0)
	else:
		print(b * (a // b + 1) - a)


size = int(input())
remainder = 0
for i in range(size):
	(first, second) = input().split()
	first = int(first)
	second = int(second)
	if first < second:
		print(second - first)
	elif first % second == 0:
		print(0)
	else:
		remainder = first % second
		print(second - remainder)


z = int(input())

def sm(x):
	ans = 0
	while x > 0:
		ans += x % 10
		x //= 10
	return ans
for _ in range(z):
	(n, s) = map(int, input().split())
	ans = 10000000000000000000000000000
	if sm(n) <= s:
		print(0)
		continue
	goal = n
	for i in range(len(str(n)) + 1):
		goal = int(str(n)[:len(str(n)) - i] + '0' * i) + 10 ** i
		if sm(goal) <= s:
			ans = min(ans, goal - n)
	print(ans)


test_cases = eval(input())
total = []
for i in range(test_cases):
	(a, b) = list(map(int, input().split()))
	if a % b == 0:
		total.append(0)
	else:
		modulus = a % b
		total.append(b - modulus)
for j in range(len(total)):
	print(total[j])


t = int(input())
for _ in range(0, t):
	(n, m) = map(int, input().split())
	if n % m == 0:
		print(0)
	else:
		z = min(n, m)
		p = max(n, m)
		k = n // m + 1
		k = k * z
		print(abs(k - p))


import math
t = int(input())
for wert in range(t):
	(n, k) = input().split()
	a = int(n)
	b = int(k)
	print(math.ceil(a / b) * b - a)


def summ(a):
	r = 0
	while a != 0:
		r += a % 10
		a = a // 10
	return r
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	if summ(n) <= s:
		print('0')
		continue
	p = 1
	res = 0
	for i in range(18):
		d = n // p % 10
		e = (10 - d) * p
		n += e
		res += e
		if summ(n) <= s:
			break
		p *= 10
	print(res)


n = int(input())
for i in range(0, n):
	p = input().rstrip().split(' ')
	if int(p[0]) % int(p[1]) == 0:
		print(0)
	elif int(p[0]) < int(p[1]):
		print(int(p[1]) - int(p[0]))
	else:
		A = int(p[0]) // int(p[1]) + 1
		B = A * int(p[1])
		print(B - int(p[0]))


import math
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	r = math.ceil(a / b) * b - a
	print(r)


t = int(input())
for q in range(t):
	(a, b) = map(int, input().split())
	ob = b
	if a == b or (a % b == 0 and a >= b):
		print(0)
	else:
		b *= a // b
		if b >= a:
			print(b - a)
		else:
			b += ob
			print(b - a)


t = int(input())
li = []
for i in range(t):
	(a, b) = map(int, input().split())
	if a > b:
		if a % b == 0:
			li.append('0')
		else:
			li.append(b - a % b)
	else:
		li.append(b - a)
for i in li:
	print(i)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b == 0:
		res = 0
	else:
		div = a // b
		mul = (div + 1) * b
		res = mul - a
	print(res)


from math import *
t = int(input())
while t > 0:
	(a, s1) = input().split()
	s = int(s1)
	val = 0
	ans1 = []
	ind = -1
	tot = 0
	for i in range(len(a)):
		tot = tot + int(a[i])
	if tot <= s:
		print(0)
		t -= 1
		continue
	for i in range(len(a)):
		if val + int(a[i]) >= s:
			ind = i
			break
		ans1.append(a[i])
		val = val + int(a[i])
	if ind == -1:
		print(0)
	elif ind == 0:
		ans = '10'
		for i in range(1, len(a)):
			ans = ans + '0'
		print(int(ans) - int(a))
	else:
		i = ind - 1
		while i > 0 and ans1[i] == '9':
			ans1[i] = '0'
			i -= 1
		ans1[i] = str(int(ans1[i]) + 1)
		for i in range(ind, len(a)):
			ans1.append('0')
		ans = ''
		for i in ans1:
			ans = ans + i
		print(int(ans) - int(a))
	t -= 1


for _ in range(int(input())):
	(n, s) = input().split()
	s = int(s)
	su = 0
	for i in n:
		su += int(i)
	val = su - s
	if val <= 0:
		print(0)
	else:
		v = 0
		n = '0' + n
		ind = len(n) - 1
		c = 0
		while v <= val:
			c += 1
			v += int(n[ind])
			ind -= 1
		if v == val:
			ind -= 1
			c += 1
		st2 = n[:ind + 1] + '0' * c
		st = '1' + '0' * c
		v1 = int(st)
		v2 = int(st2)
		ans = v1 + v2
		print(ans - int(n))


tc = int(input())
for _ in range(tc):
	(n, s) = map(int, input().split(' '))
	if sum(map(int, str(n))) <= s:
		print(0)
		continue
	answer = 0
	for i in range(len(str(n))):
		t = 10 ** (i + 1)
		step = t - n % t
		n += step
		answer += step
		if sum(map(int, str(n))) <= s:
			print(answer)
			break


x = int(input())
(rows, cols) = (x, 2)
a = [[0] * cols] * rows
b = []
for i in range(0, x):
	(a[i][0], a[i][1]) = map(int, input().split())
	if a[i][1] > a[i][0]:
		b.append(int(a[i][1] - a[i][0]))
	elif a[i][0] % a[i][1] == 0:
		b.append(0)
	else:
		b.append(int(a[i][1] - a[i][0] % a[i][1]))
for i in range(0, x):
	print(b[i])


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	ans = k - n % k
	if n % k == 0:
		ans = 0
	print(ans)


def main():
	T = int(input())
	for _ in range(T):
		(n, s) = (int(i) for i in input().split())
		cur = sum((int(v) for v in str(n)))
		ans = 0
		if cur <= s:
			print(ans)
		else:
			d = 0
			while cur > s:
				r = int(str(n)[::-1][d])
				if r == 0:
					d += 1
					continue
				ans += (10 - r) * 10 ** d
				n += (10 - r) * 10 ** d
				cur = sum((int(v) for v in str(n)))
				d += 1
			print(ans)
main()


def solution(x):
	ans = []
	for i in range(len(x)):
		(a, b) = x[i]
		if a % b == 0:
			c = 0
		else:
			c = b - a % b
		ans.append(c)
	return ans

def main():
	t = int(input())
	x = []
	for i in range(t):
		a = list(map(int, input().split()))
		x.append(a)
	ans = solution(x)
	for i in range(len(ans)):
		print(ans[i])
main()


n = int(input())
a = []
for i in range(n):
	r = input()
	a.append(r)
for i in range(len(a)):
	b = a[i]
	for j in range(len(b)):
		if b[j] == ' ':
			c = j
	d = int(b[:c])
	e = int(b[c + 1:])
	if d % e == 0:
		print(0)
	else:
		print(e - d % e)


import string

def moves(cases):
	a = cases[0]
	b = cases[1]
	m = 0
	div = a / b
	rest = a % b
	if rest == 0:
		return m
	else:
		div = int(div)
		div += 1
		c = b * div
		m = c - a
		return m
for i in range(int(input())):
	cases = input().split(' ')
	for j in range(len(cases)):
		cases[j] = int(cases[j])
	print(moves(cases))


import math
import collections
import functools
import sys
import os
input = sys.stdin.read
readInts = lambda : list(map(int, input().split()))

def readChar():
	c = input(1)
	while c == '\n' or c == '\r' or c == ' ':
		c = input(1)
	return c

def readStr():
	c = input(1)
	while c == '\n' or c == '\r' or c == ' ':
		c = input(1)
	s = str()
	while c != '\n' and c != '\r' and (c != ' '):
		s += c
		c = input(1)
	return s

def readInt():
	c = input(1)
	while c != '-' and (not c.isdigit()):
		c = input(1)
	d: int = -1
	x: int = 0
	if c.isdigit():
		d = 1
	else:
		c = input(1)
	while c.isdigit():
		x = x * 10 + ord(c) - ord('0')
		c = input(1)
	return d * x

def gcd(a, b):
	while b > 0:
		(a, b) = (b, a % b)
	return a

def lcm(a, b):
	return a * b // gcd(a, b)
eps = 10 ** (-9)
inf = 10 ** 18
mod = 10 ** 9 + 7

def solution():
	a = readInt()
	b = readInt()
	if a % b == 0:
		os.write(1, str.encode('0\n'))
	else:
		os.write(1, str.encode(str((a // b + 1) * b - a) + '\n'))
tests = 1
tests = readInt()
while tests > 0:
	solution()
	tests -= 1


t = int(input())
for i in range(t):
	(n, s) = input().split(' ')
	tmp = int(n)
	n = str(n)
	s = int(s)
	ar = [0]
	m = len(n)
	for j in range(m):
		ar.append(ar[-1] + ord(n[j]) - ord('0'))
	if ar[-1] <= s:
		print(0)
		continue
	check = False
	for j in range(len(ar) - 1, 0, -1):
		if ar[j] + 1 <= s:
			ans = 0
			cur = 10
			for t in range(j + 1, m):
				cur *= 10
			ans = cur * (ord(n[j - 1]) - ord('0') + 1)
			for t in range(j - 1, 0, -1):
				cur = cur * 10
				ans = ans + (ord(n[t - 1]) - ord('0')) * cur
			print(ans - tmp)
			check = True
			break
	if check:
		continue
	ans = 1
	for j in range(m):
		ans *= 10
	print(ans - tmp)


n = int(input())
for i in range(n):
	(a, s) = input().split()
	s = int(s)
	curr = 0
	for digit in a:
		curr += int(digit)
	if curr <= s:
		print(0)
		continue
	diff = curr - s
	zeroes = ''
	rem = ''
	for digit in a[::-1]:
		if diff >= 0:
			zeroes = '0' + zeroes
			diff -= int(digit)
		else:
			rem = digit + rem
	if rem == '':
		rem = '0'
	ideal = str(int(rem) + 1) + zeroes
	print(int(ideal) - int(a))


from sys import stdin, stdout

def solve():
	(a, b) = [int(i) for i in stdin.readline().split()]
	if a % b == 0:
		return 0
	else:
		return b - a % b
t = int(input())
for i in range(t):
	print(solve())


for T in range(int(input())):
	(a, b) = list(map(int, input().split()))
	q = a // b
	r = a % b
	if r != 0:
		q += 1
	res = b * q - a
	print(res)


rr = lambda : input().strip()
rri = lambda : int(rr())
rrm = lambda : map(int, rr().split())
T = rri()
for i in range(T):
	(a, b) = rrm()
	x = a % b
	if x:
		x = b - x
	print(x)


from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
import math

def sp():
	return map(int, input().split())

def fun(x):
	return sum((int(i) for i in str(x)))
t = int(input())
for _ in range(t):
	(n, s) = sp()
	x = n
	if fun(x) > s:
		while fun(x + 1) > s:
			x //= 10
		x += 1
	while x < n:
		x *= 10
	print(x - n)


import sys
input = sys.stdin.readline
import math
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	l = list(map(int, list(str(n))))
	x = 0
	i = 0
	while i < len(l) and x < s:
		if x + l[i] < s:
			x += l[i]
			i += 1
		else:
			break
	if sum(l) == s:
		print(0)
	elif i == len(l):
		print(0)
	elif i == 0:
		print(pow(10, len(l)) - n)
	else:
		for j in range(len(l)):
			l[j] = str(l[j])
		k = int(''.join(l[:i]))
		k += 1
		print(k * pow(10, len(l) - i) - n)


n = int(input())
for x in range(n):
	(n, m) = list(map(int, input().strip().split()[:2]))
	k = n % m
	if k != 0:
		print(m - k)
	else:
		print(0)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	curr = a // b
	if not curr:
		if a >= b:
			print(0)
		else:
			print(b - a)
	else:
		while curr * b < a:
			curr += 1
		print(curr * b - a)


t = int(input())
for _ in range(t):
	(x, y) = map(int, input().split())
	if x % y == 0:
		print(0)
	else:
		zz = x % y
		print(y - zz)


from math import gcd
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if b > a:
		print(b - a)
	elif a % b == 0:
		print(0)
	else:
		print((a // b + 1) * b - a)


t = int(input())
while t:
	t -= 1
	(n, s) = input().split()
	on = int(n)
	(n, s) = ([0] + [int(i) for i in n], int(s))
	sm = sum((int(i) for i in n))
	prv = 0
	if sm > s:
		for i in range(len(n) - 1, -1, -1):
			if n[i] != 9 and sm - prv + 1 <= s:
				sm = 0
				n[i] += 1
				break
			prv += n[i]
			n[i] = 0
	n = int(''.join([str(i) for i in n]))
	print(n - on)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	st = str(n)
	p = [0] * len(st)
	for i in range(len(st) - 1, -1, -1):
		p[i] += int(st[i])
		if i + 1 < len(p):
			p[i] += p[i + 1]
	if p[0] <= s:
		print(0)
		continue
	last = 0
	moves = float('inf')
	for j in range(len(p) - 1, -1, -1):
		last += int(st[j])
		val = p[0] - last + 1
		if val <= s:
			if j - 1 >= 0:
				newnum = int(st[:j - 1] + str(int(st[j - 1]) + 1) + '0' * (len(st) - j))
				moves = min(moves, newnum - n)
			else:
				newnum = int('1' + '0' * len(st))
				moves = min(moves, newnum - n)
	print(moves)


for t in range(int(input())):
	(n, s) = map(int, input().split())
	num = list(str(n))
	if sum(map(int, num)) <= s:
		print('0')
		continue
	final_ans = list('1' + '0' * len(num))
	(res, idx) = (0, len(num) - 1)
	while num != final_ans:
		num[idx] = '0'
		idx -= 1
		while idx >= 0 and num[idx] == '9':
			num[idx] = '0'
			idx -= 1
		if idx < 0:
			res += int(''.join(final_ans)) - n
			break
		num[idx] = str(int(num[idx]) + 1)
		res += int(''.join(num)) - n
		n = int(''.join(num))
		if sum(map(int, num)) <= s:
			break
	print(res)


import sys
for _ in range(int(input())):
	(n, s) = map(int, sys.stdin.readline().split())
	n_list = list(str(n))
	for i in range(len(n_list)):
		n_list[i] = int(n_list[i])
	cnt = 0
	if sum(n_list) <= s:
		cnt = 0
	elif n_list[0] >= s:
		cnt = 10 ** len(n_list) - n
	else:
		for i in range(1, len(n_list)):
			if sum(n_list[0:i + 1]) >= s:
				j = ''.join(map(str, n_list[0:i]))
				cnt = (int(j) + 1) * 10 ** len(n_list[i:]) - n
				break
	print(cnt)


rr = lambda : input().strip()
rrm = lambda : map(int, rr().split())

def solve():
	(n, s) = rrm()
	n = str(n)
	l = len(n)
	x = s
	for i in range(l):
		x = int(n[i])
		if x >= s:
			break
		else:
			s -= x
	else:
		return 0
	if s < 10 and x == s:
		x = n[:i] + str(s) + '0' * (l - i - 1)
		if x == n:
			return 0
	ans = 10 ** (l - i) - int(n[i:])
	return ans
T = int(rr())
for _ in range(T):
	ans = solve()
	print(ans)


def main():
	t = int(input())
	for i in range(t):
		(n, m) = map(int, input().split())
		if n % m == 0:
			print(0)
		else:
			print((n // m + 1) * m - n)
main()


val = int(input())
liste = []
for _ in range(val):
	(a, b) = [int(x) for x in input().split()]
	liste.append((b - a % b) % b)
for x in liste:
	print(x)


t = int(input())
while t > 0:
	t -= 1
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	if n % k == 0:
		print(0)
	else:
		print(k - n % k)


T = int(input())
A = []
for i in range(T):
	A.append([int(x) for x in input().split()])
for X in A:
	print(X[1] - X[0] % X[1] if X[0] % X[1] != 0 else 0)


t = int(input())
for i in range(t):
	at = 0
	(a, b) = map(int, input().split())
	k = a
	if sum(map(int, list(str(a)))) <= b:
		print(0)
		continue
	else:
		for j in range(len(str(a)) - 1, -1, -1):
			a += (10 - int(str(a)[j])) * 10 ** (len(str(a)) - j - 1)
			if sum(map(int, list(str(a)))) <= b:
				print(a - k)
				break


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def gift():
	for _ in range(t):
		(a, b) = list(map(int, input().split()))
		c = a % b
		if c == 0:
			yield 0
		else:
			yield (b - c)
t = int(input())
ans = gift()
print(*ans, sep='\n')


import sys, bisect
input = sys.stdin.readline

def One(type):
	return type(input())

def List(type):
	return list(map(type, input().split()))

def Str():
	ans = list(input())
	ans.pop()
	return ans

def Many(type):
	return map(type, input().split())

def val(n):
	ans = 0
	for i in n:
		ans += int(i)
	return ans

def solve():
	(n, s) = Many(int)
	n = str(n)[::-1]
	ans = 0
	j = -1
	cnt = 10
	while j < len(n) and cnt > 0:
		j += 1
		i = n[j]
		if val(n) <= s:
			break
		if int(i) == 0:
			continue
		pl = 10 - int(i)
		n = str(int(n[::-1]) + pl * 10 ** j)[::-1]
		ans += pl * 10 ** j
	print(ans)

def main():
	t = One(int)
	for _ in range(t):
		solve()
main()


import sys

def clean(ans):
	pos = 0
	for c in ans:
		if c == '0':
			pos += 1
		else:
			break
	if pos == len(ans):
		pos -= 1
	return ans[pos:]

def task():
	(n, s_str) = input().split()
	s = int(s_str)
	d = 0
	for c in n:
		d += int(c)
	pos = len(n) - 1
	res = ''
	carry = 0
	while d > s or carry != 0:
		sum = int(n[pos]) if pos >= 0 else 0
		d -= sum
		sum += carry
		dig = sum % 10
		d += dig
		carry = int(sum / 10)
		if d <= s and carry == 0:
			break
		d -= dig
		diff = 10 - dig if dig != 0 else 0
		res = str(diff) + res
		sum += diff
		carry = int(sum / 10)
		pos -= 1
	if res == '':
		res = '0'
	return clean(res)
n = int(input())
for i in range(n):
	print(task())


import sys
RI = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
for i in range(int(ri())):
	(a, b) = RI()
	temp = a % b
	if temp == 0:
		print(0)
	else:
		print(b - temp)


t = int(input())
while t > 0:
	val = list(map(int, input().split(' ')))
	a = val[0]
	b = val[1]
	counter = 0
	if a % b != 0:
		quotient = a // b
		pro = b * (quotient + 1)
		counter = pro - a
	print(counter)
	t -= 1


q = int(input())

def fun(a, b):
	s = a % b
	if s == 0:
		print(0)
	else:
		print(b - s)
while q:
	q -= 1
	(a, b) = map(int, input().split())
	fun(a, b)


val = int(input())
for i in range(0, val):
	(x, y) = map(int, input().split())
	if x % y == 0:
		print('0')
	if x % y != 0:
		c = int(x / y) + 1
		e = c * y
		d = e - x
		print(d)


t = int(input())
javab = []
for i in range(0, t):
	x = input()
	xx = x.split()
	a = int(xx[0])
	b = int(xx[1])
	if a % b == 0:
		javab.append(0)
	else:
		f = a // b + 1
		javab.append(f * b - a)
for i in javab:
	print(i)


s = int(input())
for i in range(0, s):
	q = input().split()
	a = int(q[0])
	b = int(q[1])
	if a % b == 0:
		print(0)
	else:
		c = a // b
		d = b * (c + 1)
		print(d - a)


import math
T = int(input())
while T:
	T -= 1
	(x, y) = map(int, input().split())
	if x % y == 0:
		print(0)
	else:
		print(y - x % y)


import math
g = lambda x: map(x, input().split())

def main():
	n = int(input())
	for i in range(n):
		(a, b) = g(int)
		print((a // b + int(a % b > 0)) * b - a)
main()


x = int(input())
for i in range(x):
	found = False
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if a % b == 0 and (not found):
		print(0)
		found = True
	if a < b and (not found):
		print(b - a)
		found = True
	elif not found:
		print(b - a % b)


from math import *
from bisect import bisect_left, bisect_right
from sys import stdin, stdout, setrecursionlimit
from collections import Counter
input = lambda : stdin.readline().strip()
print = stdout.write
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	print(str((b - a % b) % b) + '\n')


for i in range(int(input())):
	(a, b) = map(int, input().strip().split())
	count = 0
	x = a % b
	if x == 0:
		print('0')
	else:
		print(b - x)


def fun(tmp):
	ret = 0
	while tmp > 0:
		ret += tmp % 10
		tmp //= 10
	return ret

def main():
	T = eval(input())
	for cas in range(T):
		(n, s) = map(int, input().split())
		tmp = 1
		ans = 0
		rdy = 0
		while n > 0:
			num = fun(n) + rdy
			bit = n % 10
			if num > s and bit != 0:
				ans += (10 - bit) * tmp
				n += 10
			tmp *= 10
			n //= 10
		print(ans)
main()


t = int(input())
for z in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	elif a < b:
		print(b - a)
	else:
		temp = int(a / b) * b
		while temp < a:
			temp = temp + b
		print(temp - a)


import sys

def divisor(a, b):
	while a != b:
		if a > b:
			a = a - b
		elif a < b:
			b = b - a
		return a
num = input()
for index in range(0, int(num)):
	i = 0
	str = input().split()
	a = int(str[0])
	b = int(str[1])
	if a % b == 0:
		print(0)
	elif a % b != 0:
		if b > a:
			print(b - a)
		else:
			print(b * (a // b + 1) - a)


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def get_digits(n):
	s = []
	v = 0
	while n:
		s.append(n % 10)
		v += 1
		n //= 10
	return (v, s, sum(s))
cases = int(input())
output = ''
for t in range(cases):
	(n, s) = list(map(int, input().split()))
	(num, dig, sd) = get_digits(n)
	if sd <= s:
		print(0)
	else:
		i = 0
		while sd >= s:
			sd -= dig[i]
			dig[i] = 0
			i += 1
		if i <= num - 1:
			dig[i] += 1
			while dig[i] == 10:
				dig[i] = 0
				if i + 1 <= num - 1:
					dig[i + 1] += 1
				else:
					dig.append(1)
				i += 1
		else:
			dig.append(1)
		dig = int(''.join(map(str, dig[::-1])))
		print(dig - n)


import sys
import math
mod = 998244353
cases = True
dynamic_factorial = False

def main(test_case=False):
	n = int(input()) if test_case else 1
	for _ in range(n):
		test()

def fast_pow(a: int, b: int):
	res = 1
	while b > 0:
		if b & 1:
			res *= a
		a *= a
		b >>= 1
	return res

def c2(n):
	return n * (n - 1) // 2

def get():
	return list(map(int, input().split()))

def bits(n: int):
	return list(bin(n)).count('1')

def flush():
	sys.stdout.flush()

def parr(arr):
	print(*arr, sep=' ')

def gcd(a, b):
	while b:
		if b % a == 0:
			break
		tmp = a
		a = b % a
		b = tmp
	return a

def ext_gcd(a: int, b: int):
	if b == 0:
		return [a, [1, 0]]
	res = ext_gcd(b, a % b)
	g = res[0]
	if g != 1:
		return False
	x1 = res[1][0]
	y1 = res[1][1]
	x = y1
	y = x1 - y1 * (a // b)
	return [g, [x, y]]

def get_set(a):
	res = {}
	for x in a:
		if x in res:
			res[x] += 1
		else:
			res[x] = 1
	return res
fact = {0: 1}

def factorial(n):
	if dynamic_factorial:
		if n not in fact:
			fact[n] = factorial(n - 1) * n
		return fact[n]
	else:
		res = 1
		while n > 0:
			res = res * n % mod
			n -= 1
		return res

def sum_of(a):
	res = 0
	for x in a:
		res = (res + x) % mod
	return res

def prod_of(a):
	res = 1
	for x in a:
		res = res * x % mod
	return res

def test():
	(n, s) = get()
	print(solve(n, s))

def digit_sum(n):
	result = 0
	while n > 0:
		result += n % 10
		n //= 10
	return result

def solve(n, s):
	d = digit_sum(n)
	if d <= s:
		return 0
	else:
		last_digit = n % 10
		return 10 - last_digit + 10 * solve(n // 10 + 1, s)
	print('OUT')
main(cases)


test = int(input())
for cases in range(test):
	(a, b) = map(int, input().split())
	if b > a:
		print(b - a)
	elif a % b == 0:
		print(0)
	else:
		rem = a % b
		print(b - rem)


t = int(input())
for q in range(t):
	(a, b) = map(int, input().split())
	x = a % b
	if x:
		print(b - x)
	else:
		print(x)


a = int(input())
for i in range(a):
	b = list(map(int, input().split()))
	b1 = b[0]
	b2 = b[1]
	c = (b1 - 1) // b2 + 1
	print(b2 * c - b1)


n = int(input())

def fon(mini):
	(a, b) = map(int, mini.split())
	c = 0
	if a > b and a % b != 0:
		c = b - a % b
		return c
	elif a % b == 0:
		return '0'
	else:
		return b - a
for i in range(n):
	print(fon(input()))


def main():
	t = int(input())
	for i in range(t):
		(a, b) = [int(z) for z in input().split()]
		if a < b:
			print(b - a)
		else:
			j = a % b
			if j == 0:
				print(0)
			else:
				print(b - j)
main()


for i in range(int(input())):
	(a1, b1) = input().split()
	a = int(a1)
	b = int(b1)
	r = a % b
	if r == 0:
		f = 0
	else:
		f = b - r
	print(f)


int_input_list = lambda : list(map(int, input().split()))
int_input = lambda : int(input())
import math
for _ in range(int_input()):
	(a, b) = int_input_list()
	q = math.ceil(a / b)
	print(b * q - a)


def get_digits(n):
	s = []
	v = 0
	while n:
		s.append(n % 10)
		v += 1
		n //= 10
	return (v, s, sum(s))
cases = int(input())
output = ''
for t in range(cases):
	(n, s) = list(map(int, input().split()))
	(num, dig, sd) = get_digits(n)
	if sd <= s:
		print(0)
	else:
		i = 0
		while sd >= s:
			sd -= dig[i]
			dig[i] = 0
			i += 1
		if i <= num - 1:
			dig[i] += 1
			while dig[i] == 10:
				dig[i] = 0
				if i + 1 <= num - 1:
					dig[i + 1] += 1
				else:
					dig.append(1)
				i += 1
		else:
			dig.append(1)
		dig = int(''.join(map(str, dig[::-1])))
		print(dig - n)


t = int(input())
for _ in range(t):
	(n, s) = [int(p) for p in input().split()]
	li = [int(p) for p in list(str(n))]
	if sum(li) <= s:
		print(0)
		continue
	val = 0
	i = 1
	currSum = sum(li)
	while currSum > s:
		rem = n % 10 ** i
		val += 10 ** i - rem
		n += 10 ** i - rem
		currSum = sum([int(p) for p in list(str(n))])
		i += 1
	print(val)


test = int(input())

def digitsum(n):
	sum = 0
	while int(n) > 0:
		sum += int(n) % 10
		n = int(n) - int(n) % 10
		n = int(n) // 10
	return sum
for i in range(test):
	(n, s) = input().split()
	if digitsum(n) <= int(s):
		print('0')
	elif int(s) <= int(n[0]):
		wynik = '1'
		while int(wynik) < int(n):
			wynik += '0'
		print(int(wynik) - int(n))
	else:
		target = ''
		ss = 0
		tmp = 0
		while int(s) > ss + int(n[tmp]):
			ss += int(n[tmp])
			tmp += 1
			if tmp > len(n) - 1:
				tmp = len(n)
				break
		for i in range(tmp):
			target += str(n[i])
		targett = int(target)
		targett += 1
		targettt = str(targett)
		while int(targettt) < int(n):
			targettt += '0'
		print(int(targettt) - int(n))


n = int(input())
l = []
for i in range(n):
	p = list(map(int, input().split()))
	l += [p]
for i in l:
	if i[0] % i[-1] == 0:
		print(0)
	else:
		q = i[0] // i[-1]
		w = (q + 1) * i[-1]
		e = w - i[0]
		print(e)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	savn = n
	cd = 1
	while cd <= n:
		if sum(map(int, str(n))) <= s:
			break
		cc = n // cd % 10
		if cc == 0:
			cd *= 10
			continue
		n += (10 - cc) * cd
		cd *= 10
	print(n - savn)


import math

class Read:

	@staticmethod
	def string():
		return input()

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(sep=' '):
		return input().split(sep)

	@staticmethod
	def list_int(sep=' '):
		return list(map(int, input().split(sep)))

def solve():
	(a, b) = Read.list_int()
	t = a % b
	print(b - t if t != 0 else 0)
query_count = Read.int()
while query_count:
	query_count -= 1
	solve()


n = int(input())
for i in range(n):
	cnt = 0
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if a % b == 0:
		print(cnt)
	elif a > b:
		print((a // b + 1) * b - a)
	else:
		print(b - a)


import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
for ik in range(int(input())):
	(a, b) = map(int, input().split())
	cop = a
	a = str(a)
	a = list(a)
	n = len(a)
	a = [int(a[i]) for i in range(len(a))]
	a = [0] + a
	su = 0
	t = 0
	n += 1
	if sum(a) <= b:
		print(0)
		continue
	while su < b:
		su += a[t]
		t += 1
	t -= 2
	a[t] += 1
	no = 0
	for i in range(t - 1, -1, -1):
		a[i] += a[i + 1] // 10
	for i in range(n):
		a[i] %= 10
	for i in range(t + 1, n):
		a[i] = 0
	for i in a:
		no = no * 10 + i
	print(no - cop)


def a():
	t = int(input())
	for _ in range(t):
		(a, b) = map(int, input().split())
		if a % b == 0:
			print(0)
		else:
			print(str(b - a % b))
a()


testCases = int(input())
cases = []
for i in range(testCases):
	cases.append(input())
for i in range(testCases):
	txt = cases[i].split(' ')
	a = int(txt[0])
	b = int(txt[1])
	if a % b == 0:
		print('0')
	else:
		result = a % b
		skips = b - result
		print(skips)


for t in range(int(input())):
	(a, b) = map(int, input().split())
	if a <= b:
		print(b - a)
	elif a % b == 0:
		print(0)
	else:
		v = a // b + 1
		print(b * v - a)


tc = int(input())
for i in range(tc):
	s = str(input())
	l = s.split()
	div = int(l[0]) / int(l[1])
	if div % 1 == 0:
		print(0)
	else:
		div = int(div) + 1
		print(div * int(l[1]) - int(l[0]))


t = int(input())

def sumOfDigits(num):
	sum = 0
	while num > 0:
		last = num % 10
		num = num // 10
		sum += last
	return sum
while t > 0:
	(n, s) = input().split(' ')
	n = int(n)
	s = int(s)
	ans = 0
	inc = 0
	while True:
		if sumOfDigits(n) <= s:
			break
		last = n % 10
		ans += 10 ** inc * (10 - last)
		n += 10 - last
		n = n // 10
		inc += 1
	print(ans)
	t -= 1


for s in [*open(0)][1:]:
	(n, s) = s.split()
	m = n
	while sum(map(int, m)) > int(s):
		i = len(m.strip('0'))
		m = str(int(m) + (10 - int(m[i - 1])) * 10 ** (len(m) - i))
	print(int(m) - int(n))


pairs_count = int(input())
for pair_index in range(pairs_count):
	(left_num, right_num) = map(int, input().split())
	if left_num % right_num:
		print(right_num - left_num % right_num)
	else:
		print(0)


t = int(input())

def sum_digits(n):
	summ = 0
	while n:
		summ += n % 10
		n //= 10
	return summ
for _ in range(t):
	(n, s) = map(int, input().split())
	ans = 0
	pow_ten = 10
	for i in range(18):
		if sum_digits(n) > s:
			ans += pow_ten - n % pow_ten
			n += pow_ten - n % pow_ten
			pow_ten *= 10
	print(ans)


t = int(input())
for x in range(t):
	l = [int(x) for x in input().split()]
	rem = l[0] % l[1]
	if rem == 0:
		print(0)
	else:
		print(l[1] - l[0] % l[1])


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	rem = a % b
	res = b - rem
	if a % b == 0:
		print(0)
	else:
		print(res)


import sys
input = lambda : sys.stdin.readline().rstrip()

def zap():
	(a, b) = map(int, input().split())
	if a < b:
		return b - a
	if a % b == 0:
		return 0
	return (a // b + 1) * b - a
for _ in range(int(input())):
	print(zap())


def getSum(n):
	sum = 0
	while n != 0:
		sum += int(n % 10)
		n //= 10
	return sum
t = int(input())
for _ in range(t):
	(n, s) = [int(s) for s in input().split(' ')]
	str_n = str(n)
	if getSum(n) <= s:
		print(0)
	else:
		zeroes = 0
		sum = 0
		j = 0
		for i in range(len(str_n)):
			sum += int(str_n[i])
			if sum >= s:
				break
		number = str_n[i:]
		length = len(number)
		print(10 ** length - int(number))


import math
t = int(input())
for xx in range(t):
	(n, k) = map(int, input().split())
	if n % k == 0:
		print(0)
		continue
	if n > k:
		print((n // k + 1) * k - n)
	else:
		print(k - n)


def divisible(a, b):
	c = 0
	if a % b == 0 and a > b:
		c = 0
	elif a > b:
		rem = a // b
		d = b * (rem + 1)
		f = d - a
		c = f
	elif a < b:
		c = b - a
	print(c)
t = int(input())
while t > 0:
	t -= 1
	(a, b) = map(int, input().split())
	divisible(a, b)


t = int(input())
for iii in range(t):
	(a, b) = map(int, input().split())
	print((b - a % b) % b)


import sys

def main():
	next(sys.stdin)
	for line in sys.stdin:
		(a, b) = tuple(map(lambda x: int(x), line.split()))
		if a % b == 0:
			print(0)
		else:
			m = a // b
			print((m + 1) * b - a)
main()


def func(n):
	for i in range(n):
		k = list(map(int, input().split()))
		print((k[1] - k[0] % k[1]) % k[1])
n = int(input())
func(n)


from math import ceil

def func():
	t = [int(i) for i in input().split()]
	a = t[0]
	b = t[1]
	if a % b == 0:
		print(0)
	else:
		tt = ceil(a / b)
		count = tt * b - a
		print(count)
t = int(input())
for i in range(t):
	func()


t = int(input())
for e in range(t):
	(a, b) = input().split()
	(a, b) = (int(a), int(b))
	if a < b:
		print(b - a)
	elif a % b == 0:
		print(0)
	elif a > b:
		x = a / b
		x = int(x)
		x += 1
		b = b * x
		b = int(b)
		ans = b - a
		print(ans)


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 998244353
EPS = 1e-06

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	(n, s) = input().split()
	ans = [int(i) for i in n]
	s = int(s)
	ans = [0] * (20 - len(n)) + ans
	extra = sum(ans) - s
	for i in range(19, 0, -1):
		if extra > 0:
			extra -= ans[i]
			ans[i] = 0
			ind = i - 1
			while ans[ind] == 9 and ind > 0:
				extra -= ans[ind]
				ans[ind] = 0
				ind -= 1
			ans[ind] += 1
			extra += 1
	new_n = 0
	for i in range(len(ans)):
		new_n = new_n * 10 + ans[i]
	n = int(n)
	print(new_n - n)


t = int(input())
for case_num in range(t):
	(a, b) = map(int, input().split(' '))
	print((b - a % b) % b)


from sys import stdin
import math as m

def main():
	inp = stdin.readline
	for _ in range(int(inp())):
		(a, b) = map(int, inp().split())
		print(b * int(m.ceil(a / b)) - a)
main()


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	c = 0
	if a % b != 0:
		x = a // b
		y = (x + 1) * b
		c = y - a
	print(c)


Q = int(input())
for i in range(Q):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
		continue
	ct = a // b
	ans = (ct + 1) * b - a
	print(ans)


for _ in range(int(input())):
	(n, s) = list(map(int, input().split()))
	ns = str(n)
	na = [0]
	sum = 0
	for i in range(len(ns)):
		a = int(ns[i])
		sum += a
		na.append(a)
	if sum <= s:
		print(0)
		continue
	d = 1
	moves = 0
	for i in range(len(na) - 1, 0, -1):
		moves += (10 - na[i]) * d
		d *= 10
		sum -= na[i]
		sum += 1
		na[i - 1] += 1
		if sum <= s:
			print(moves)
			break


for x in range(int(input())):
	n = input().split()
	a = int(n[0])
	b = int(n[1])
	if a % b == 0:
		print(0)
	else:
		num = int(a / b + 1)
		print(b * num - a)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	digit = [0, 0, 0, 0, 0]
	s = str(a)
	for i in s:
		digit.append(int(i))
	isum = sum(digit)
	if isum <= b:
		print(0)
		continue
	moves = 0
	mul = 1
	for i in reversed(range(len(digit))):
		if digit[i] == 0:
			mul = mul * 10
			continue
		else:
			isum -= digit[i]
			digit[i - 1] += 1
			moves += mul * (10 - digit[i])
			digit[i] = 0
			isum += 1
		if isum <= b:
			break
		mul = mul * 10
	print(moves)


import math
n = int(input())
for i in range(n):
	pole = input().split()
	dividend = math.ceil(int(pole[0]) / int(pole[1]))
	dividend = dividend * int(pole[1])
	print(dividend - int(pole[0]))


import sys
input = sys.stdin.readline
t = int(input())
for t1 in range(t):
	(n, s) = list(map(int, input().split(' ')))
	su = s
	z = str(n)
	z = '0' + z
	o = n
	ans = 0
	for i in z:
		ans += int(i)
	w = 0
	if ans <= s:
		print(0)
	else:
		count = 0
		for i in range(len(z)):
			count += int(z[i])
			if count >= s:
				a = '1' + (len(z) - i) * '0'
				a = int(a)
				org = len(z)
				n += a
				after = len(str(n))
				if after != org:
					n = '0' + str(n)
				x = str(n)
				x = x[:i] + '0' * (len(z) - i)
				w = x
				break
		w = int(w)
		print(w - o)


def get_div(n, r):
	c = n % r
	return r - c if c != 0 else 0
t = int(input())
for _ in range(t):
	(n, r) = [int(x) for x in input().split()]
	print(get_div(n, r))


import math
for t in range(int(input())):
	[a, b] = list(map(int, input().split()))
	num = math.ceil(a / b)
	ans = num * b
	print(ans - a)


t = int(input())
for _ in range(t):
	(a, b) = [int(i) for i in input().split()]
	c = a % b
	print(abs(a - (a - b + c if c else a)))


exec(int(input()) * 's,r=map(int,input().split());print((r-s%r)%r);')


def f1():
	import math as m
	T = int(input())
	while T != 0:
		T = T - 1
		Array = [int(i) for i in input().split(' ')]
		A = Array[0]
		B = Array[1]
		Mult = m.ceil(A / B)
		print(B * Mult - A)
f1()


def check(n):
	temp = n
	res = 0
	while temp:
		res += temp % 10
		temp = temp // 10
	return res
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	start = n
	cur = 1
	flag = True
	while flag:
		d = n % cur
		if d != 0:
			n += cur - d
		if check(n) <= s:
			print(n - start)
			flag = False
			break
		cur = cur * 10


def sum1(a, b):
	s = str(a)
	r = 0
	index = 0
	for i in s:
		if r + int(i) >= b:
			return index
		r += int(i)
		index += 1
	return -1

def sum2(a):
	s = str(a)
	r = 0
	for i in s:
		r += int(i)
	return r
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	s = sum2(a)
	if s > b:
		index = sum1(a, b)
		k = len(str(a)) - index
		if index == 0:
			print(10 ** k - a)
		else:
			abc = int(str(int(str(a)[:index]) + 1) + (len(str(a)) - index) * '0')
			print(abc - a)
	else:
		print(0)


import math
t = int(input())
while t > 0:
	(a, b) = map(int, input().split())
	if b > a:
		print(b - a)
	elif a % b == 0:
		print(0)
	else:
		print(int(b * (math.modf(a / b)[1] + 1) - a))
	t -= 1


def main():
	(a, b) = [int(i) for i in input().split()]
	ans = b - a % b
	if ans == b:
		ans = 0
	return ans
for i in range(int(input())):
	print(main())


def divisibler(n, d):
	mod = n % d
	if mod == 0:
		return 0
	prev = n - mod
	prev += d
	prev -= n
	return prev
t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	res = divisibler(n, d)
	print(res)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())

	def div(a, b):
		for j in range(b):
			if a % b == 0:
				return '0'
			else:
				return b - a % b
	print(div(a, b))


t = int(input())
ls = []
for i in range(t):
	(a, b) = map(int, input().split())
	if a >= b and a % b == 0:
		rs = 0
	else:
		c = a // b
		c = (c + 1) * b
		rs = c - a
	ls.append(rs)
for o in ls:
	print(o)


t = int(input())
for case in range(t):
	(a, b) = map(int, input().split())
	print((b - a % b) % b)


a = int(input().strip())
s = 0
d = 0
e = 0
for i in range(a):
	(n, m) = map(int, input().split())
	if n % m == 0:
		print('0')
	else:
		print(m - n % m)


test_case = int(input())
for i in range(test_case):
	val = list(map(int, input().split(' ')))
	if val[0] % val[1] == 0:
		print(0)
		continue
	else:
		res = val[1] - val[0] % val[1]
		print(res)


t = int(input())
for i in range(t):
	(ad, bd) = list(map(int, input().split()))
	if ad % bd == 0:
		print(0)
	else:
		print(bd - ad % bd)


def summ(n: int) -> int:
	sn = str(n)
	s = 0
	for i in range(len(sn)):
		s += int(sn[i])
	return s
t = int(input())
for _ in range(t):
	(n, k) = [int(i) for i in input().split()]
	if summ(n) <= k:
		print(0)
	else:
		ind = 0
		ans = 0
		while summ(n) > k:
			cur = str(n)[::-1][ind]
			dif = (10 - int(cur)) % 10
			ans += dif * 10 ** ind
			n += dif * 10 ** ind
			ind += 1
		print(ans)


testcases = int(input())
for testcase in range(testcases):
	temparr = input()
	temparr = temparr.split()
	a = temparr[0]
	a = a[::-1]
	b = int(temparr[1])
	arr = []
	for i in a:
		arr.append(int(i))
	arr.append(0)
	ans = []
	cursum = sum(arr)
	if cursum <= b:
		print(0)
		continue
	nn = len(arr)
	carry = 0
	for i in range(nn - 1):
		if arr[i] == 0:
			ans.append('0')
			continue
		else:
			diff = 10 - arr[i]
			ans.append(str(diff))
			arr[i] = 0
			j = i + 1
			arr[i + 1] += 1
			while j < nn:
				if arr[j] == 10:
					arr[j] = 0
					arr[j + 1] += 1
					j += 1
					continue
				else:
					break
		cursum = sum(arr)
		if cursum <= b:
			break
	ans = ans[::-1]
	print(''.join(ans))


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n % k == 0:
		print('0')
	else:
		print(k - n % k)


t = int(input())
for _ in range(t):
	(a, b) = [int(x) for x in input().split()]
	c = 0
	if a < b:
		print(b - a)
		continue
	if a % b == 0:
		print(0)
		continue
	else:
		print(b - a % b)


from sys import stdin, stdout
from math import gcd, log2, log10, floor
import math
from collections import defaultdict
input = stdin.readline

def sumof(n):
	suma = 0
	while n:
		suma += n % 10
		n //= 10
	return suma
for i in range(int(input())):
	(n, s) = map(int, input().split())
	answer = 0
	m = 1
	count = 0
	while sumof(n + answer) > s:
		m *= 10
		answer = m - n % m
	print(answer)


n = int(input())
for i in range(0, n):
	(x, y) = [int(a) for a in input().split()]
	if x >= y:
		if x % y != 0:
			f = x // y
			d = (f + 1) * y - x
		else:
			d = 0
	else:
		d = y - x
	print(d)


def divi(a, b):
	if b >= a:
		return b - a
	mod = a % b
	if mod == 0:
		return 0
	return b - mod
t = int(input())
l = []
for i in range(t):
	l.append(divi(*list(map(int, input().split(' ')))))
for i in range(t):
	print(l[i])


from sys import stdin
N = int(stdin.readline())
for case in range(N):
	(x, y) = map(int, stdin.readline().split())
	if x % y == 0:
		print(0)
	else:
		print(y - x % y)


t = int(input())
d = []
for i in range(t):
	n = list(map(int, input().split()))
	d.append(n)
for j in range(t):
	a = d[j][0]
	b = d[j][1]
	if a == b:
		print(0)
	elif a % b == 0:
		print(0)
	else:
		print(b - a % b)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
for idx in range(0, t):
	[a, b] = invr()
	if a % b == 0:
		print(0)
	else:
		print(b * (int(a / b) + 1) - a)


def dos(n):
	return sum(n)
for _ in range(int(input())):
	(n, s) = [int(i) for i in input().split()]
	a = list(map(int, str(n)))[::-1]
	a += [0]
	ans = 0
	if dos(a) <= s:
		print(0)
		continue
	for i in range(len(a) - 1):
		d = a[i]
		a[i] = 0
		ans += 10 ** i * (10 - d)
		a[i + 1] += 1
		temp = dos(a)
		if temp == s:
			break
		if temp < s:
			dif = s - temp
			a[i] = d - dif
			break
	print(ans)


from sys import stdin, stdout
test = int(stdin.readline())
for _ in range(test):
	(n, s) = map(int, stdin.readline().split())
	n = [int(x) for x in list(str(n))]
	n = n[::-1]
	if sum(n) <= s:
		print(0)
		continue
	ans = 0
	sm = sum(n)
	for i in range(len(n)):
		if sm <= s:
			break
		if n[i] == 0:
			continue
		ans += (10 - n[i]) * 10 ** i
		n[i] = 0
		if i != len(n) - 1:
			n[i + 1] += 1
		sm = sum(n)
	print(ans)


import math
t = int(input())
for test in range(t):
	(a, b) = [int(x) for x in input().split()]
	x = a / b
	if x == a // b:
		print(0)
		continue
	else:
		y = abs(a - b * math.ceil(a / b))
		print(int(y))


import sys
inputlist = sys.stdin.readlines()
number_of_testcases = int(inputlist[0].strip())
for i in range(number_of_testcases):
	(a, b) = list(map(int, inputlist[i + 1].strip().split(' ')))
	modresult = a % b
	if modresult == 0:
		print(modresult)
	else:
		print(b - modresult)


from math import *
from sys import *
t = int(stdin.readline())
for i in range(t):
	(a, b) = map(int, stdin.readline().split())
	x = b - a % b
	if a % b == 0:
		x = 0
	print(x)


t_cases = int(input())
a_and_b = []
for _ in range(t_cases):
	a_and_b.append(tuple(map(int, input().split())))
for (a, b) in a_and_b:
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


t = int(input())
while t > 0:
	ab = input().split()
	a = int(ab[0])
	b = int(ab[1])
	if a >= b:
		c = float(a % b)
		if c == 0:
			print(int(c))
		else:
			f = float(a / b)
			d = int(f)
			e = b * (d + 1)
			print(e - a)
	else:
		print(b - a)
	t -= 1


t = int(input())
a = []
for i in range(t):
	a.append(list(map(int, input().split()[:2])))

def chk(a, b):
	if a % b == 0:
		return 0
	if a > b:
		return b - a % b
	else:
		return b - a
for i in a:
	print(chk(i[0], i[1]))


MOD = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
from collections import *
for _ in range(ii()):
	(a, b) = f()
	c = 0
	if a == b:
		print(0)
	if b > a:
		print(b - a)
	if a > b:
		if a % b == 0:
			print(0)
		else:
			print(b - a % b)


def solution():
	from sys import stdout, stdin
	(_input, _print) = (stdin.readline, stdout.write)
	for _ in range(int(input())):
		(a, b) = [int(i) for i in input().split()]
		if a % b == 0:
			print(0)
		else:
			print(b - a % b)
solution()


import math, collections, heapq
testcase = int(input())
for _ in range(testcase):
	(a, b) = map(int, input().split())
	c = a % b
	if c == 0:
		print(0)
	else:
		print(b - c)


t = int(input())
cases = []
for i in range(t):
	inp = input().split()
	a = int(inp[0])
	b = int(inp[1])
	cases.append([a, b])
for i in range(t):
	a = cases[i][0]
	b = cases[i][1]
	r = int(a / b)
	if a / b == r:
		print(0)
	else:
		r = r + 1
		print(b * r - a)


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def input():
	return sys.stdin.readline().strip()
mod = 10 ** 9 + 7
for _ in range(int(input())):
	(a, b) = get_ints()
	if a % b == 0:
		print(0)
		continue
	if a % b != 0:
		val = (a // b + 1) * b
		diff = val - a
	print(diff)


for _ in range(int(input())):
	(n, total) = map(int, input().split())
	s = list(str(n)[::-1])
	for i in range(len(s)):
		s[i] = int(s[i])
	val = sum(s)
	if val <= total:
		print(0)
		continue
	if total <= s[-1]:
		val = 10 ** len(s) - n
		print(val)
		continue
	i = len(s) - 1
	total_so_far = s[i]
	while i > 0 and total_so_far < total:
		i -= 1
		total_so_far += s[i]
	i += 1
	val = 0
	j = i - 1
	while j > -1:
		val *= 10
		val += s[j]
		j -= 1
	print(10 ** i - val)


t = int(input())
while t:
	t -= 1
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if a % b == 0:
		print(0)
	elif a <= b:
		print(b - a)
		continue
	else:
		print(b - a % b)


def nod(a, b):
	while a != b:
		(a, b) = (max(a, b), min(a, b))
		if a % b == 0:
			a -= (a // b - 1) * b
		else:
			a -= a // b * b
	return a
for i in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	if a % b == 0:
		print(0)
	else:
		print((a // b + 1) * b - a)


import math
t = int(input())
list = []
for n in range(1, t + 1):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	list.append(-a + b * math.ceil(a / b))
for n in list:
	print(n)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	value = sum(map(int, str(n)))
	p = 10
	ans = 0
	while value > s:
		v = n % p
		ans += p - v
		n += p - v
		p *= 10
		value = sum(map(int, str(n)))
	print(ans)


def solve():
	(n, s) = input().split()
	s = int(s)
	sd = sum(list(map(int, n)))
	ans = 0
	point = 0
	a = int(n)
	n = n[::-1]
	debug = 0
	while s < sd:
		a += 10 ** point * (10 - int(n[point]))
		ans += 10 ** point * (10 - int(n[point]))
		point += 1
		n = str(a)[::-1]
		sd = sum(list(map(int, n)))
	print(ans)
t = int(input())
for i in range(t):
	solve()


for i in range(int(input())):
	f = input().split()
	print((int(f[1]) - int(f[0]) % int(f[1])) % int(f[1]))


t = int(input())
for i in range(t):
	(a, b) = list(map(int, input().split()))
	c = a % b
	n = (b - c) % b
	print(n)


n = int(input())
for i in range(n):
	k = 0
	(a, b) = map(lambda x: int(x), input().split())
	c = a % b
	if a < b:
		print(b - a)
	elif c == 0:
		print(0)
	else:
		print(b - c)


import sys, math, heapq, copy
from collections import defaultdict, deque
from bisect import bisect_left, bisect_right
from functools import cmp_to_key

def fun(n):
	res = 0
	while n:
		res += n % 10
		n //= 10
	return res
t = int(input())
for _ in range(t):
	(n, s) = map(int, input().split())
	if fun(n) <= s:
		print(0)
	else:
		x = 1
		ans = 0
		for i in range(18):
			res = n // x % 10
			add = x * ((10 - res) % 10)
			n += add
			ans += add
			if fun(n) <= s:
				break
			x *= 10
		print(ans)


import sys
import math
tests = int(input())

def DigitSum(n):
	s = 0
	while n > 0:
		s += n % 10
		n = n // 10
	return s

def inc(x):
	tens = 1
	while x % 10 == 0:
		tens *= 10
		x = x // 10
	return tens * (10 - x % 10)
for i in range(tests):
	(n, s) = [int(i) for i in input().split()]
	x = n
	while DigitSum(x) > s:
		x += inc(x)
	print(x - n)


case = int(input())
for i in range(0, case):
	(x, y) = [int(x) for x in input().split()]
	difference = x % y
	if difference == 0:
		difference = y
	print(y - difference)


def integer(array):
	for i in range(len(array)):
		array[i] = int(array[i])
	return array
N = int(input())
inputs = []
for i in range(N):
	inputs.append(integer(str(input()).split(' ')))

def div(a, b):
	if a % b == 0:
		return 0
	else:
		return b - a % b
for i in inputs:
	print(div(i[0], i[1]))


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	rem = a % b
	if rem == 0:
		print(0)
		continue
	else:
		print(b - rem)


def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def main():
	for t in range(inp()):
		l = inlt()
		if l[0] % l[1] == 0:
			print('0')
		elif l[0] < l[1]:
			print(-(l[0] - l[1]))
		else:
			r = l[0] / l[1]
			r = round(r) * l[1]
			while r <= l[0]:
				r += l[1]
			print(r - l[0])
	return

def lcm(a, b):
	return abs(a * b)
main()


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a < b:
		print(b - a, flush=True)
	else:
		q = a // b
		r = a % b
		if r == 0:
			print(0, flush=True)
		else:
			ans = (q + 1) * b - a
			print(ans, flush=True)


import math

def sum_of_dig(n):
	ans = 0
	n = str(n)
	for i in range(len(n)):
		ans += int(n[i])
	return ans
for t in range(int(input())):
	(n, m) = map(int, input().split())
	count = 0
	power = 1
	while sum_of_dig(n) > m:
		last__n_dig = n % 10 ** power
		diff = 10 ** power - last__n_dig
		n += diff
		count += diff
		power += 1
	print(count)


def main():
	t = int(input())
	while t != 0:
		lst = list(map(int, input().strip().split()))
		a = lst[0]
		b = lst[1]
		if a % b == 0:
			print('0')
		else:
			res = b - a % b
			print(res)
		t -= 1
main()


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlst():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def solve(n, s):
	d = list(map(int, str(n)))
	d.insert(0, 0)
	if sum(d) <= s:
		return 0
	for i in range(len(d) - 1, 0, -1):
		if sum(d[:i]) + 1 <= s:
			target = d[:]
			for j in range(i, len(d) - 1):
				target[j] = 0
			target[i - 1] = (target[i - 1] + 1) % 10
			if target[i - 1] == 0:
				target[i - 2] += 1
			break
	t = 0
	for i in range(0, len(d) - 1):
		t += target[i] * pow(10, len(d) - 1 - i)
	return t - n
n = inp()
for _ in range(n):
	(n, s) = invr()
	print(solve(n, s))


def divisibility(a, b):
	if a % b == 0:
		return 0
	return b - a % b
t = int(input())
for i in range(1, t + 1):
	(a, b) = [int(s) for s in input().split(' ')]
	h = divisibility(a, b)
	print(h)


i = int(input())
for x in range(i):
	s = input().split()
	a = int(s[0])
	b = int(s[1])
	if a < b:
		print(b - a)
	elif a % b == 0:
		print(0)
	else:
		print(int(s[1]) - int(s[0]) % int(s[1]))


t = int(input())
for _ in range(t):
	(n, s) = map(int, input().split())
	m = str(n)
	t = 0
	for i in range(len(m)):
		t += int(m[i])
	if t <= s:
		print(0)
	else:
		temp = 0
		m = list(m)
		m.reverse()
		m = [int(d) for d in m]
		m.append(0)
		m.append(0)
		cnt = 0
		for i in range(len(m)):
			cnt += (10 - m[i]) * 10 ** i
			if i != len(m) - 1:
				temp += m[i] - 1
				m[i + 1] += 1
			else:
				temp += m[i] - 1
			if temp >= t - s:
				print(cnt)
				break
		else:
			ans = 10 ** len(m) - n
			print(ans)


def digit(n):
	res = 0
	for i in str(n):
		res += int(i)
	return res
t = int(input())
while t > 0:
	(n, s) = map(int, input().split(' '))
	var = 0
	if digit(n) <= s:
		print(0)
		t -= 1
		continue
	n = str(n)
	x = 1
	for i in n:
		if var + int(i) >= s:
			break
		var += int(i)
		x += 1
	if x == 0:
		d = '0' * len(n)
		f = '1' + d
		print(int(n) - int(f))
		t -= 1
		continue
	y = len(n[x - 1:])
	k = n[:x - 1]
	if k == '':
		ans = '1' + '0' * y
	else:
		ans = str(int(k) + 1) + '0' * y
	print(int(ans) - int(n))
	t -= 1


def answer():
	n = int(input())
	ans = []
	while n:
		c = input().split()
		(a, b) = (int(c[0]), int(c[1]))
		if a % b:
			ans.append(b - a % b)
		else:
			ans.append(0)
		n -= 1
	i = 0
	while i < len(ans):
		print(ans[i])
		i += 1
answer()


def calSum(n):
	x = 0
	while n != 0:
		x += n % 10
		n //= 10
	return x
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	orig = n
	sm = calSum(orig)
	if sm <= s:
		print(0)
	else:
		count = 1
		while sm > s:
			w = n % 10 ** count
			n += 10 ** count - w
			sm = calSum(n)
			count += 1
		print(n - orig)


N = int(input())
ab = []
for n in range(N):
	(a, b) = (int(i) for i in input().split())
	ab.append((a, b))
for (a, b) in ab:
	mod = a % b
	ans = b - mod if mod != 0 else 0
	print(ans)


def divisible(a, b):
	return b - a % b if a % b > 0 else 0
testcases = int(input())
for i in range(1, testcases + 1):
	data = tuple(map(int, input().split()))
	print(divisible(data[0], data[1]))


import math
T = int(input())
for t in range(T):
	(a, b) = [int(i) for i in input().split(' ')]
	print(math.ceil(a / b) * b - a)


x = int(input())
lst = []
for i in range(0, x):
	(y, z) = input().split()
	(y, z) = (int(y), int(z))
	c = y % z
	if c == 0:
		lst.append(0)
	else:
		lst.append(z - c)
print(*lst, sep='\n')


t = int(input())

def summ(ss):
	s1 = 0
	while ss > 0:
		s1 += ss % 10
		ss = ss // 10
	return s1

def last(s, n):
	return int(s[len(s) - n:])
while t > 0:
	(s, n) = [int(x) for x in input().split()]
	s1 = summ(s)
	if s1 <= n:
		print(0)
	elif s1 > n:
		add = 10
		k = 1
		while s1 > n:
			s1 = summ(s + add - last(str(s), k))
			if s1 <= n:
				break
			add *= 10
			k += 1
		print(add - last(str(s), k))
	t -= 1


from sys import stdin, stdout
t = int(stdin.readline().strip())
for _ in range(t):
	(a, b) = list(map(int, stdin.readline().strip().split()))
	if a % b == 0:
		stdout.write('0' + '\n')
	else:
		k = int(a / b) + 1
		d = k * b - a
		stdout.write(str(d) + '\n')


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7

def digit_sum(n):
	ans = 0
	while n > 0:
		ans += n % 10
		n //= 10
	return ans
for _ in range(INT()):
	(N, s) = MAP()
	dsm = digit_sum(N)
	if dsm <= s:
		print(0)
		continue
	A = list(map(int, str(N)))[::-1]
	M = len(A)
	for i in range(M - 1):
		if A[i] == 0:
			continue
		dsm += 1 - A[i]
		A[i] = 0
		A[i + 1] += 1
		if dsm <= s:
			break
	for i in range(M - 1):
		if A[i] == 10:
			dsm += 1 - A[i]
			A[i] = 0
			A[i + 1] += 1
	if A[-1] == 10:
		dsm += 1 - A[-1]
		A[-1] = 0
		A.append(1)
	while dsm > s:
		dsm += 1 - A[-1]
		A[-1] = 0
		A.append(1)
	L = int(''.join(map(str, A[::-1])))
	ans = L - N
	print(ans)


test_count = int(input())
for t in range(test_count):
	(a, b) = map(int, input().split())
	if a <= b:
		print(b - a)
	else:
		rem = a % b
		if rem == 0:
			print(0)
		else:
			print(b - rem)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	digits = []
	while n > 0:
		digits.append(n % 10)
		n //= 10
	result = 0
	cur_sum = 0
	cur = len(digits) - 1
	while cur >= 0 and cur_sum <= s:
		cur_sum += digits[cur]
		cur -= 1
	cur += 1
	while cur_sum > s:
		cur_sum -= digits[cur]
		cur_sum += 1
		n_sum = 0
		for (i, x) in enumerate(digits[0:cur + 1]):
			n_sum += x * 10 ** i
			digits[i] = 0
		result += 10 ** (cur + 1) - n_sum
		cur += 1
		if cur >= len(digits):
			digits.append(1)
		elif digits[cur] != 9:
			digits[cur] += 1
		else:
			while digits[cur] == 9:
				digits[cur] = 0
				cur_sum -= 9
				cur += 1
				if cur >= len(digits):
					digits.append(1)
	print(result)


t = int(input())
for i in range(t):
	(n, s) = map(int, input().split())
	pn = n
	tn = []
	while n:
		(n, a) = divmod(n, 10)
		tn.append(a)
	tn.append(0)

	def cal(p):
		tn[p] = 0
		tn[p + 1] += 1
		for d in range(p + 1, 100000000):
			if tn[d] == 10:
				tn[d] = 0
				tn[d + 1] += 1
			else:
				break
		return sum(tn) <= s
	if sum(tn) <= s:
		print(0)
		continue
	for j in range(0, 100000):
		if cal(j):
			print(int(''.join(map(str, tn[::-1]))) - pn)
			break


t = int(input())
h = []
s = 0
for i in range(t):
	s = 0
	(a, b) = map(int, input().split())
	if a % b == 0:
		pass
	else:
		s = b - a % b
	h.append(s)
for i in h:
	print(i)


n = int(input())
x = []
for i in range(n):
	(a, b) = map(int, input().split())
	if a % b == 0:
		x.append(0)
	elif a > b:
		x.append(b - a % b)
	else:
		x.append(b - a)
for elm in x:
	print(elm)


t = int(input())
for _ in range(t):
	(a, b) = (int(x) for x in input().split())
	print((b - a % b) % b)


def sumcal(x):
	s = 0
	while x:
		s += x % 10
		x //= 10
	return s
for _ in range(int(input())):
	(n, s) = list(map(int, input().split()))
	i = n
	b = 10
	while sumcal(n) > s:
		n += b - n % b
		b *= 10
	print(n - i)


for _ in range(int(input())):
	(n, s) = [int(i) for i in input().split()]
	num = str(n)
	sum = 0
	for i in num:
		sum += int(i)
	i = -1
	ans = 0
	while sum > s:
		x = int(num[i])
		temp = 10 - x
		temp = temp * 10 ** (abs(i) - 1)
		ans += temp
		n += temp
		num = str(n)
		t = 0
		for j in num:
			t += int(j)
		sum = t
		i -= 1
	print(ans)


import math
t = int(input())
r = []
for x in range(0, t):
	r.append(input().split())
for i in range(0, len(r)):
	a = int(r[i][0])
	b = int(r[i][1])
	answer = b * math.ceil(a / b) - a
	print(answer)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a < b:
		ans = b - a
	else:
		v = (10 ** 9 + 1) * b
		c = v - a
		ans = int(c % b)
	print(ans)


def move(a, b):
	x = a % b
	if x == 0:
		print(0)
	else:
		print(b - x)
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	move(a, b)


t = int(input())
out = []
while t != 0:
	(a, b) = input().split(' ')
	a = int(a)
	b = int(b)
	z = int(0)
	if a % b == 0:
		out.append(0)
	else:
		out.append(b - a % b)
	t -= 1
print(*out, sep='\n')


def calc(n):
	ans = 0
	for i in n:
		ans += int(i)
	return ans
for nt in range(int(input())):
	(n, s) = input().split()
	s = int(s)
	f = calc(n)
	if f <= s:
		print(0)
		continue
	n = n[::-1]
	if n[0] == '0':
		ans = [0]
		flag = 0
		diff = f - s
	else:
		ans = [10 - int(n[0])]
		flag = 1
		diff = f - s - int(n[0])
	for i in range(1, len(n)):
		x = int(n[i])
		if flag:
			x += 1
			diff += 1
		if diff <= 0:
			break
		if x == 0:
			flag = 0
			diff -= int(n[i])
			ans.append(0)
			continue
		flag = 1
		ans.append(10 - x)
		diff -= x
	new = []
	flag = 0
	for i in ans[::-1]:
		if i != 0 or (i == 0 and flag):
			flag = 1
			new.append(i)
		else:
			continue
	print(''.join(map(str, new)))


def answer(a, b):
	if a % b == 0:
		return 0
	return (a // b + 1) * b - a
testCount = int(input())
for _ in range(testCount):
	(a, b) = map(int, input().split())
	print(answer(a, b))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b != 0:
		temp1 = a % b
		temp2 = a - temp1
		print(temp2 + b - a)
	else:
		print(0)


def myfun(x, y):
	if x % y == 0:
		print(0)
	else:
		print(y - x % y)
t = int(input())
mov = 0
for i in range(t):
	liste = input().split()
	myfun(int(liste[0]), int(liste[1]))


def modify(l, p):
	s = list(l)
	for i in range(p, len(s)):
		s[i] = '0'
	p -= 1
	ok = 1
	while p >= 0:
		if s[p] == '9' and ok == 1:
			s[p] = '0'
		else:
			if ok == 1:
				s[p] = chr(ord(s[p]) + 1)
			else:
				s[p] = s[p]
			ok = 0
		p -= 1
	if s[0] == '0':
		return '1' + ''.join(s)
	return ''.join(s)

def tc():
	(sn, ss) = [x for x in input().split(' ')]
	n = int(sn)
	s = int(ss)
	suf = [0] * len(sn)
	j = len(sn) - 2
	while j >= 0:
		suf[j] = max(suf[j + 1], ord(sn[j + 1]) - ord('0'))
		j -= 1
	cur = 0
	for i in range(len(sn)):
		cur += ord(sn[i]) - ord('0')
		if cur + 1 > s and suf[i] > 0:
			sn = modify(sn, i)
			break
		if cur > s:
			sn = modify(sn, i)
			break
	print(int(sn) - n)
t = int(input())
for _ in range(t):
	tc()


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def get_str():
	return input().decode().strip()

def rint():
	return map(int, input().split())

def oint():
	return int(input())
t = oint()
for _ in range(t):
	(a, b) = rint()
	r = a % b
	print((b - r) % b)


num_cases = int(input())
for t in range(num_cases):
	(a, b) = [int(i) for i in input().split()]
	if a < b:
		print(b - a)
	elif a > b and a % b != 0:
		print(b - a % b)
	else:
		print(0)


import math
for t in range(int(input())):
	(a, b) = map(int, input().split())
	c = a // b
	if a % b == 0:
		print(0)
	elif b > a:
		print(b - a)
	else:
		print(abs(min(a - b * c, a - b * (c + 1))))


import bisect
import collections
import functools
import itertools
import math
import heapq
import random
import string

def repeat(_func=None, *, times=1):

	def decorator(func):

		@functools.wraps(func)
		def wrapper(*args, **kwargs):
			for _ in range(times):
				func(*args, **kwargs)
		return wrapper
	if _func is None:
		return decorator
	else:
		return decorator(_func)

def unpack(func=int):
	return map(func, input().split())

def l_unpack(func=int):
	return list(map(func, input().split()))

def s_unpack(func=int, rev=False):
	return sorted(map(func, input().split()), reverse=rev)

def ml_unpack(n):
	return [int(input()) for _ in range(n)]

def range_n():
	return range(int(input()))

def getint():
	return int(input())

def factor(n):
	d = {}
	while not n % 2:
		d[2] = d.get(2, 0) + 1
		n //= 2
	i = 3
	while i * i <= n:
		while not n % i:
			d[i] = d.get(i, 0) + 1
			n //= i
		i += 2
	if n > 1:
		d[n] = d.get(n, 0) + 1
	return d

def get_sum(a):
	ans = 0
	n = len(a)
	for i in range(n):
		ans += (i - (n - i - 1)) * a[i]
	return ans

def digitsum(n):
	ans = 0
	while n:
		ans += n % 10
		n //= 10
	return ans

@repeat(times=getint())
def main():
	(n, s) = unpack()
	m = n
	k = digitsum(n)
	if k <= s:
		print(0)
	else:
		cnt = 0
		while k >= s:
			n //= 10
			cnt += 1
			k = digitsum(n)
		n += 1
		k = digitsum(n)
		while k > s:
			n //= 10
			cnt += 1
			k = digitsum(n)
		n = int(str(n) + '0' * cnt)
		print(n - m)
main()


def Stepsneeded(a, b):
	if a % b == 0:
		return 0
	elif a > b:
		s = a // b + 1
		return b * s - a
	else:
		return b - a
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	print(Stepsneeded(a, b))


t = int(input())
l = 0
for i in range(t):
	k = input().split(' ')
	a = int(k[0])
	b = int(k[1])
	if b > a:
		print(b - a)
	elif a % b == 0:
		print(0)
	else:
		lol = a // b
		lul = b * (lol + 1)
		print(lul - a)


def divisible(a, b):
	if a % b == 0:
		return 0
	power = a // b + 1
	return b * power - a

def main():
	n = int(input())
	ans = []
	for i in range(n):
		(a, b) = list(map(int, input().split(' ')))
		ans.append(divisible(a, b))
	for i in ans:
		print(i)
main()


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	if n % m == 0:
		print('0')
	else:
		a = n // m
		b = m * (a + 1)
		print(int(b - n))


t = int(input())
resultList = []
while t > 0:
	(a, b) = [int(i) for i in input().split()]
	if b > a:
		moves = b - a
	elif a % b == 0:
		moves = 0
	else:
		moves = b - a % b
	resultList.append(moves)
	t -= 1
for result in resultList:
	print(result)


t = int(input())
while t != 0:
	(m, n) = map(int, input().split())
	q = m / n
	r = m % n
	if r == 0:
		ans = 0
	else:
		new = (int(q) + 1) * n
		ans = new - m
	print(ans)
	t -= 1


from math import ceil, floor, log, sqrt, factorial
for _ in range(int(input())):
	(n, s) = input().split()
	s = int(s)
	n = list(map(int, list(n)))
	n.reverse()
	n.append(0)
	n.reverse()
	if sum(n) <= s:
		print(0)
	else:
		c = 0
		for i in range(len(n) - 1, -1, -1):
			if n[i]:
				p = 10 - n[i]
				n[i] = 0
				n[i - 1] += 1
				c += p * 10 ** (len(n) - 1 - i)
			if sum(n) <= s:
				break
		print(c)


def to_list(s):
	return list(map(lambda x: int(x), s.split(' ')))

def solve(a, b):
	residue = a % b
	if residue == 0:
		return '0'
	else:
		return str(b - residue)
t = int(input())
answers = []
for i in range(t):
	(a, b) = to_list(input())
	answers.append(solve(a, b))
print('\n'.join(answers))


k = int(input())

def sum_digits(n):
	s = 0
	while n > 0:
		s += n % 10
		n //= 10
	return s
for _ in range(k):
	(n, s) = map(int, input().strip().split(' '))
	m = 0
	r = 1
	while sum_digits(n) > s:
		d = 10 - n % 10
		n += d
		m += d * r
		r *= 10
		n //= 10
	print(m)


t = int(input())
x = 0
while t > 0:
	t -= 1
	a = input().split()
	a = list(map(int, a))
	x = a[0] // a[1] * a[1]
	if x < a[0]:
		x += a[1]
	print(x - a[0])


t = int(input())
for i in range(t):
	(s, m) = [int(s) for s in input().split()]
	s = str(s)
	sumi = 0
	for i in range(len(s)):
		sumi = sumi + int(s[i])
		if sumi >= m:
			answer = int(s[i:])
			answer = int('1' + (len(s) - i) * '0') - answer
			break
	sumi = 0
	for i in range(len(s)):
		sumi = sumi + int(s[i])
	if sumi <= m:
		print(0)
	else:
		print(answer)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	a = [int(i) for i in str(n)]
	ans = 0
	i = 0
	if sum(a) <= s:
		print(0)
		continue
	while ans < s and i < len(a):
		ans += a[i]
		i += 1
	b = []
	for j in range(i - 1, len(a)):
		b.append(a[j])
	c = ''.join((str(i) for i in b))
	d = 10 ** len(c)
	print(d - int(c))


def sum_digits(n):
	sw = 0
	while n:
		sw += n % 10
		n //= 10
	return sw
for _ in range(int(input())):
	(n, s) = list(map(int, input().split()))
	d = list(map(int, str(n)))
	if sum(d) <= s:
		print(0)
		continue
	su = 0
	new = []
	pl = 0
	for i in range(len(d)):
		su += d[i]
		if su >= s:
			new = int(''.join(map(str, d[:i + 1])))
			pl = '0' * (len(d) - i - 1)
			break
	new += 1
	while sum_digits(new) > s:
		new += 1
	print(int(str(new) + pl) - n)


def sum(n):
	res = 0
	for c in n:
		res += int(c)
	return res
t = int(input())
for i in range(t):
	q = input().split()
	n = [int(x) for x in q[0]]
	s = int(q[1])
	res = 0
	i = len(n) - 1
	while sum(n) > s:
		res += (10 - int(n[i])) * 10 ** (len(n) - i - 1)
		n[i] = '0'
		j = i - 1
		while j > -1 and n[j] == 9:
			n[j] = '0'
			j -= 1
		if j > -1:
			n[j] += 1
		i = j
	print(res)


t = int(input())
for x in range(t):
	inp = input().split()
	a = int(inp[0])
	b = int(inp[1])
	moves = 0
	if a % b == 0:
		pass
	elif a < b:
		moves = b - a
	elif a > b:
		rest = 1 - a / b % 1
		moves = round(rest * b)
	print(moves)


import sys
sys.setrecursionlimit(10 ** 9)
import copy

def solve(a: int, b: int, n: int=0) -> int:
	if a % b == 0:
		return 0
	if a < b:
		return b - a
	return (a // b + 1) * b - a
x = input()
if int(x) < 1 or int(x) > 10 ** 4:
	quit
rez = ''
for i in range(int(x)):
	dual = input()
	(x, y) = dual.split()
	(x, y) = (int(x), int(y))
	if x < 1 or x > 10 ** 9 or y < 1 or (y > 10 ** 9):
		if rez == '':
			rez = 333
		else:
			rez = rez + '\n333'
		continue
	if rez == '':
		rez = rez + str(solve(x, y))
	else:
		rez = rez + '\n' + str(solve(x, y))
print(rez)


from sys import stdin

def min_moves(n: int, s: int):
	moves = 0
	power = 1
	while sum(map(int, str(n))) > s:
		d = n // power % 10
		toAdd = power * (10 - d)
		moves += toAdd
		n += toAdd
		power *= 10
	return moves
t = int(stdin.readline())
for _ in range(t):
	(n, s) = map(int, stdin.readline().split())
	print(min_moves(n, s))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ans = 0
	q = int(n / m)
	n1 = m * q
	if n % m == 0:
		print(0)
	if m > n:
		print(m - n)
	if n % m != 0 and m < n:
		n2 = m * (q + 1)
		print(n2 - n)


t = int(input())
for i in range(t):
	(n, s) = map(int, input().split())
	number = list(str(n))
	summation = 0
	for digit in number:
		summation += int(digit)
	flag = True
	if summation <= s:
		flag = False
	exponent = 0
	add = 0
	cost = 0
	if flag:
		for digit in number[::-1]:
			if int(digit) + add == 0:
				add = 0
			else:
				cost += (10 - (int(digit) + add)) * 10 ** exponent
				summation -= int(digit)
				if not add:
					summation += 1
				add = 1
			exponent += 1
			if summation <= s:
				break
	print(cost)


from math import sqrt
t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	if a % b == 0:
		print(0)
	else:
		k = (a // b + 1) * b
		print(abs(k - a))


for v in [[int(t) for t in input().split()] for _ in range(int(input()))]:
	(a, b) = v
	r = a % b
	print(0 if r == 0 else b - r)


t = int(input())

def sum_d(string):
	return sum((int(x) for x in string))
for _ in range(t):
	(n, s) = list(map(int, input().split()))
	start = str(n)
	if sum_d(start) <= s:
		print(0)
		continue
	for digits in range(1, len(start) + 1):
		if sum_d(start[-digits:]) == 0:
			continue
		new_str = [x for x in start]
		for x in range(digits):
			new_str[-1 - x] = '0'
		if digits == len(start):
			new_str.insert(0, '1')
		else:
			for x in range(len(start) - digits):
				if new_str[len(start) - digits - 1 - x] == '9':
					new_str[len(start) - digits - 1 - x] = 0
					if x == len(start) - digits - 1:
						new_str.insert(0, '1')
				else:
					new_str[len(start) - digits - 1 - x] = int(new_str[len(start) - digits - 1 - x]) + 1
					break
		if sum_d(new_str) <= s:
			new_val = 0
			for val in new_str:
				new_val *= 10
				new_val += int(val)
			print(new_val - n)
			break


for u in range(int(input())):
	(a, b) = map(int, input().split())
	if a < b:
		print(b - a)
	elif a % b == 0.0:
		print(0)
	else:
		y = a // b
		y = y + 1
		print(b * y - a)


from sys import stdin, stdout
rr = lambda : input().strip()
rri = lambda : int(rr())
rrm = lambda : [int(x) for x in rr().split()]

def sol():
	(a, b) = rrm()
	if a % b == 0:
		return 0
	return b - a % b
T = rri()
for t in range(T):
	ans = sol()
	print(ans)


def f(i, s):
	if s == arr[i]:
		if pres[-1] - pres[i + 1] != 0:
			arr[i - 1] += 1
			for i in range(i, len(arr)):
				arr[i] = 0
			return 0
		else:
			return 0
	elif s < arr[i]:
		arr[i - 1] += 1
		for i in range(i, len(arr)):
			arr[i] = 0
		return 0
	else:
		return s - arr[i]
for _ in range(int(input())):
	(n, s) = list(map(int, input().split()))
	n1 = n
	arr = []
	while n > 0:
		arr.append(n % 10)
		n = n // 10
	if sum(arr) <= s:
		print(0)
		continue
	arr = arr[::-1]
	arr = [0] + arr
	pres = [0] * (len(arr) + 1)
	for i in range(len(arr)):
		pres[i + 1] = pres[i] + arr[i]
	i = 1
	while s != 0:
		s = f(i, s)
		i += 1
	for i in range(n, 0, -1):
		if arr[i] > 9:
			arr[i - 1] += 1
			arr[i] -= 10
	if sum(arr) <= s:
		print(0)
		continue
	c = 0
	u = 0
	for i in range(len(arr) - 1, -1, -1):
		c += arr[i] * 10 ** (len(arr) - i - 1)
	print(c - n1)


from sys import stdin

def digsum(n):
	ret = 0
	while n > 0:
		ret += n % 10
		n //= 10
	return ret

def solve(n, s):
	oldn = n
	if digsum(n) <= s:
		return 0
	else:
		NS = []
		while n > 0:
			NS.append(n % 10)
			n //= 10
		NS.append(0)
		NS.reverse()
		tmpsum = 0
		flag = False
		for i in range(len(NS)):
			tmpsum += NS[i]
			if tmpsum >= s and flag == False:
				flag = True
				NS[i - 1] += 1
			if flag:
				NS[i] = 0
		nex = 0
		for i in NS:
			nex *= 10
			nex += i
		return solve(nex, s) + (nex - oldn)
tt = int(stdin.readline())
for loop in range(tt):
	(n, s) = map(int, stdin.readline().split())
	print(solve(n, s))


import sys
cases = int(sys.stdin.readline().strip())
for i in range(cases):
	candles = sys.stdin.readline().strip().split(' ')
	a = int(candles[0])
	b = int(candles[1])
	if a % b == 0:
		print('0')
	else:
		print(str(b - a % b))


t = int(input())
for _ in range(t):
	(a, b) = [int(s) for s in input().split()]
	div = a % b
	if div == 0:
		print(0)
	else:
		print(b - div)


x = input()
y = int(x)
lis = []
for i in range(y):
	x2 = input()
	spl = x2.split()
	i1 = int(spl[0])
	i2 = int(spl[1])
	i3 = i1 // i2
	if i1 % i2 == 0:
		i4 = 0
	else:
		i4 = (i3 + 1) * i2 - i1
	lis.append(i4)
for i in lis:
	print(i)


def div(a, b):
	if a % b == 0:
		return 0
	return b - a % b
q = int(input())
while q:
	(a, b) = map(int, input().split())
	print(div(a, b))
	q -= 1


t = int(input())
C = []
for i in range(0, t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		c = 0
	else:
		tp = a % b
		c = b - tp
	C.append(c)
for i in range(0, t):
	print(C[i])


from collections import *
from sys import stdin, stderr

def rl():
	return [int(w) for w in stdin.readline().split()]
for _ in range(rl()[0]):
	(n, s) = rl()
	n0 = n
	while sum(map(int, str(n))) > s:
		x = 10
		while n % x == 0:
			x *= 10
		n += x - n % x
	print(n - n0)


from sys import stdin, stdout
t = int(stdin.readline())
for case in range(t):
	(a, b) = map(int, stdin.readline().split())
	ans = -1
	if a % b == 0:
		ans = 0
	elif a > b:
		ans = b - a % b
	else:
		ans = b - a
	stdout.write('{}\n'.format(ans))


from sys import stdin

def func():
	return
for _ in range(int(stdin.readline())):
	(a, b) = map(int, stdin.readline().split())
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


def answer(n, s):
	count = 0
	l = [int(i) for i in str(n)]
	l = l[::-1]
	for i in l:
		count += i
	move = 0
	i = 0
	while count > s:
		if l[i] != 0:
			move += (10 - l[i]) * 10 ** i
			l[i] = 0
			carry = 1
			index = i + 1
			while index < len(l) and carry:
				x = l[index] + carry
				l[index] = x % 10
				carry = x // 10
				index += 1
			if carry > 0:
				l.append(carry)
			count = sum(l)
		i += 1
	return move
t = int(input())
for i in range(t):
	(n, s) = map(int, input().split())
	print(answer(n, s))


import sys

def process(a, b):
	m = a % b
	if m == 0:
		print(0)
	else:
		print(b - m)
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
for i in range(t):
	AB = inlt()
	(a, b) = (AB[0], AB[1])
	process(a, b)


n = int(input())
lst = []
for i in range(n):
	stp = 0
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if b > a:
		stp = b - a
		lst.append(stp)
	elif a % b == 0:
		lst.append(0)
	else:
		stp = a % b
		c = int(a / b)
		c = c + 1
		d = int(c * b)
		stp2 = min(a - stp, d - a)
		lst.append(stp2)
for i in lst:
	print(i)


for _ in range(int(input())):
	(a, b) = (int(x) for x in input().split())
	if a % b == 0:
		ans1 = 0
	elif a <= b:
		ans1 = b - a
	else:
		ans1 = b - a % b
	print(ans1)


n = int(input())
l = []
for x in range(n):
	s = list(map(int, input().split(' ')))
	(a, b) = (s[0], s[1])
	if a % b != 0:
		r = a // b + 1
		a = b * r
	l.append(a - s[0])
for x in l:
	print(x)


for i in range(int(input())):
	(x, y) = input().split()
	x = int(x)
	y = int(y)
	if x % y != 0:
		z = x // y + 1
		z = z * y
		print(z - x)
	else:
		print(0)


times = int(input())
for i in range(0, times):
	(a, b) = map(int, input().strip().split())
	if a % b == 0:
		print(0)
	else:
		steps = b - a % b
		print(steps)


t = int(input())
for loop in range(t):
	(a, b) = map(int, input().split())
	print((b - a % b) % b)


n = int(input())
for i in range(n):
	(a, b) = [int(x) for x in input().split()]
	c = -(-a // b)
	count = b * c - a
	print(count)


t = int(input())
dig = []
for i in range(t):
	(a, b) = list(map(int, input().split()))
	if a % b != 0:
		number = a // b + 1
		number *= b
		dig.append(number - a)
	else:
		dig.append(0)
for j in range(len(dig)):
	print(dig[j])


from math import ceil
cases = int(input())
while cases:
	(a, b) = map(int, input().split())
	print(int(ceil(a / b)) * b - a)
	cases -= 1


for _ in range(int(input())):
	(n, s) = input().split()
	s = int(s)
	digits = [int(c) for c in n]
	x = len(digits)
	p = 0
	while digits[x - 1] == 0:
		x -= 1
		p += 1
	(y, s_) = (0, 0)
	while s_ < s and y < x:
		s_ += digits[y]
		y += 1
	if y == x and s_ <= s:
		print(0)
	else:
		suffix = int(n[y - 1:x])
		ans = (10 ** (x - y + 1) - suffix) * 10 ** p
		print(ans)


def get_sum(n):
	s = 0
	while n:
		s += n % 10
		n = n // 10
	return int(s)

def get_results():
	(n, s) = list(map(int, input().split()))
	presum = get_sum(n)
	if presum <= s:
		return 0
	mul = 1
	moves = 0
	while presum > s:
		d = n // mul % 10
		if d != 0:
			dif = (10 - d) * mul
			n += dif
			moves += dif
		presum = get_sum(n)
		mul = mul * 10
	return moves

def main():
	t = int(input())
	res = []
	for i in range(t):
		res.append(get_results())
	for i in res:
		print(i)
main()


t = eval(input())
while t:
	(a, b) = map(int, input().split())
	extra = a % b
	if extra == 0:
		print(extra)
	else:
		steps = b - extra
		print(steps)
	t -= 1


def su(a):
	return sum(map(int, str(a)))
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	(t, i) = (a, 0)
	while su(t) > b:
		x = t // 10 ** i
		t += 10 ** i * (10 - int(str(x)[-1]))
		i += 1
	print(t - a)


def getSumOfDigits(num: int) -> int:
	ans = 0
	while num:
		digit = num % 10
		num //= 10
		ans += digit
	return ans

def decreaseTheSumOfDigits(n: int, s: int) -> int:
	ans = 0
	i = 1
	while getSumOfDigits(n) > s:
		summand = 10 ** i - n % 10 ** i
		n += summand
		ans += summand
		i += 1
	return ans
test_cases = int(input())
for _ in range(test_cases):
	inputs = list(map(int, input().split(' ')))
	print(decreaseTheSumOfDigits(inputs[0], inputs[1]))


import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	(n, s) = input().split()
	n_len = len(n)
	s = int(s)
	if sum(list(map(int, n))) <= s:
		print(0)
		continue
	e_sum = 0
	for (count, e) in enumerate(map(int, n)):
		e_sum += e
		if e_sum >= s:
			break
	if count == 0:
		ans = 10 ** n_len - int(n)
	else:
		ans = 10 ** (n_len - count) - int(n[count:])
	print(ans)


def main():
	output = []
	t = int(input())
	for _ in range(t):
		(a, b) = map(int, input().split())
		if a == b or a % b == 0:
			output.append('0')
		elif b > a:
			output.append(str(b - a))
		else:
			r = b * (a // b + 1)
			output.append(str(r - a))
	print('\n'.join(output))
main()


for _ in range(int(input())):
	(n, s) = [int(x) for x in input().split()]
	a = [int(x) for x in str(n)]
	if sum(a) <= s:
		print(0)
	else:
		acum = 0
		j = 0
		encontrado = -1
		for i in range(len(a) - 1, -1, -1):
			if sum(a[0:i + 1]) + 1 <= s:
				encontrado = i
				break
		if encontrado >= 0:
			print(10 ** len(a[encontrado + 1:]) - int(str(n)[encontrado + 1:]))
		else:
			print(10 ** len(a) - int(str(n)))


t = int(input())
for tc in range(t):
	(s1, n) = input().split(' ')
	n = int(n)
	ans = 0
	s = list(s1)
	for i in s:
		ans += int(i)
	if ans <= n:
		print(0)
		continue
	else:
		dig = []
		for i in s:
			dig.append(i)
		sz = len(dig)
		ptr = sz - 2
		while ptr >= 0:
			dig[ptr] = str(int(dig[ptr + 1]) + int(dig[ptr]))
			ptr -= 1
		ptr = sz - 2
		while ptr >= -1:
			if ans - int(dig[ptr + 1]) + 1 <= n:
				break
			ptr -= 1
		while ptr >= 0 and s[ptr] == '9':
			ptr -= 1
		if ptr == -1:
			ptr = 1
			nn = ['1']
			nn += s
			while ptr <= sz:
				nn[ptr] = '0'
				ptr += 1
			nn1 = ''
			nn1 = nn1.join(nn)
			print(int(nn1) - int(s1))
		else:
			nn = s
			nn[ptr] = str(int(nn[ptr]) + 1)
			ptr += 1
			while ptr < sz:
				nn[ptr] = '0'
				ptr += 1
			nn1 = ''
			nn1 = nn1.join(nn)
			print(int(nn1) - int(s1))


T = int(input())
for t in range(T):
	(n, s) = input().split()
	fixn = n
	n_list = [0] + [int(i) for i in n]
	m = len(n_list)
	s = int(s)
	cur_sum = sum(n_list)
	ans = 0
	right_pointer = m - 1
	while cur_sum > s:
		while n_list[right_pointer] == 0:
			right_pointer -= 1
		n_list[right_pointer - 1] += 1
		n_list[right_pointer] = 0
		new_pointer = right_pointer - 1
		while n_list[new_pointer] >= 10:
			n_list[new_pointer] %= 10
			n_list[new_pointer - 1] += 1
			new_pointer -= 1
		cur_sum = sum(n_list)
	tmp = 0
	for i in range(m):
		tmp *= 10
		tmp += n_list[i]
	print(tmp - int(fixn))


t = int(input())
for _ in range(t):
	(n, s) = input().split()
	s = int(s)
	n = [int(x) for x in n]
	if sum(n) <= s:
		print(0)
	else:
		count = 0
		for i in range(len(n)):
			if s >= n[i] + 1 or (i == len(n) - 1 and s >= n[i]):
				s -= n[i]
				count += 1
			else:
				break
		s = ''
		for x in n[count:]:
			s += str(x)
		print(10 ** len(n[count:]) - int(s))


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	l = len(str(n))
	st = str(n)
	som = 0
	for i in range(l):
		som += int(st[i])
	if s == 1 and som != 1:
		print(10 ** l - n)
	elif som <= s:
		print(0)
	else:
		som = 0
		for i in range(l):
			som += int(st[i])
			if som >= s:
				if i == 0:
					ans = 10 ** l - n
					break
				else:
					ans = (int(st[i - 1]) + 1) * 10 ** (l - i) - int(st[i - 1:])
					break
		print(ans)


n = int(input())
while n != 0:
	(a, b) = [int(x) for x in input().split()]
	if a % b == 0:
		print(0)
	else:
		k = a // b
		print(b * (k + 1) - a)
	n -= 1


import os
import sys
from io import BytesIO, IOBase
import math

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def addto(l, i):
	while i >= 0 and l[i] == 9:
		l[i] = 0
		i -= 1
	if i == -1:
		l.insert(0, 0)
		l[0] += 1
		return l
	else:
		l[i] += 1
		return l

def update(i, n):
	for j in range(i, n):
		l[j] = 0
	return l

def te(i):
	s = '0'
	for j in range(i + 1, n):
		s += str(l[j])
	return int(s)
for xyz in range(0, int(input())):
	(n, s) = input().split()
	s = int(s)
	st = n
	l = []
	for i in n:
		l.append(int(i))
	ans = 0
	n = len(l)
	f = 1
	while sum(l) > s:
		cs = 0
		for i in range(0, n):
			cs += l[i]
			if cs > s:
				ans += pow(10, n - i - 1) * (10 - l[i]) - te(i)
				l = update(i, n)
				l = addto(l, i - 1)
				break
	print(ans)


for _ in range(int(input())):
	(n, s) = map(str, input().split())
	s = int(s)
	le = len(n)
	su = 0
	flag = 0
	l = []
	ans = 0
	for i in n:
		l.append(int(i))
	if sum(l) <= s:
		ans = 0
		flag = 1
	else:
		for i in range(le):
			if su + int(n[i]) < s:
				su += int(n[i])
			else:
				st = n[i:]
				ans = pow(10, le - i) - int(st)
				flag = 1
				break
	if flag:
		print(ans)
	else:
		print(0)


t = int(input())

def get_sum(n):
	return sum([i for i in map(int, list(str(n)))])

def destroy_digit(n, digit):
	if digit == 0:
		return n
	return int(str(n)[0:-1 * digit] + '0' * digit) + 10 ** digit
for _ in range(t):
	(n, s) = map(int, input().split())
	n_digits = len(str(n))
	for i in range(n_digits + 1):
		new_num = destroy_digit(n, i)
		if get_sum(new_num) <= s:
			print(new_num - n)
			break


n = int(input())
f = 0
for i in range(n):
	(a, b) = map(int, input().split())
	if a < b:
		print(abs(b - a))
	elif a % b != 0:
		print(abs((a // b + 1) * b - a))
	else:
		print(0)


m = int(input())
for i in range(m):
	(n, s) = map(int, input().split(' '))
	summat = int(0)
	r = n
	rnt = int(0)
	mov = int(0)
	mov1 = int(0)
	while r:
		summat += r % 10
		r //= 10
		rnt += 1
	if summat <= s:
		print('0')
	else:
		for jj in range(rnt):
			if jj == 0:
				dig = n % 10
			else:
				dig = n // 10 ** jj % 10
			j = n
			summat = 0
			while j:
				summat += j % 10
				j //= 10
			if summat <= s:
				break
			if dig == 0:
				continue
			mov = (10 - dig) % 10 * 10 ** jj
			n = n + mov
			mov1 += mov
		print(mov1)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	c = a % b
	if c == 0:
		print('0')
	else:
		print(abs(b - c))


n = int(input())
ans = []
for i in range(n):
	a = input()
	list_a = a.split()
	a = int(list_a[0])
	b = int(list_a[1])
	if a % b == 0:
		ans.append(0)
	else:
		s = a // b
		ans.append(b * (s + 1) - a)
for i in ans:
	print(i)


a = int(input())
L = []
for i in range(a):
	b = input()
	c = ''
	for j in b:
		if j == ' ':
			x = int(c)
			c = ''
		else:
			c += j
	L += [[x, int(c)]]
for k in range(a):
	if L[k][0] % L[k][1] != 0:
		print(L[k][1] - L[k][0] % L[k][1])
	else:
		print(0)


Test = int(input())
for i in range(Test):
	(x, y) = list((int(i) for i in input().strip().split()))[:2]
	if x % y == 0:
		print(0)
	else:
		print(y - x % y)


def solve(a, b):
	if a % b == 0:
		return 0
	return b - a % b
t = int(input())
while t:
	(a, b) = map(int, input().split())
	print(solve(a, b))
	t -= 1


t = int(input())
for test in range(t):
	(a, b) = [int(x) for x in input().split()]
	print((b - a % b) % b)


t = int(input())
for i in range(0, t):
	n = list(map(int, input().split()))
	if n[0] % n[1] == 0:
		print(0)
	else:
		div = n[0] // n[1]
		x = (div + 1) * n[1]
		print(x - n[0])


import sys, math
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))
for _ in range(inp()):
	(N, s) = inpl()
	org = N
	n = list(str(N))
	ln = len(n)
	a = [0] + [int(x) for x in n]
	up = False
	for i in range(ln):
		n = list(str(N))
		now = 0
		for x in n:
			now += int(x)
		if now <= s:
			break
		c = pow(10, i + 1)
		N += c - N % c
	print(N - org)


def digit_sum(n):
	result = 0
	while n > 0:
		result += n % 10
		n //= 10
	return result

def moves(n, s):
	if digit_sum(n) <= s:
		return 0
	m = n
	i = 1
	while digit_sum(m) > s:
		m = (n // 10 ** i + 1) * 10 ** i
		i += 1
	return m - n
t = int(input())
for i in range(t):
	(n, s) = map(int, input().split())
	print(moves(n, s))


n = int(input())
for i in range(n):
	(ai, bi) = map(int, input().split())
	if ai % bi == 0:
		print('0')
	else:
		print(bi - ai % bi)


a = input()
b = []
count = 0
for i in range(int(a)):
	l = input().split()
	b.append(int(l[0]))
	b.append(int(l[1]))
for i in range(0, len(b) - 1, 2):
	if b[i] % b[i + 1] == 0:
		print('0')
	else:
		print((b[i] // b[i + 1] + 1) * b[i + 1] - b[i])


import math
t = int(input())
for _ in range(t):
	(a, b) = [int(x) for x in input().split()]
	if math.floor(a / b) == math.ceil(a / b):
		print(0)
	else:
		c = a % b
		print(b - c)


import sys
from collections import defaultdict as dd
from collections import deque
from functools import *
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
from math import *
from itertools import permutations, product

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

def inc(d, c):
	d[c] = d[c] + 1 if c in d else 1

def bo(i):
	return ord(i) - ord('A')

def li():
	return [int(xx) for xx in input().split()]

def fli():
	return [float(x) for x in input().split()]

def comp(a, b):
	if a > b:
		return 2
	return 2 if a == b else 0

def gi():
	return [xx for xx in input().split()]

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def gh():
	sys.stdout.flush()

def isvalid(i, j):
	return 0 <= i < n and 0 <= j < n

def bo(i):
	return ord(i) - ord('a')

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = fi()

def sod(n):
	p = str(n)
	c = 0
	for i in range(len(p)):
		c += int(p[i])
	return c
while t > 0:
	t -= 1
	(n, s) = mi()
	mm = n
	l = sod(n)
	need = s - l
	if need >= 0:
		print(0)
		continue
	s = list(str(n))
	m = len(s)
	c = 1
	ans = 0
	need = -need
	need += 1
	flag = 0
	z = -1
	for i in range(m - 1, -1, -1):
		if int(s[i]) >= need:
			ans += need * c
			if i == 0:
				s[i] = '0'
				s.insert(0, '1')
				flag = 1
			else:
				z = i
				s[i] = '0'
			break
		else:
			ans += int(s[i]) * c
			need -= int(s[i])
			s[i] = '0'
		c *= 10
	if flag == 1:
		print(int(''.join(s)) - mm)
		continue
	m = int(''.join(s[:z]))
	m += 1
	k = int(str(m) + ''.join(s[z:]))
	print(k - mm)


t = int(input())
for kikk in range(t):
	(a, b) = list(map(int, input().split()))
	r = a % b
	if r == 0:
		print(0)
	else:
		print(b - r)


q = int(input())
while q:
	q -= 1
	(n, s) = [int(x) for x in input().split()]
	a = list(reversed([int(str(n)[i]) for i in range(len(str(n)))]))
	price = 1
	i = 0
	ans = 0
	while sum(a) > s:
		if a[i] == 0:
			price *= 10
			i += 1
			continue
		k = 10 - a[i]
		z = a[i] - 1
		ans += k * price
		price *= 10
		a[i] = 0
		i += 1
		if i >= len(a):
			a.append(1)
		else:
			a[i] += 1
		j = i
		while a[j] >= 10:
			c = a[j] % 10
			d = a[j] // 10
			if j + 1 >= len(a):
				a.append(d)
			else:
				a[j + 1] += d
			a[j] = c
			j += 1
	print(ans)


t = int(input())
for i in range(t):
	(a, b) = [int(j) for j in input().split()]
	if a % b == 0:
		print(0)
	elif b > a:
		print(b - a)
	else:
		x = a % b
		ans = b - x
		print(ans)


n = int(input())
l = []
for i in range(n):
	a = list(map(int, input().split()[:2]))
	if a[0] % a[1] == 0:
		l.append(0)
	else:
		b = a[0] // a[1]
		b = b + 1
		value = a[1] * b - a[0]
		l.append(value)
for i in l:
	print(i)


n = int(input())
while n > 0:
	n -= 1
	count = 0
	(a, b) = map(int, input().split())
	if a % b == 0:
		count += 0
	elif a > b:
		div = a % b
		count += b - div
	else:
		count += b - a
	print(count)


def sum_digits(num):
	return sum([int(s) for s in str(num)])

def solve(N, S):
	Q = sum_digits(N)
	pow = 1
	ans = 0
	while Q > S:
		diff = N % 10 ** pow
		if N % 10 ** pow != 0:
			ans += 10 ** pow - diff
			N += 10 ** pow - diff
		Q = sum_digits(N)
		pow += 1
	return ans
T = int(input())
for t in range(1, T + 1):
	(N, S) = [int(s) for s in input().split()]
	print(solve(N, S))


from math import gcd
from collections import defaultdict
from sys import stdout

def su(z):
	s = 0
	while z > 0:
		s += z % 10
		z = z // 10
	return s
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	z = a
	s = 0
	while z > 0:
		s += z % 10
		z = z // 10
	if s <= b:
		print(0)
	else:
		ans = 0
		temp = 1
		while s > b:
			r = a % 10
			x = 10 - r
			ans += temp * x
			a += x
			s = su(a)
			temp *= 10
			a = a // 10
		print(ans)


def main():
	t = int(input())
	for _ in range(t):
		(n, s) = input().split(' ')
		s = int(s)
		total = 0
		for nn in n:
			total += int(nn)
		ans = 0
		p = 1
		ten = 1
		carry = False
		while total > s:
			num = int(n[-p])
			if carry:
				num += 1
			if num == 0:
				carry = False
			else:
				ans += ten * (10 - num)
				total -= num - 1
				carry = True
			ten *= 10
			p += 1
		print(ans)
main()


tc = int(input())
while tc > 0:
	tc -= 1
	(a, b) = map(int, input().split())
	print((b - a % b) % b)


t = int(input())
i = 0
while i < t:
	riga = list(map(int, input().strip().split()))
	a = riga[0]
	b = riga[1]
	c = a % b
	mosse = 0
	if c != 0:
		mosse = b - c
	else:
		mosse = 0
	print(mosse)
	i = i + 1


def DivisibilityProblem(x, y):
	if x % y == 0:
		return 0
	else:
		a = x % y
		return abs(a - y)
t = int(input())
for i in range(t):
	(x, y) = map(int, input().split())
	print(DivisibilityProblem(x, y))


for i in range(int(input())):
	(n, s) = map(str, input().split())
	n = list(map(int, list(n)))
	su = sum(n)
	n.reverse()
	n.append(0)
	ans = 0
	for i in range(len(n) - 1):
		su = sum(n)
		if su <= int(s):
			break
		else:
			ans += int(10 - int(n[i])) * 10 ** i
			n[i] = 0
			n[i + 1] += 1
	print(ans)


def find(a, b):
	m = a % b
	if m > 0:
		return b - m
	else:
		return m
rounds = int(input())
for _ in range(rounds):
	(a_, b_) = map(int, input().split())
	print(find(a_, b_))


N = int(input())
for i in range(N):
	(n, d) = [int(x) for x in input().split()]
	r = n % d
	if r == 0:
		print(0)
	else:
		print(abs(d - n % d))


def find(a, b):
	if a % b == 0:
		return 0
	d = a % b
	return b - d
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(find(n, k))


for _ in range(int(input())):
	(n, s) = map(int, input().split(' '))
	n_str = str(n)
	n_int = [int(num) for num in n_str]
	x = sum(n_int)
	if x <= s:
		ans = 0
	else:
		tu = 0
		a = len(n_int)
		for i in range(a):
			if tu + n_int[i] >= s:
				k = i
				break
			else:
				tu = tu + n_int[i]
		b = a - k
		ans = 10 ** b - int(n_str[k:a])
	print(ans)


from math import ceil
test = int(input())
for i in range(0, test):
	num = list(map(int, input().split()))
	if num[1] > num[0]:
		print(int(num[1] - num[0]))
	else:
		i = ceil(num[0] / num[1])
		print(num[1] * i - num[0])


def minimum_moves(n, s):
	moves = 0
	multiplier = 1
	while sum(map(int, str(n))) > s:
		if n % 10:
			delta = 10 - n % 10
			n += delta
			moves += multiplier * delta
		n //= 10
		multiplier *= 10
	return moves
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	print(minimum_moves(n, s))


times = int(input())
for round in range(times):
	numbers = input()
	a = int(numbers.split()[0])
	b = int(numbers.split()[1])
	c = a // b
	d = (c + 1) * b - a
	if a % b == 0:
		d = 0
	print(d)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	f = a // b
	ans = 0
	if a < b:
		ans = b - a
	elif a % b != 0:
		ans = b * (f + 1) - a
	print(ans)


import sys
for _ in range(int(input())):
	(n, s) = [int(i) for i in input().split()]
	su = 0
	nn = n
	while nn > 0:
		su += nn % 10
		nn = nn // 10
	diff = su - s
	cnt = 0
	ans = 0
	cdiff = 0
	while cdiff < diff:
		rem = n % 10
		ans += (10 - rem) * 10 ** cnt
		cnt += 1
		n = n // 10
		temp = 0
		while n % 10 == 9:
			n = n // 10
			temp += 1
			cnt += 1
		n += 1
		cdiff += rem - 1 + temp * 9
	print(ans)


from sys import stdin, stdout
for i in range(int(stdin.readline())):
	a = [int(x) for x in stdin.readline().split()]
	if a[0] % a[1] != 0:
		if a[0] < a[1]:
			print(a[1] - a[0])
		elif a[0] > a[1]:
			print((1 + a[0] // a[1]) * a[1] - a[0])
	else:
		print(0)


import math

def BuubleSort(a, b):
	if a < b:
		return b - a
	elif a == b or a % b == 0:
		return 0
	else:
		return b - a % b

def main():
	n = int(input())
	for _ in range(n):
		(a, b) = map(int, input().split())
		ans = BuubleSort(a, b)
		print(ans)
main()


def divisible(a, b):
	if a % b == 0:
		res = 0
	else:
		c = a // b
		c += 1
		res = b * c - a
	return res
t = int(input())
while t > 0:
	(a, b) = map(int, list(input().split()))
	print(divisible(a, b))
	t -= 1


def main(a, b):
	if a % b == 0:
		return 0
	else:
		index = (int(a / b) + 1) * b
		return abs(index - a)
t = int(input())
for t_itr in range(t):
	ab = list(map(int, input().rstrip().split()))
	a = ab[0]
	b = ab[1]
	res = main(a, b)
	print(res)


import sys
import math
import collections
import bisect
import itertools
import decimal
import copy
INF = 10 ** 20
ni = lambda : int(sys.stdin.readline().rstrip())
ns = lambda : map(int, sys.stdin.readline().rstrip().split())
na = lambda : list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda : list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))

def main():
	t = ni()
	for _ in range(t):
		(n, s) = ns()
		a = [int(i) for i in list(str(n))]
		total = sum(a)
		a.reverse()
		a.append(0)
		ar = a.copy()
		if total > s:
			ans = 0
			for i in range(len(ar)):
				if ar[i] == 10:
					total -= a[i]
					ar[i + 1] += 1
					if total + 1 <= s:
						total += 1
						break
				elif ar[i] > 0:
					total -= a[i]
					ar[i + 1] += 1
					ans += pow(10, i) * (10 - ar[i])
					if total + 1 <= s:
						total += 1
						break
			print(ans)
		else:
			print(0)
main()


def x(a, b):
	if a % b == 0:
		return 0
	else:
		return b - a % b
for i in range(int(input())):
	(m, n) = map(int, input().split())
	print(x(m, n))


for t in [0] * int(input()):
	(a, b) = map(int, input().split())
	import math
	print(math.ceil(a / b) * b - a)


n = int(input())
for i in range(n):
	(a, b) = list(map(int, input().split()))
	if a % b == 0:
		print(0)
	else:
		k = a % b
		j = abs(k - b)
		print(j)


t = int(input())
while t:
	(a, b) = tuple(map(int, input().split()))
	z = b - a % b
	if z == b:
		print(0)
		t -= 1
		continue
	print(z)
	t -= 1


from math import ceil
t = int(input())
for _ in range(0, t):
	(a, b) = map(int, input().split(' '))
	ans = b * ceil(a / b) - a
	print(ans)


t = int(input())
for tt in range(t):
	ab = input().split(' ')
	a = int(ab[0])
	b = int(ab[1])
	if a == b:
		print(0)
	elif a < b:
		print(b - a)
	elif a % b == 0:
		print(0)
	else:
		t = (int(a / b) + 1) * b
		print(t - a)


x = int(input())
a = list()
for i in range(x):
	s = list(map(int, input().split()))
	a.append(s)
for i in a:
	if i[0] % i[1] == 0:
		print('0')
	else:
		l = i[0] // i[1]
		print((l + 1) * i[1] - i[0])


testCases = int(input())
for _ in range(testCases):
	(a, b) = map(int, input().split())
	reminder = a % b
	if reminder == 0:
		print(reminder)
	else:
		print(b - a % b)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	k = m
	cnt = 0
	if n % m == 0:
		print(0)
	else:
		print(m * (int(n / m) + 1) - n)


n = int(input())
import math
while n > 0:
	(a, b) = [int(x) for x in input().split()]
	print(b * math.ceil(a / b) - a)
	n -= 1


def solve():
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		print((a // b + 1) * b - a)
for i in ' ' * int(input()):
	solve()


t = int(input())
while t != 0:
	(a, b) = map(int, input().split())
	if b > a:
		print(b - a)
	elif b == a:
		print(0)
	else:
		r = int(a / b)
		m = a % b
		if m == 0:
			print(0)
		else:
			print((r + 1) * b - a)
	t -= 1


import math
t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().split(' ')))
	if a % b == 0:
		print(0)
	elif b > a:
		print(b - a)
	else:
		c = math.floor(a / b) + 1
		print(b * c - a)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil, pi, sin, cos, acos, atan
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = ip()
for _ in range(t):
	(n, s) = input().split(' ')
	s = int(s)
	arr = [0]
	for i in n:
		arr.append(int(i))
	ans = 0
	pos = len(arr) - 1
	power = 0
	while sum(arr) > s:
		if arr[pos] == 0:
			pos -= 1
			power += 1
		else:
			val = 10 - arr[pos]
			arr[pos] = 0
			ans += val * pow(10, power)
			arr[pos - 1] += 1
			pos -= 1
			power += 1
	out(ans)


def solve():
	(a, b) = map(int, input().split())
	if a < b:
		print(b - a)
	elif a == b:
		print(0)
	else:
		q = a % b
		if q == 0:
			print(0)
			return
		min1 = b - q
		print(min1)
for _ in range(int(input())):
	solve()


def solve():
	(a, b) = list(map(int, input().split()))
	if a % b == 0:
		return 0
	nn = a + b - (a + b) % b
	return nn - a
T = int(input())
for t in range(T):
	print(solve())


def get(*arg):
	if arg[0] == 0:
		cnt = int(input())
		flag = 1
	else:
		cnt = 1
		flag = 0
	lst = list()
	for i in range(cnt):
		lst2 = list()
		for ii in range(len(arg) - flag):
			if arg[ii + flag] == 1:
				t = input().split()
				tmp = list()
				for iii in t:
					tmp.append(int(iii))
			elif arg[ii + flag] == 2:
				tmp = input().split()
			else:
				tmp = input()
			lst2.append(tmp)
		lst.append(lst2)
	return lst
q = get(0, 1)
for i in q:
	a = i[0][0]
	b = i[0][1]
	if a <= b:
		print(b - a)
	else:
		c = (a // b + 1) * b - a
		if c == b:
			c = 0
		print(c)


t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	if a // b == a / b:
		print(0)
	else:
		remain = a % b
		add = b - remain
		print(add)


try:
	t = int(input())
	i = 0
	while i < t:
		(a, b) = list(map(int, input().split()))
		c = a % b
		if c == 0:
			print(0)
		else:
			print(b - c)
		i += 1
except:
	pass


def make_div_eff(a, b):
	if a % b == 0:
		return 0
	else:
		return b - a % b
t = int(input())
while t > 0:
	inp = input().split()
	inp = [int(c) for c in inp]
	(a, b) = (inp[0], inp[1])
	res = make_div_eff(a, b)
	print(res)
	t -= 1


from sys import stdin

def solve(tc):
	(a, b) = map(int, stdin.readline().split())
	div = a // b
	rem = a % b
	if rem > 0:
		div += 1
	print(b * div - a)
LOCAL_TEST = not __debug__
if LOCAL_TEST:
	infile = __file__.split('.')[0] + '-test.in'
	stdin = open(infile, 'r')
tcs = int(stdin.readline().strip())
tc = 1
while tc <= tcs:
	solve(tc)
	tc += 1


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print('0')
	else:
		down = a // b
		down += 1
		print(abs(a - b * down))


def getSum(n):
	sum = 0
	while n > 0:
		sum += n % 10
		n //= 10
	return sum
tc = int(input())
while tc:
	tc -= 1
	(n, s) = map(int, input().split())
	ans = 0
	while getSum(n) > s:
		p = 1
		tmp = n
		while tmp % 10 == 0:
			tmp //= 10
			p *= 10
		n += (10 - tmp % 10) * p
		ans += (10 - tmp % 10) * p
	print(ans)


t = int(input())
for _ in range(t):
	(a, b) = [int(i) for i in input().split()]
	print((b - a % b) % b)


x = int(input())
c = []
d = []
for i in range(x):
	(a, b) = list(map(int, input().split()))
	c.append(a)
	d.append(b)
for i in range(x):
	if c[i] % d[i] == 0:
		print('0')
	elif c[i] > d[i]:
		f = c[i] % d[i]
		print(d[i] - f)
	else:
		print(d[i] - c[i])


t = input()
t = int(t)
while t > 0:
	x = input()
	x = x.split(' ')
	(a, b) = (int(x[0]), int(x[1]))
	if a < b:
		print(b - a)
	elif a % b == 0:
		print(0)
	else:
		count = a - a % b + b
		print(count - a)
	t = t - 1


def somaalg(numero):
	soma = 0
	while numero:
		soma += numero % 10
		numero //= 10
	return soma
t = int(input())
for i in range(t):
	(n, s) = [int(i) for i in input().split()]
	moves = 0
	potdez = 1
	while True:
		if somaalg(n) <= s:
			break
		else:
			alg = n // potdez % 10
			moves += (10 - alg) * potdez
			n += (10 - alg) * potdez
			potdez = potdez * 10
	print(int(moves))


from collections import defaultdict
from itertools import zip_longest
from math import ceil
for i in range(int(input())):
	(a, b) = map(int, input().split())
	if a <= b:
		print(b - a)
	else:
		y = ceil(a / b)
		print(y * b - a)


tcase = int(input())
for i in range(tcase):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	elif a < b:
		print(b - a)
	else:
		c = b - a % b
		print(c)


from collections import Counter
from collections import defaultdict
import math
t = int(input())
for _ in range(0, t):
	(a, b) = list(map(int, input().split()))
	s = math.ceil(a / b)
	s1 = s * b
	print(s1 - a)


t = int(input())
ans = []
for _ in range(t):
	(n, s) = map(int, input().split())
	n = str(n)[::-1]
	temp = 0
	if sum([int(c) for c in n]) <= s:
		ans.append(temp)
	else:
		num_lis = [0] * 19
		for (i, c) in enumerate(n):
			num_lis[i] = int(c)
		digit = 1
		for i in range(19):
			if num_lis[i] != 0:
				temp += (10 - num_lis[i]) * digit
				num_lis[i] = 0
				num_lis[i + 1] += 1
				if sum(num_lis) <= s:
					ans.append(temp)
					break
			digit *= 10
print(*ans, sep='\n')


def digsum(nc, s):
	sodfun = 0
	while nc > 0:
		sodfun += nc % 10
		nc = nc // 10
	if sodfun <= s:
		return True
	else:
		return False
for t in range(int(input())):
	(n, s) = [int(k) for k in input().split()]
	sod = 0
	dig = 0
	nc = n
	while nc > 0:
		sod += nc % 10
		dig += 1
		nc = nc // 10
	if sod <= s:
		print(0)
	else:
		nc = n
		exp = 1
		for i in range(1, dig + 2):
			exp *= 10
			rem = nc % 10
			nc = nc // 10
			nd = nc + 1
			if digsum(nd, s):
				print(nd * exp - n)
				break


import sys

def input():
	return sys.stdin.readline()[:-1]

def getInt():
	return int(input())

def getIntIter():
	return map(int, input().split())

def getIntList():
	return list(getIntIter())
for _ in range(int(input())):
	(n, s) = getIntIter()
	digits = []
	while n > 0:
		digits.insert(0, n % 10)
		n = n // 10
	if sum(digits) <= s:
		print(0)
	else:
		currSum = 0
		i = -1
		while currSum < s and i + 1 < len(digits):
			i += 1
			currSum += digits[i]
		digits = digits[i:]
		num = sum((10 ** (len(digits) - 1 - i) * digits[i] for i in range(len(digits))))
		print(10 ** len(digits) - num)


n = input()
n = int(n)
for i in range(n):
	(a, b) = (int(z) for z in input().split())
	if a % b == 0:
		ans = 0
	else:
		ans = b - a % b
	print(ans)


import math

def ii():
	return int(input())

def si():
	return input()

def li():
	return list(map(int, input().split()))

def mi():
	return map(int, input().split())

def dpc(a, b):
	return [[0] * b for i in range(a)]

def sum_digits(n):
	r = 0
	while n:
		(r, n) = (r + n % 10, n // 10)
	return r

def solve():
	(n, s) = mi()
	sm = sum_digits(n)
	move = 0
	while sm > s:
		temp = str(n)
		d = 0
		cnt = -1
		for i in range(len(temp) - 1, -1, -1):
			cnt += 1
			if temp[i] != '0':
				d = int(temp[i])
				break
		move += (10 - d) * 10 ** cnt
		n += (10 - d) * 10 ** cnt
		sm = sum_digits(n)
	print(move)
t = ii()
for _ in range(t):
	solve()


import sys
t = int(sys.stdin.readline().strip())
for _ in range(t):
	(n, s) = map(int, sys.stdin.readline().strip().split())
	orin = n
	tot = 0
	for x in str(n):
		tot += int(x)
	ans = 0
	add = 1
	ind = -1
	while tot > s:
		while str(n)[ind] != '0':
			n += add
		tot = 0
		for x in str(n):
			tot += int(x)
		ind -= 1
		add *= 10
	print(n - orin)


n = int(input())
x = []
for i in range(n):
	y = str(input())
	z = y.split(' ')
	(a, b) = (int(z[0]), int(z[1]))
	m = a % b
	if m == 0:
		x.append(m)
	else:
		x.append(b - m)
for i in x:
	print(i)


amount = int(input())
for testCase in range(amount):
	inp = input().split()
	A = int(inp[0])
	b = int(inp[1])
	dif = A % b
	if dif == 0:
		print(0)
	else:
		print(str(b - dif))


import math
t = int(input())
while t > 0:
	(a, b) = map(int, input().split())
	if b > a:
		print(b - a)
	elif b == 1 or a == b or a % b == 0:
		print(0)
	else:
		remainder = a % b
		print(b - remainder)
	t -= 1


import sys
import os
from io import IOBase, BytesIO
import math
mod = 10 ** 9 + 7
pie = 3.1415926536

def modinv(n, p):
	return pow(n, p - 2, p)

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def ain():
	return list(map(int, sin().split()))

def sin():
	return input().strip()

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def read2DIntArray(row, col):
	arr = []
	for i in range(0, row):
		temp = list(map(int, sin().split()))
		arr.append(temp)
	return arr

def read2DCharArray(row, col):
	arr = []
	for i in range(0, row):
		temp = str(sin())
		arr.append(temp)
	return arr

def smallestNumber(n):
	lst = list(str(n))
	lst.sort()
	tmp = ''
	for (i, n) in enumerate(lst):
		if n != '0':
			tmp = lst.pop(i)
			break
	return str(tmp) + ''.join(lst)

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = False
	prime[1] = False
	lst = []
	for p in range(n + 1):
		if prime[p]:
			lst.append(p)
	return lst

def nCr(n, r):
	a = 1
	b = 1
	c = 1
	for i in range(1, n + 1):
		c *= i
	for i in range(1, r + 1):
		b *= i
	for i in range(1, n - r + 1):
		a *= i
	return c // (a * b)

def sieveOfEratosthenes1(N, s):
	prime = [False] * (N + 1)
	for i in range(2, N + 1, 2):
		s[i] = 2
	for i in range(3, N + 1, 2):
		if prime[i] == False:
			s[i] = i
			for j in range(i, int(N / i) + 1, 2):
				if prime[i * j] == False:
					prime[i * j] = True
					s[i * j] = i

def generatePrimeFactors(N):
	s = [0] * (N + 1)
	sieveOfEratosthenes1(N, s)
	curr = s[N]
	cnt = 1
	factors = []
	power = []
	while N > 1:
		N //= s[N]
		if curr == s[N]:
			cnt += 1
			continue
		factors.append(curr)
		power.append(cnt)
		curr = s[N]
		cnt = 1
	return (factors, power)

def main():
	for _ in range(int(sin())):
		(a, b) = map(int, sin().split())
		d = (int(a / b) + 1) * b
		if a % b == 0:
			print('0')
		else:
			print(d - a)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
for _ in range(n):
	(a, b) = [int(i) for i in input().split()]
	if not a % b:
		print(0)
	else:
		print(b - a % b)


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


q = int(input())
for qiew in range(q):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	digits = list(map(int, str(n)))
	n_dig_sum = sum(digits)
	if n_dig_sum <= s:
		print(0)
	else:
		moves = 0
		i = -1
		j = 0
		while n_dig_sum > s:
			moves += (10 - digits[i]) * 10 ** j
			digits[i] = 0
			if i == -len(digits):
				digits = [1] + digits
			else:
				digits[i - 1] += 1
			n_dig_sum = sum(digits)
			i -= 1
			j += 1
		print(moves)


t = int(input())
for _ in range(t):
	(a, b) = tuple(map(int, input().split()))
	if a % b == 0:
		answer = 0
	else:
		answer = b - a % b
	print(answer)


t = int(input())
for _ in range(t):
	(n, s) = map(int, input().split())
	total = n
	x = list(map(int, str(n)))
	sum1 = sum(x)
	if s >= sum1:
		print(0)
		continue
	i = 10
	while sum1 > s:
		if n % i != 0:
			n = n + (i - n % i)
		i *= 10
		sum1 = list(map(int, str(n)))
		sum1 = sum(sum1)
	print(n - total)


import sys
input = sys.stdin.readline
for ti in range(int(input().strip())):
	(a, b) = [int(x) for x in input().strip().split()]
	print((b - a % b) % b)


n = int(input())
arr = []
for i in range(n):
	temp = input().split()
	temp[0] = int(temp[0])
	temp[1] = int(temp[1])
	arr.append(temp)
for i in range(n):
	a = arr[i][0]
	b = arr[i][1]
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


t = int(input())
for i in range(0, t, 1):
	arr = [str(string) for string in input().split()]
	n = arr[0]
	s = arr[1]
	l1 = len(n)
	l2 = len(s)
	s_sum = int(s)
	n_sum = 0
	j = 0
	while j != l1:
		if int(n[j]) + n_sum <= s_sum:
			n_sum += int(n[j])
		else:
			break
		j += 1
	if j == l1:
		print(0)
	elif j == 0:
		ans = 10 ** len(n) - int(n)
		print(ans)
	elif int(n[0]) == s_sum and n_sum > s_sum:
		ans = 10 ** len(n) - int(n)
		print(ans)
	else:
		exceeder = int(n[j])
		offset = exceeder - (s_sum - n_sum)
		flag = 0
		new_str = ''
		while j != 0:
			prev_index_num = int(n[j - 1])
			prev_index_num += 1
			if prev_index_num == 10 or n_sum + 1 > s_sum:
				n_sum -= int(n[j - 1])
				j -= 1
				continue
			for k in range(0, j - 1):
				new_str += n[k]
			new_str += str(prev_index_num)
			for k in range(j, l1, 1):
				new_str += '0'
			flag = 1
			break
		if flag == 0:
			ans = 10 ** len(n) - int(n)
			print(ans)
		else:
			ans = int(new_str) - int(n)
			print(ans)


import sys
input = sys.stdin.readline

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()

def lower_letters():
	lowercase = [chr(i) for i in range(97, 97 + 26)]
	return lowercase

def upper_letters():
	uppercase = [chr(i) for i in range(65, 65 + 26)]
	return uppercase
for _ in range(int(input())):
	(a, b) = int_array()
	if a % b != 0:
		print(b * (a // b + 1) - a)
	else:
		print(0)


import sys
n = int(input())
while n >= 1:
	x = input().split()
	a = int(x[0])
	b = int(x[1])
	rest = a % b
	if rest == 0:
		diff = 0
	else:
		diff = b - rest
	print(diff)
	n = n - 1


t = int(input())
for ii in range(t):
	(n, s) = input().split()
	s = int(s)
	start = 0
	for i in n:
		start += int(i)
	if start <= s:
		print(0)
		continue
	count = 0
	ptr = len(n) - 1
	while start >= s:
		start -= int(n[ptr])
		ptr -= 1
		if ptr < 0:
			break
	a = len(n) - 1 - ptr
	if start > s:
		print(10 ** len(n) - int(n))
		continue
	else:
		num = []
		for i in range(len(n) - 1, ptr, -1):
			num.append(n[i])
		num = num[::-1]
		num = ''.join(num)
		num = int(num)
		print(10 ** a - num)


_1 = '236a'
_2 = '339a'
_3 = '266a'
_4 = '96a'
_5 = '236a'
_6 = '281a'
_7 = '546a'
_8 = '116a'
_9 = '977a'
_10 = '266b'
_11 = '110a'
_12 = '41a'
_13 = '734a'
_14 = '133a'
_15 = '467a'
_16 = '158a'
_17 = '677a'
_18 = '580a'
_19 = '344a'
_20 = '1030a'
_21 = '705a'
_22 = '318a'
_23 = '479a'
_24 = '486a'
_25 = '61a'
_26 = '405a'
_27 = '200b'
_28 = '337a'
_29 = '148a'
_30 = '228a'
_31 = '25a'
_32 = '25a'
_33 = '1328a'
n = int(input())
o = []
for i in range(n):
	(a, b) = map(int, input().split())
	if a % b == 0:
		o.append(0)
	else:
		o.append(b - a % b)
for i in o:
	print(i)


def sumnum(x):
	a = 0
	for i in x:
		a += int(i)
	return a

def plone(lst):
	n = 0
	for i in lst:
		n *= 10
		n += int(i)
	n += 1
	newlst = list(str(n))
	return newlst

def solve():
	(n, s) = input().split()
	s = int(s)
	lst = list(n)
	prefzero = True
	ans = []
	while len(lst):
		if prefzero and sumnum(lst) <= s:
			break
		if not prefzero and sumnum(plone(lst)) <= s:
			break
		if lst[-1] == 0:
			lst.pop()
		else:
			lst.pop()
			prefzero = False
		ans.append(0)
	if not prefzero:
		lst = plone(lst)
	k = 0
	for i in lst:
		k *= 10
		k += int(i)
	for i in ans:
		k *= 10
	print(k - int(n))
for i in range(int(input())):
	solve()


for _ in range(int(input())):
	(n, x) = input().split()
	x = int(x)
	n = list(map(str, str(n)))
	z = list(map(int, n))
	if sum(z) <= x:
		print(0)
	else:
		z = 0
		for i in range(len(n)):
			z += int(n[i])
			if z >= x:
				break
		n = n[i:]
		z = ''.join(n)
		x = len(z)
		z = int(z)
		print(10 ** x - z)


t = int(input())
data = [0] * t
ans = 0
for i in range(t):
	data = list(map(int, input().split()))
	if data[0] % data[1] != 0:
		ans = data[1] - data[0] % data[1]
	print(ans)
	ans = 0


tc = input()
tc = int(tc)
for i in range(tc):
	inp = input()
	inp_lst = inp.split()
	a = int(inp_lst[0])
	b = int(inp_lst[1])
	ans = (b - a % b) % b
	print(ans)


totalNums = int(input())
ans_ = []
index = totalNums
while totalNums > 0:
	totalNums -= 1
	a = input()
	a = a.split(' ')
	mod = int(a[0]) % int(a[1])
	if mod != 0:
		ans = int(a[1]) - mod
		ans_.append(ans)
	else:
		ans = mod
		ans_.append(ans)
i = 0
for i in range(index):
	print(ans_[i])
	i += 1


n = int(input())
for i in range(n):
	line2 = input().split(' ')
	lst = [int(x) for x in line2]
	if lst[0] % lst[1] == 0:
		print(0)
	else:
		print(lst[1] - lst[0] % lst[1])


n = int(input())
while n > 0:
	(a, b) = map(int, input().split())
	count = 0
	if a < b:
		print(b - a)
	elif a % b == 0:
		print('0')
	else:
		temp = a // b
		a1 = b * (temp + 1)
		print(a1 - a)
	n = n - 1


def res(l):
	if l[0] % l[1] == 0:
		print(0)
	else:
		k = l[0] % l[1]
		print(l[1] - k)
t = int(input())
while t > 0:
	t = t - 1
	l = list(map(int, input().split()))
	res(l)


T = int(input())

def addn(N, k):
	val = 0
	j = 1
	for i in N[::-1]:
		val += i * j
		j *= 10
	val += k
	val = list(str(val))
	val = [int(i) for i in val]
	return val

def sumd(N):
	ans = 0
	for i in N:
		ans += i
	return ans
while T > 0:
	T -= 1
	N = input()
	N = N.split(' ')
	s = int(N[1])
	n = int(N[0])
	val = 0
	ans = 0
	N = list(N[0])
	N = [int(x) for x in N]
	for i in N:
		val += i
	i = len(N) - 1
	while val > s:
		if N[i] != 0:
			val -= N[i]
			ans += (10 - N[i]) * pow(10, len(N) - i - 1)
			N = addn(N, (10 - N[i]) * pow(10, len(N) - i - 1))
			val = sumd(N)
		i -= 1
	print(ans)


def digitsum(x):
	res = 0
	while x > 0:
		res += x % 10
		x //= 10
	return res

def solve():
	res = 10 ** 30
	(n, s) = map(int, input().split())
	if digitsum(n) <= s:
		return 0
	N = len(str(n))
	for i in range(1, N + 1):
		P = pow10[i] - n % pow10[i]
		if digitsum(n + P) <= s:
			res = min(res, P)
	return res
t = int(input())
pow10 = [1]
for i in range(20):
	pow10.append(pow10[-1] * 10)
for i in range(t):
	print(solve())


def solve():
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if a < b:
		print(b - a)
	elif a % b == 0:
		print(0)
	else:
		print(b - a % b)
t = int(input())
for i in range(0, t):
	solve()


t = int(input())
for ex in range(t):
	(n, s) = [int(i) for i in input().split()]
	di = list()
	n1 = n
	while n1 > 0:
		di.append(n1 % 10)
		n1 //= 10
	di_s = sum(di)
	ans = -1
	if di_s <= s:
		print(0)
	else:
		for i in range(len(di)):
			if di_s + 1 <= s:
				ans = (n // 10 ** i + 1) * 10 ** i - n
				break
			else:
				di_s -= di[i]
		if ans == -1:
			print(10 ** len(di) - n)
		else:
			print(ans)


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop, heapify
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
from itertools import accumulate
from functools import lru_cache
M = mod = 998244353

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]

def givesum(n):
	return sum([int(i) for i in str(n)])
for _ in range(val()):
	(n, s) = li()
	ans = 0
	curr = 10
	while givesum(n) > s:
		temp = n % curr
		n += curr - temp
		ans += curr - temp
		curr *= 10
	print(ans)


for _t in range(int(input())):
	(a, b) = map(int, input().strip().split())
	print((b - a % b) % b)


a = int(input())
k = []
t = []
p = 0
for i in range(a):
	p = 0
	k = list(map(int, input().split()))
	if k[0] < k[1]:
		print(k[1] - k[0])
	elif k[0] == k[1]:
		print('0')
	else:
		if k[0] % k[1] != 0:
			l = k[0] % k[1]
			p = k[1] - l
		print(p)


num = int(input())
for i in range(num):
	l = input().split()
	a = int(l[0])
	b = int(l[1])
	if a % b == 0:
		print(0)
	else:
		print(int(b - a % b))


def solve(n, k):
	return 0 if n % k == 0 else k - n % k
p = int(input())
for _ in range(p):
	(n, k) = list(map(int, input().split()))
	result = solve(n, k)
	print(result)


def count(x, y):
	if x % y == 0:
		return 0
	elif x < y:
		return y - x
	else:
		c = x // y
		c += 1
		c = y * c - x
		return c
n = int(input())
while n > 0:
	ar = [int(f) for f in input().split()]
	x = ar[0]
	y = ar[1]
	print(count(x, y))
	n -= 1


from sys import stdin, stdout
from math import *
import itertools
import sys
for z in range(int(input())):
	(a, b) = map(int, input().split())
	print(int(ceil(a / b) * b - a))


try:
	for _ in range(int(input())):
		(a, b) = map(int, input().split())
		if a % b != 0:
			print((a // b + 1) * b - a)
		else:
			print(0)
except Exception as e:
	print(e)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		answer = 0
	elif a > b:
		multi = 1 + a // b
		pas = multi * b
		answer = pas - a
	else:
		answer = b - a
	print(answer)


import math

def solve():
	(n, s) = map(int, input().split())
	nums = list(reversed(list(map(int, str(n)))))
	nums.append(0)
	if sum(nums) <= s:
		print(0)
		return
	i = 0
	while i < len(nums):
		nums[i] = 0
		i += 1
		while nums[i] == 9:
			nums[i] = 0
			i += 1
		nums[i] = nums[i] + 1
		if sum(nums) <= s:
			break
	new_n = int(''.join(map(str, reversed(nums))))
	print(new_n - n)
T = int(input())
for _ in range(T):
	solve()


from collections import defaultdict
from collections import Counter
from sys import setrecursionlimit as srl
srl(2 * 10 ** 6)
import sys

def sum_dig(n):
	s = 0
	while n > 0:
		s += n % 10
		n = n // 10
	return s

def solve(n, s):
	if sum_dig(n) <= s:
		return 0
	else:
		r = 1
		old_n = n
		while sum_dig(n) > s:
			r = r * 10
			n = n // 10
			n += 1
	return n * r - old_n
t = int(input())
while t:
	(n, s) = map(int, input().split())
	print(solve(n, s))
	t -= 1


def noMoves(arr):
	a = arr[0]
	b = arr[1]
	c = a // b
	d = a / b
	if c == d:
		return 0
	return b * (c + 1) - a
i = int(input())
for j in range(0, i):
	arr = [int(num) for num in input().split()]
	print(noMoves(arr))


from math import *
from copy import *
from string import *
from random import *
from bisect import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
from collections import defaultdict

def solve(l):
	n = len(l)
T = int(input())
for _ in range(T):
	(a, b) = list(map(int, stdin.readline().rstrip().split()))
	if a % b == 0:
		print(0)
	else:
		print(abs(b - a % b))


test = int(input())
for x in range(1, test + 1):
	cnt = int(0)
	(a, b) = map(int, input().split())
	if a % b == 0:
		print('0')
	else:
		cnt = b - a % b
		print(cnt)


for _ in range(int(input())):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	an = a // b
	if b * an == a:
		print(0)
	else:
		print(b * (an + 1) - a)


import math
n = int(input())
for i in range(n):
	(l, m) = input().split()
	l = int(l)
	m = int(m)
	if l <= m:
		print(m - l)
	else:
		k = l / m
		m *= math.ceil(k)
		print(m - l)


t = int(input())
for z in range(t):
	(n, s) = [int(q) for q in input().split()]
	n = str(n)
	c = 0
	p = False
	for i in range(len(n)):
		c += int(n[i])
		if c >= s:
			if sum((int(q) for q in n)) <= s:
				p = True
				print(0)
				break
			else:
				p = True
				a = 1 if i == 0 else int(n[:i]) + 1
				a = int(str(a) + '0' * (len(n) - i))
				print(a - int(n))
				break
	if not p:
		print(0)


t = int(input())
while t:
	t -= 1
	(a, b) = list(map(int, input().split()))
	res = 0
	if int(a % b) != 0:
		if a > b:
			r = int(a / b)
			res = b * (r + 1) - a
		elif a < b:
			res = b - a
	else:
		res = 0
	print(res)


from math import ceil
t = int(input())
l = []
for i in range(t):
	li = [int(j) for j in input().split()]
	l.append(li)
for i in range(len(l)):
	print(ceil(l[i][0] / l[i][1]) * l[i][1] - l[i][0])


lis = []
for i in range(int(input())):
	(num1, num2) = map(int, input().split())
	if num2 > num1:
		lis.append(num2 - num1)
	elif num1 % num2 == 0:
		lis.append(0)
	else:
		lis.append(num2 - num1 % num2)
for i in lis:
	print(i)


for _ in range(int(input())):
	(x, y) = list(map(int, input().split()))
	print(abs(x % -y))


from bisect import bisect_left
import os
import sys
from io import BytesIO, IOBase
from collections import Counter, defaultdict
from collections import deque
from functools import cmp_to_key
import math
import heapq

def sin():
	return input()

def ain():
	return list(map(int, sin().split()))

def sain():
	return input().split()

def iin():
	return int(sin())
MAX = float('inf')
MIN = float('-inf')
MOD = 1000000007

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	s = set()
	for p in range(2, n + 1):
		if prime[p]:
			s.add(p)
	return s

def readTree(n, m):
	adj = [deque([]) for _ in range(n + 1)]
	for _ in range(m):
		(u, v) = ain()
		adj[u].append(v)
		adj[v].append(u)
	return adj

def main():
	for _ in range(iin()):
		(n, s) = ain()
		sn = list(str(n))
		x = 0
		ll = len(sn)
		for i in range(ll):
			sn[i] = int(sn[i])
			x += sn[i]
		if x <= s:
			print(0)
		else:
			i = ll - 1
			j = -1
			while i > 0:
				if sn[i] != 0:
					sn[i] = 0
					sn[i - 1] += 1
					if sn[i - 1] == 10:
						j = i - 1
						while j >= 0:
							if j == 0:
								sn[j] = 10
								break
							sn[j] = 0
							sn[j - 1] += 1
							if sn[j - 1] != 10:
								break
							j -= 1
						i = j
					else:
						i -= 1
				else:
					i -= 1
				if sum(sn) <= s:
					break
			ans = ''
			for i in sn:
				ans += str(i)
			ans = int(ans)
			if sum(sn) > s:
				ans = 10 ** ll
			print(ans - n)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
if os.getcwd() == 'D:\\code':
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


i = int
n = input
exec(i(n()) * 'a,b=map(i,n().split());print([b-(a%b),0][a%b==0]);')


n = int(input())
for i in range(1, n + 1):
	l = list(map(int, input().split()))
	b = l[0]
	a = l[1]
	if b % a == 0:
		print(0)
	else:
		con = b // a
		ans = (con + 1) * a - b
		print(ans)


def sum_digits(n):
	n = str(n)
	return sum(map(int, n))
testes = int(input())
for i in range(testes):
	(a, b) = input().split()
	(a, b) = (int(a), int(b))
	v = a
	d = 1
	while sum_digits(a) > b:
		c = a // d % 10
		a += -c % 10 * d
		d *= 10
	print(a - v)


t = int(input())
for i in range(t):
	(m, n) = map(int, input().split())
	if m % n == 0:
		print(0)
	else:
		k = m // n
		d = k + 1
		if n > m:
			print(n - m)
		elif n * k < m:
			print(abs(m - n * d))


t = int(input())
count = 0
while count < t:
	count += 1
	ints = list(map(int, input().split(' ')))
	n = ints[0]
	m = ints[1]
	if n % m == 0:
		print(0)
	else:
		print(m - n % m)


t = int(input())
sol = []
while t:
	t -= 1
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	nr = 0
	if a > b:
		if a % b:
			nr = b - a % b
	else:
		nr = b - a
	sol.append(nr)
print(*sol, sep='\n')


t = int(input())
for T in range(t):
	(a, b) = [int(x) for x in input().split()]
	rem = a % b
	if rem > 0:
		rem = b - rem
	print(rem)


import sys
import os
DEBUG = True

class Scan:

	def __init__(self):
		self.read = sys.stdin.read
		self.input = sys.stdin.readline

	def integer(self, count=1):
		if count == 1:
			return self._integer()
		return [self._integer() for _ in range(count)]

	def _integer(self):
		sym: str = self.read(1)
		(number, sign) = (0, -1) if sym == '-' else (int(sym), 1)
		sym: str = self.read(1)
		while sym.isdigit():
			number = number * 10 + int(sym)
			sym = self.read(1)
		return number * sign

def solution(scan: Scan):
	(a, b) = scan.integer(2)
	if a % b == 0:
		sys.stdout.write(str(0) + '\n')
	else:
		sys.stdout.write(str((a // b + 1) * b - a) + '\n')

def main():
	queries: int = 1
	scan = Scan()
	queries = scan.integer()
	for _ in range(queries):
		solution(scan)
main()


def divison(a, b):
	if a % b == 0:
		return 0
	else:
		m = a // b
		number = b * (m + 1)
		return number - a
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	print(divison(a, b))


def div(a, b):
	if a <= b:
		return b - a
	elif a % b == 0:
		return 0
	else:
		x = a % b
		return b - x
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	print(div(a, b))


num_lines = int(input())
for i in range(num_lines):
	(a, b) = list(map(int, input().split()))
	remainder = a % b
	if remainder == 0:
		print(remainder)
		continue
	print(b - remainder)


a = int(input())
for j in range(a):
	(n, x) = [int(i) for i in input().split()]
	if n % x:
		print((int(n / x) + 1) * x - n)
	else:
		print(0)


def add(a, b):
	return -a % b
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split(' '))
	print(add(a, b))


test = int(input())
for temp in range(test):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print('0')
	else:
		print(b * (a // b + 1) - a)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	k = a // b
	s = b * k
	while s < a:
		s = b * (k + 1)
	print(s - a)


def main():
	t = int(input())
	for i in range(t):
		(a, b) = list(map(int, input().split()))
		Divisible(a, b)

def Divisible(a, b):
	count = 0
	if a % b == 0:
		print('0')
		return
	else:
		div = a // b
		num = b * (div + 1)
		diff = num - a
		print(diff)
		return
main()


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	dn = str(n)
	len_ = len(dn)
	(i, sum_) = (0, 0)
	while i < len_ and sum_ < s:
		sum_ += int(dn[i])
		i += 1
	if i == len_ and sum_ <= s:
		print(0)
	elif sum_ == s and int(''.join(dn[i:])) == 0:
		print(0)
	else:
		i -= 1
		suffix = int(''.join(dn[i:]))
		print(10 ** (len_ - i) - suffix)


for i in range(int(input())):
	lt = input().split()
	x = int(lt[0])
	y = int(lt[1])
	print([y - x % y, 0][x % y == 0])


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	(a, s) = I()
	an = 0
	p = str(a)
	cr = 0
	if sum((int(i) for i in p)) <= s:
		an = a
	else:
		for i in range(len(p)):
			cr += int(p[i])
			if cr >= s:
				an = (an + 1) * 10 ** (len(p) - i)
				break
			an = an * 10 + int(p[i])
	print(an - a)


t = int(input())
for test in range(t):
	(a, b) = map(int, input().split(' '))
	if a % b == 0:
		answer = 0
	else:
		remainder = a % b
		answer = b - remainder
	print(answer)


from sys import stdin, stdout

class SOLVE:

	def solve(self):
		R = stdin.readline
		W = stdout.write
		ans = []
		for i in range(int(input())):
			(n, s) = [x for x in R().split()]
			s = int(s)
			if sum([int(x) for x in n]) <= s:
				ans += ['0']
				continue
			temps = 0
			for j in range(len(n)):
				temps += int(n[j])
				if temps >= s:
					ans += [str(int(str(int('0' + n[:j]) + 1) + (len(n) - j) * '0') - int(n))]
					break
		W('\n'.join(ans))

def main():
	s = SOLVE()
	s.solve()
main()


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, S):
	digitStr = str(N)
	digits = [int(x) for x in digitStr]
	if sum(digits) <= S:
		return 0
	best = float('inf')
	for (i, d) in enumerate(digits):
		temp = str(int(digitStr[:i] or 0) + 1) + '0' * (len(digits) - i)
		if sum(map(int, temp)) <= S:
			best = min(best, int(temp) - N)
	return best
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = int(input())
for tc in range(1, TC + 1):
	(N, S) = [int(x) for x in input().split()]
	ans = solve(N, S)
	print(ans)


n = int(input())
x = []
y = []
for i in range(n):
	(a, b) = map(int, input().split())
	x.append(a)
	y.append(b)
for j in range(len(x)):
	if x[j] % y[j] != 0:
		print(y[j] - x[j] % y[j])
	else:
		print('0')


import sys, math
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
t = 1
t = inp()
for tt in range(t):
	(n, k) = invr()
	print(k * math.ceil(n / k) - n)


k = []
for i in range(0, int(input())):
	k.append(input().split())
	if int(k[i][0]) % int(k[i][1]) == 0:
		print(0)
	elif int(k[i][0]) > int(k[i][1]):
		print(int(k[i][1]) - int(k[i][0]) % int(k[i][1]))
	else:
		print(int(k[i][1]) - int(k[i][0]))


def su(a):
	an = 0
	while a > 0:
		an += a % 10
		a = a // 10
	return an
t = int(input())
for i in range(1, t + 1):
	(n, s) = map(int, input().split())
	if su(n) <= s:
		print('0')
		continue
	ans = 0
	p = 1
	for i in range(18):
		dig = n // p % 10
		ad = p * ((10 - dig) % 10)
		ans += ad
		n += ad
		if su(n) <= s:
			break
		p *= 10
	print(ans)


for i in range(int(input())):
	(a, b) = map(int, input().split(' '))
	if a % b == 0:
		print('0')
	else:
		steps = 0
		temp = a // b
		print(b * (temp + 1) - a)


t = int(input())
while t > 0:
	(m, n) = map(int, input().split())
	if m % n == 0:
		print('0')
	else:
		k = m % n
		print(abs(n - k))
	t = t - 1


t = int(input())
for i in range(t):
	(n, s) = map(int, input().split())
	j = 0
	n = str(n)
	k = 0
	while j < len(n) and k + int(n[j]) <= s:
		k += int(n[j])
		j += 1
	if j == len(n):
		print(0)
	elif j == 0:
		print(int('1' + '0' * len(n)) - int(n))
	else:
		h = str((int(n[:j]) + 1) * 10 ** (len(n) - j))
		l = True
		while l:
			j = 0
			k = 0
			while j < len(h) and k + int(h[j]) <= s:
				k += int(h[j])
				j += 1
			if j == 0:
				h = '1' + '0' * len(n)
				l = False
			elif j != len(h):
				h = str((int(h[:j]) + 1) * 10 ** (len(h) - j))
			else:
				l = False
		print(int(h) - int(n))


def read_array():
	x = []
	x1 = []
	x = input()
	x = x.split(' ')
	for v in x:
		x1.append(int(v))
	return x1
x = int(input())
re = []
for r in range(x):
	x = read_array()
	a = x[0]
	b = x[1]
	if b > a:
		re.append(b - a)
	elif a % b == 0:
		re.append(0)
	else:
		re.append(b - a % b)
for v in re:
	print(v)


t = int(input())
for _ in range(t):
	(x, y) = map(int, input().split())
	if x % y == 0:
		print(0)
	else:
		rem1 = x % y
		rem2 = y - rem1
		print(y - rem1)


t = int(input())
ab = [list(map(int, input().split())) for _ in range(t)]
for abi in ab:
	if abi[0] % abi[1] == 0:
		print(0)
	else:
		print(abi[1] - abi[0] % abi[1])


def fun(a, b):
	if a % b == 0:
		return 0
	else:
		x = a // b
		y = (x + 1) * b
		return y - a
for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	print(fun(a, b))


t = int(input())
for _ in range(t):
	(a, b) = (int(x) for x in input().split())
	temp = a % b
	if temp != 0:
		print(abs(b - temp))
	else:
		print(temp)


t = int(input())
for _ in range(t):
	(n, s) = [int(x) for x in input().split()]
	arr = [int(x) for x in str(n)]
	currsum = sum(arr)
	while currsum > s:
		for j in range(len(arr) - 1, -1, -1):
			if arr[j] != 0:
				break
		arr[j] = 0
		j -= 1
		if j == -1:
			arr.insert(0, 0)
			j += 1
		while arr[j] == 9:
			arr[j] = 0
			j -= 1
			if j == -1:
				arr.insert(0, 0)
				j += 1
				break
		arr[j] += 1
		currsum = sum(arr)
	newN = int(''.join([str(x) for x in arr]))
	print(newN - n)


to = int(input())
for i in range(to):
	(a, b) = map(int, input().split())
	print((b - a % b) % b)


for x in range(int(input())):
	a = list(map(int, input().split()))
	x = a[0]
	y = a[-1]
	if x % y == 0:
		print(0)
	elif x < y:
		print(y - x)
	elif x > y:
		c = y - x % y
		print(c)
	else:
		print(0)


import sys
import math
nums = sys.stdin.read().split()
nums.remove(nums[0])
nums = [int(i) for i in nums]
pairs = [nums[i * 2:(i + 1) * 2] for i in range(int(len(nums) / 2))]
for (m, n) in pairs:
	print(math.ceil(m / n) * n - m)


import math
a = b = None
n = int(input())
str1 = None
r = None
for i in range(1, n + 1, 1):
	str1 = input().split()
	a = int(str1[0])
	b = int(str1[1])
	d = math.ceil(a / b)
	r = int(abs(a - b * d))
	print(r)


tst_cas = int(input())
for x in range(tst_cas):
	(a, b) = [int(k) for k in input().split()]
	cnt = 0
	rem = a % b
	if rem != 0:
		print(b - rem)
	else:
		print(0)


a = int(input())
for i in range(a):
	(p, q) = map(int, input().split())
	f = p % q
	if f == 0:
		print(0)
	else:
		w = p // q
		s = (w + 1) * q - p
		print(s)


def digsum(n):
	summ = 0
	while n:
		summ += n % 10
		n //= 10
	return summ
t = int(input())
for i in range(t):
	(n, s) = map(int, input().split())
	if digsum(n) <= s:
		print(0)
	else:
		n1 = n
		n_str = '0' + str(n)
		n2 = []
		for char in n_str:
			num = int(char)
			n2.append(num)
		l = len(n2)
		for j in range(len(n2)):
			n2[l - 1] = 0
			n2[l - 2] += 1
			if sum(n2) <= s:
				break
			l -= 1
		n2 = n2[::-1]
		n3 = 0
		for i in range(len(n2)):
			n3 += n2[i] * 10 ** i
		print(n3 - n1)


t = int(input())
u = 0
i = 0
j = 0
a1 = []
b2 = []
while u != t:
	(a, b) = [int(x) for x in input().split()]
	a1.append(a)
	b2.append(b)
	u += 1
while i != t:
	if a1[i] % b2[i] == 0:
		print(0)
	else:
		j = b2[i] - a1[i] % b2[i]
		print(j)
	i += 1


import sys
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
		continue
	m = a // b + 1
	print(m * b - a)


tests = int(input())
aaa = []
bbb = []
for i in range(0, tests):
	ab = list(map(int, input().split()))
	aaa.append(ab[0])
	bbb.append(ab[1])
for i in range(0, tests):
	a = aaa[i]
	b = bbb[i]
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


def digsum(n):
	ret = 0
	while n > 0:
		ret += n % 10
		n = n // 10
	return ret

def solve():
	(n, s) = map(int, input().split())
	ans = 0
	i = 0
	while digsum(n) > s and i < 20:
		d = n % pow(10, i + 1)
		d = digsum(d)
		if d != 0:
			n += (10 - d) * pow(10, i)
			ans += (10 - d) * pow(10, i)
		i += 1
	print(ans)
for _ in range(int(input())):
	solve()


cq = int(input())
ql = list()
fl = list()
for _ in range(cq):
	ql.append(tuple(map(int, input().split(' '))))
for (a, b) in ql:
	if a % b == 0:
		fl.append(0)
	else:
		fl.append(b - a % b)
for ans in fl:
	print(ans)


t = int(input())
m = []
for i in range(t):
	ab = list(map(int, input().split(' ')))
	a = ab[0]
	b = ab[1]
	x = a % b
	y = b - x
	if y == b:
		m.append(0)
	else:
		m.append(y)
for i in m:
	print(i)


n = int(input())
answers = []
for i in range(n):
	(a, b) = [int(x) for x in input().split()]
	if a % b == 0:
		answers.append(0)
	else:
		answers.append(b - a % b)
for i in range(n):
	print(answers[i])


T = int(input())
while T > 0:
	(a, b) = map(int, input().split())
	c = 0
	i = int(a / b)
	if a > b * i:
		res = b * (i + 1)
		c = res - a
	print(c)
	T -= 1


T = int(input())
for _ in range(T):
	(a, b) = map(int, input().split())
	c = (a + b - 1) // b
	print(c * b - a)


def disum(x):
	ans = 0
	while x:
		ans += x % 10
		x //= 10
	return ans

def solve():
	(n, s) = map(int, input().split())
	if disum(n) <= s:
		return 0
	mii = 1
	while 1:
		now = n + mii
		now //= mii
		now *= mii
		if disum(now) <= s:
			return now - n
		mii *= 10
t = int(input())
for i in range(t):
	print(solve())


t = int(input())
l = []
for i in range(t):
	(n, s) = map(int, input().split())
	dig = 0
	x = n
	sum = 0
	l1 = []
	while x > 0:
		dig += 1
		sum += x % 10
		l1.append(x % 10)
		x //= 10
	if sum <= s:
		l.append(0)
	else:
		y = 10 ** dig
		sum = 0
		a = dig
		for j in range(dig - 1, -1, -1):
			sum += l1[j]
			if sum >= s:
				break
			a -= 1
		n = n % 10 ** a
		l.append(10 ** a - n)
for i in l:
	print(i)


n = int(input())
c = 0
for i in range(n):
	(s1, s2) = list(map(int, input().split()))
	s = s1 % s2
	if s != 0:
		print(s2 - s)
	else:
		print('0')


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	sum_of_digit = 0
	m = n
	digit_cnt = 0
	while m:
		sum_of_digit += m % 10
		digit_cnt += 1
		m //= 10
	if sum_of_digit <= s:
		print(0)
		continue
	m = n
	digit_cnt2 = 0
	flag = 0
	while m:
		sum_of_digit -= m % 10
		m //= 10
		digit_cnt2 += 1
		if m and sum_of_digit <= s - 1:
			m += 1
			while digit_cnt2:
				digit_cnt2 -= 1
				m *= 10
			print(m - n)
			flag = 1
			break
	if flag:
		continue
	m = 1
	while digit_cnt:
		digit_cnt -= 1
		m *= 10
	print(m - n)


for a0 in range(int(input())):
	(a, b) = list(map(int, input().split()))
	x = a % b
	if x == 0:
		print(0)
	else:
		print(b - x)


import math
from collections import Counter, defaultdict as dft, deque

def mp():
	return map(int, input().split())

def ml():
	return list(map(int, input().split()))

def solve():
	(n, s) = input().split()
	s = int(s)
	ls = list(n)
	ln = len(ls)
	ls = deque([int(num) for num in ls])
	sm = sum(ls)
	step = 0
	while sm > s:
		i = ln - 1
		temp = 0
		while ls[i] == 0:
			i -= 1
			temp += 1
		step += (10 - ls[i]) * int(math.pow(10, temp))
		ls[i] = 0
		i -= 1
		while i >= 0 and ls[i] == 9:
			ls[i] = 0
			i -= 1
		if i == -1:
			ls.appendleft(1)
			ln += 1
		else:
			ls[i] += 1
		sm = sum(ls)
	print(step)
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	s = list(str(n))
	c = 0
	ss = len(s)
	for i in s:
		c += int(i)
	if c <= x:
		print(0)
	else:
		for i in range(len(s) - 1, 0, -1):
			if s[i] == '0':
				continue
			if c <= x:
				break
			elif s[i - 1] == '9':
				for j in range(i - 1, -1, -1):
					if s[j] == '9' and j != 0:
						c -= 9
						s[j] = '0'
					elif j == 0 and s[j] == '9':
						c -= 8
						s[j] = str(int(s[j]) + 1)
					else:
						c += 1
						s[j] = str(int(s[j]) + 1)
						break
				c -= int(s[i])
				s[i] = '0'
			else:
				c -= int(s[i])
				c += 1
				s[i] = '0'
				s[i - 1] = str(int(s[i - 1]) + 1)
		if c > x:
			s[0] = '1'
			s.append('0')
			xx = ''.join(s)
			xx = int(xx)
			print(xx - n)
		else:
			xx = ''.join(s)
			xx = int(xx)
			print(xx - n)


a = int(input())
for x in range(a):
	(b, c) = map(int, input().split())
	if b > c and b / c % 1 == 0:
		print(0)
	elif c >= b:
		print(c - b)
	else:
		k = c * (b // c + 1) - b
		print(k)


T = int(input())
for case in range(T):
	(m, n) = [int(x) for x in input().split(' ')]
	if m % n == 0:
		print(0)
	else:
		print(n - m % n)


def main():
	t = int(input())
	for _ in range(t):
		(a, b) = map(int, input().split())
		v = a % b
		if v == 0:
			print(v)
		else:
			print(b - v)
main()


t = int(input())
for i in range(t):
	cont = 2
	(a, b) = map(int, input().split())
	if b > a:
		print(b - a)
	elif a % b == 0:
		print(0)
	else:
		print(b - a % b)


t = input('')
results = ''
for i in range(int(t)):
	x = input('').split(' ')
	a = int(x[0])
	b = int(x[1])
	if a % b == 0:
		r = 0
	else:
		c = a % b
		r = b - c
	results += str(r) + '\n'
print(results)


N = int(input())
while N != 0:
	n = str(input())
	n = n.split()
	a = int(n[0])
	b = int(n[1])
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)
	N -= 1


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 998244353

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
	(a, b) = li()
	if a <= b:
		print(b - a)
	else:
		print(b - a % b if a % b != 0 else 0)


def getSteps(a, b):
	if a % b == 0:
		return 0
	return b - a % b
n = int(input())
answers = []
for i in range(n):
	(a, b) = list(map(int, input().split()))
	answers.append(getSteps(a, b))
for ans in answers:
	print(ans)


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return [int(i) for i in input().split()]

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)
for _ in range(ii()):
	(a, b) = mi()
	print(b - a % b) if a % b else print(0)


from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def main():
	for _ in range(ii()):
		(a, b) = mi()
		x = a % b
		if x == 0:
			print(x)
		else:
			y = b - x
			print(y)
main()


import os
from io import BytesIO, IOBase
import sys

def main():
	for _ in range(int(input())):
		(n, s) = input().split()
		(su, la) = (0, len(n))
		n = n.rstrip()
		s = int(s)
		for i in n:
			su += int(i)
		n = int(n)
		if su <= s:
			print(0)
		else:
			ans = 0
			flag = 0
			for i in range(la):
				if n % 10 != 0:
					z = pow(10, i)
					ans += (10 - n % 10) * z
					su = su - n % 10 + 1
					n = n + (10 - n % 10)
					flag = 1
				elif flag == 1:
					su -= 9
				if su <= s:
					break
				n = n // 10
			print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


test = int(input())
for _ in range(test):
	(n, s) = map(int, input().split())
	ns = str(n)
	flag = False
	last = -1
	for i in range(len(ns)):
		if int(ns[i]) > s:
			if s == 0:
				h = ns[last + 1:]
				l = len(h)
				dd = 10 ** l
				ans = dd - int(h)
				print(ans)
			else:
				h = ns[i:]
				l = len(h)
				dd = 10 ** l
				ans = dd - int(h)
				print(ans)
			flag = True
			break
		else:
			s -= int(ns[i])
			if s:
				last = i
	if flag == False:
		print(0)


t = int(input())
while t > 0:
	t -= 1
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	j = int(0)
	if n % m == 0:
		print(0)
	else:
		j = m - n % m
		print(j)


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	k = a
	q = b
	N = 0
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


n = int(input())
for i in range(n):
	x = list(map(int, input().split()))
	if x[0] % x[1] == 0:
		print(0)
	else:
		b = int(x[0] / x[1])
		b = b + 1
		bb = b * x[1]
		print(bb - x[0])


def sum_digits(n):
	s = 0
	while n != 0:
		s = s + n % 10
		n = n // 10
	return s
a = int(input())
i = 0
while i < a:
	b = input().split(' ')
	c = int(b[0])
	r = c
	d = int(b[1])
	p = 0
	while p < 19:
		k = (10 ** p - c % 10 ** p) % 10 ** p
		c = c + k
		if sum_digits(c) <= d:
			print(c - r)
			break
		p = p + 1
	i = i + 1


for _ in range(int(input())):
	(n, s) = list(map(int, input().split()))
	ns = str(n)
	dsum = 0
	for d in ns:
		dsum += int(d)
	if dsum <= s:
		print(0)
		continue
	digits = 0
	dsum = 0
	for d in ns:
		d = int(d)
		if dsum + d > s - 1:
			break
		digits += 1
		dsum += d
	num = ns[0:digits] if digits else '0'
	num = str(int(num) + 1)
	num += (len(ns) - digits) * '0'
	print(int(num) - n)


testcase = int(input())
while testcase > 0:
	testcase = testcase - 1
	(a, b) = map(int, input().strip().split())
	print((b - a % b) % b)


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		now = a // b * b
		now_1 = now + b
		print(now_1 - a)


from sys import stdin, stdout
q = int(input())
for i in range(q):
	(a, b) = list(map(int, stdin.readline().split()))
	if a % b == 0:
		print('0')
	else:
		d = b - a % b
		print(d)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	ans = 0
	fac = 1
	while sum((int(x) for x in str(n))) > s:
		add = fac * (10 - n // fac % 10)
		n += add
		ans += add
		fac *= 10
	print(ans)


import io
import os
import sys
from io import BytesIO
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print('0')
	else:
		print(b - a % b)


from math import ceil, sqrt
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	w = ceil(a / b)
	if a % b == 0:
		print(0)
	else:
		print(w * b - a)


t = int(input())
lst = []
for i in range(t):
	lst.append([p for p in map(int, input().split(' '))])
cnt = 0
for a in lst:
	(c, d) = a
	if c % d != 0:
		cnt = d - c % d
	print(cnt)
	cnt = 0


for i in range(int(input())):
	(n, s) = map(int, input().split())
	ls = list(str(n))
	ls1 = [int(a) for a in ls]
	sm = 0
	bp = 1
	an1 = 0
	k1 = 1
	if sum(ls1) > s:
		for j in range(len(ls1)):
			if sm + ls1[j] < s and bp:
				sm += ls1[j]
				dg = j
			else:
				bp = 0
				an1 += ls1[j]
				k1 *= 10
				if j != len(ls1) - 1:
					an1 *= 10
		print(k1 - an1)
	else:
		print(0)


n = int(input())
for i in range(n):
	(a, b) = [int(x) for x in input().split()]
	if a < b:
		print(b - a)
	elif a == b or a % b == 0:
		print(0)
	else:
		j = int(a / b) + 1
		print(b * j - a)


def check_sum(x):
	sum = 0
	for i in str(x):
		sum += int(i)
	return sum
t = int(input())
for _ in range(t):
	(n, s) = [int(i) for i in input().split()]
	if check_sum(n) <= s:
		print(0)
		continue
	old_n = n
	digit = n % 10
	pow = 1
	ans = 0
	for _ in range(18):
		n += pow * (10 - digit)
		ans += pow * (10 - digit)
		if check_sum(n) <= s:
			break
		pow *= 10
		digit = n // pow % 10
	print(ans)


T = int(input().strip())
for t in range(T):
	(a, b) = map(int, input().split())
	if a == b or a % b == 0:
		print(0)
	elif a < b:
		print(b - a)
	else:
		print(b - a % b)


from sys import stdin

def get_int():
	return int(stdin.readline())

def get_str():
	return stdin.readline().strip()

def get_ints():
	return map(int, stdin.readline().strip().split())

def get_array():
	return list(map(int, stdin.readline().strip().split()))

def get_array2d(row):
	return [list(map(int, stdin.readline().strip().split())) for _ in range(row)]
T = get_int()
for _ in range(T):
	(n, s) = get_ints()
	dig = [int(x) for x in str(n)]
	Sum = sum(dig)
	ans = []
	if Sum <= s:
		print(0)
	else:
		lenN = len(dig)
		c = 0
		i = lenN - 1
		while Sum + c > s:
			if dig[i] + c == 0:
				ans.append(0)
				i -= 1
				continue
			Sum = Sum - dig[i]
			ans.append(10 - dig[i] - c)
			c = 1
			dig[i] = 0
			i -= 1
		ans = ans[::-1]
		lenAns = len(ans)
		s = 0
		while ans[s] == 0:
			s += 1
		for i in range(s, lenAns):
			print(ans[i], end='')
		print()


n = int(input())
lst = []
for i in range(n):
	(a, b) = map(int, input().split())
	d = a % b
	if a < b:
		lst.append(b - a)
	elif d != 0:
		r = (a // b + 1) * b - a
		lst.append(r)
	else:
		lst.append(0)
for i in range(n):
	print(lst[i])


t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	c = 0
	if a % b == 0:
		print(0)
		continue
	elif a < b:
		print(b - a)
		continue
	else:
		print(b - a % b)
		continue


a = int(input())
for i in range(a):
	count = 0
	b = list(map(int, input().split(' ')[:2]))
	if b[0] % b[1] == 0:
		print(0)
	else:
		print(b[1] - b[0] % b[1])


import math
for _ in range(int(input())):
	(a, b) = [int(i) for i in input().split()]
	k = math.ceil(a / b)
	x = k * b - a
	print(x)


T = int(input())
for i in range(T):
	(a, b) = map(int, input().split())
	div = int(a / b)
	if a % b == 0:
		print(0)
		continue
	else:
		print((div + 1) * b - a)


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(t,) = I()
while t:
	t -= 1
	(a, b) = I()
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


n = int(input())
for i in range(n):
	(a, b) = [int(a) for a in input().split()]
	if a % b == 0:
		print('0')
	else:
		c = a // b
		h = b * (c + 1)
		f = h - a
		print(f)


t = int(input())
for tests in range(t):
	(a, b) = map(int, input().split())
	print((b - a) % b)


from collections import defaultdict, deque
from itertools import permutations
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
import heapq
int_input = lambda : int(stdin.readline())
string_input = lambda : stdin.readline().split()
multi_int_input = lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input = lambda : list(map(int, stdin.readline().split()))
string_list_input = lambda : list(string_input())
MOD = pow(10, 9) + 7
test = int_input()
for _ in range(test):
	(a, b) = multi_int_input()
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


for _ in range(int(input())):
	(n, s) = list(map(int, input().split()))
	sd = 0
	ans = 0
	temp = n
	for i in range(len(str(n))):
		sd += int(str(n)[i])
	if sd > s:
		flag = 0
		temp = n
		sd = 0
		for i in reversed(range(len(str(n)))):
			sd_pre = sd
			temp_pre = temp
			sd += temp // 10 ** i
			temp -= temp // 10 ** i * 10 ** i
			if sd >= s:
				ans = 10 ** (i + 1) - temp_pre
				break
	print(ans)


t = int(input())

def dig_sum(num):
	res = 0
	while num:
		res += num % 10
		num //= 10
	return res

def rec_solve(num, s):
	dg = dig_sum(num)
	if dg <= s:
		return 0
	lst = num % 10
	return rec_solve(num // 10 + 1, s) * 10 + (10 - lst)

def solve():
	(n, s) = map(int, input().split())
	print(rec_solve(n, s))
for _ in range(t):
	solve()


number_test = int(input())
for k in range(number_test):
	ab = input().split(' ')
	(a, b) = (int(ab[0]), int(ab[1]))
	if a < b:
		print(b - a)
	elif a % b == 0:
		print('0')
	else:
		res = b - a % b
		print(res)


t = int(input())
for k in range(t):
	(a, b) = [int(el) for el in input().split()]
	if a % b == 0:
		print(0)
		continue
	print(b - a % b)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	digsum = lambda x: sum(map(int, str(x)))
	t = n
	while digsum(t) > s:
		for (i, j) in enumerate(str(t)[::-1]):
			if int(j) > 0:
				t += (10 - int(j)) * 10 ** i
				break
	print(t - n)


num = int(input())
sol = []
for i in range(num):
	(n, s) = [int(c) for c in input().split()]
	if n == s or sum((int(x) for x in str(n))) <= s:
		sol.append(0)
		continue
	rn = str(n)
	for i in range(0, len(rn)):
		idk = abs(10 ** (i + 1) - int(rn[len(rn) - 1 - i:]))
		if sum((int(x) for x in str(n + idk))) <= s:
			sol.append(idk)
			break
for i in sol:
	print(i)


from math import ceil, sqrt, floor, sqrt
import collections
import heapq
q = int(input())
for _ in range(q):
	(a, b) = list(map(int, input().split()))
	mod = a % b
	print((b - mod) % b)


T = int(input())
for _ in range(T):
	(a, b) = list(map(int, input().split()))
	count = 0
	if a % b == 0:
		print(count)
	else:
		i = 1
		d = a // b
		print(b * (d + 1) - a)


t = int(input())
for i in range(t):
	n = input()
	(a, b) = map(int, n.split())
	count = 0
	if a % b == 0:
		print(count)
	elif a < b:
		count = b - a
		print(count)
	else:
		count += b - a % b
		print(count)


n = int(input())
for i in range(n):
	(a, b) = list(map(int, input().split()))
	c = a % b
	if c == 0:
		print('0')
	else:
		d = b - c
		print(d)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b == 0 and a >= b:
		print(0)
	else:
		c = a % b
		print(b - c)


num = int(input())
x = 0
c = 0
for i in range(num):
	(a, b) = [int(j) for j in input().split(' ')]
	if a % b == 0:
		print(0)
	elif a < b:
		print(b - a)
	else:
		x = a % b
		c = b - x
		print(c)


import sys, threading
import math
from collections import defaultdict, Counter
input = sys.stdin.readline

def rl(type):
	return [type(w) for w in input().split()]

def reverse(arr):
	return arr[-1::-1]

def mod(a, m):
	return (a % m + m) % m

def create_graph(n):
	graph = {}
	for _ in range(n):
		(x, y) = map(int, input().split())
		graph[x].append(y)
		graph[y].append(x)
	return graph

def check_prime(n):
	temp = int(math.sqrt(n) + 1)
	for i in range(2, temp):
		if n % i == 0:
			return False
	return True

def main():
	for _ in range(int(input())):
		(n, s) = input().split()
		s = int(s)
		if sum((int(i) for i in n)) <= int(s):
			print('0')
			continue
		tempSum = 0
		r = 0
		for i in range(len(n)):
			if tempSum + int(n[i]) >= s:
				break
			else:
				tempSum += int(n[i])
				r += 1
		if r == 0:
			actual_result = '1'
			actual_result += '0' * len(n)
		else:
			temp = int(n[0:r]) + 1
			actual_result = str(temp)
			actual_result += '0' * (len(n) - r)
		print(int(actual_result) - int(n))
sys.setrecursionlimit(10 ** 6)
threading.stack_size(10 ** 8)
t = threading.Thread(target=main)
t.start()
t.join()


tc = int(input())
for i in range(tc):
	(a, b) = map(int, input().split())
	val = a // b + 1
	if a % b == 0:
		print('0')
	else:
		print(b * val - a)


import math as m
for i in range(int(input())):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if a % b == 0:
		print(0)
	else:
		c = m.ceil(a / b)
		div = b * c
		nummoves = div - a
		print(nummoves)


from math import ceil
for test in range(int(input())):
	(n, k) = map(int, input().split())
	print(k * ceil(n / k) - n)


import math
n = int(input())
while n:
	n -= 1
	(a, b) = input().split()
	(a, b) = (int(a), int(b))
	x = math.ceil(a / b) * b - a
	print(x)


t = int(input())
answer = []
for i in range(t):
	(a, b) = list(map(int, input().split()))
	ans = b - a % b if a % b != 0 else 0
	answer.append(str(ans))
print('\n'.join(answer))


results = ''
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b:
		results += f'{-a % b}\n'
	else:
		results += '0\n'
print(results[:-1])


a = int(input())
for c in range(a):

	def func(x, y):
		z = x % y
		res = y - z
		print(res)
	(x, y) = [int(i) for i in input().split()]
	if x % y == 0:
		print(0)
	elif y > x:
		print(y - x)
	else:
		func(x, y)


def cal_sum_of_digits(n):
	sum = 0
	while n > 0:
		sum += n % 10
		n = n // 10
	return sum

def solve(n, s):
	if cal_sum_of_digits(n) <= s:
		return 0
	temp = n
	arr = []
	power = 10
	while temp * 10 // power > 0:
		arr.append((temp // power + 1) * power)
		power *= 10
	for element in arr:
		if cal_sum_of_digits(element) <= s:
			return element - n
for i in range(int(input())):
	(n, s) = [int(x) for x in input().split(' ')]
	print(solve(n, s))


t = int(input())
q = []
for i in range(t):
	l = list(input().split())
	a = int(l[0])
	b = int(l[1])
	if a % b == 0:
		q.append(0)
	else:
		q.append(b - a % b)
for i in q:
	print(i)


import math
t = int(input())
while t:
	t = t - 1
	(a, b) = [int(s) for s in input().split()]
	if a < b:
		print(b - a)
	else:
		d = math.ceil(a / b)
		ans = d * b - a
		print(ans)


def min_del(a, b):
	if a % b == 0:
		return 0
	return b * (a // b + 1) - a
n = int(input())
for i in range(n):
	(a, b) = [int(x) for x in input().split()]
	answ = min_del(a, b)
	print(answ)


def summer(s):
	re = 0
	s = str(s)
	for i in s:
		re += int(i)
	return re

def sol(n, s):
	if summer(n) <= s:
		print(0)
		return
	ans = 0
	pw = 1
	for i in range(18):
		digit = n // pw % 10
		add = pw * ((10 - digit) % 10)
		n += add
		ans += add
		if summer(n) <= s:
			break
		pw = pw * 10
	print(ans)
k = int(input())
for i in range(k):
	(n, s) = list(map(int, input().split(' ')))
	sol(n, s)


import math
n = int(input())
for _ in range(n):
	(a, b) = map(int, input().strip().split())
	x = math.ceil(a / b)
	print(x * b - a)


def sum_of_digits(number):
	total_sum = 0
	while number > 0:
		total_sum += number % 10
		number = number // 10
	return total_sum
t = int(input())
for i in range(t):
	(n, s) = map(int, input().split())
	total_sum = sum_of_digits(n)
	ans = 0
	if total_sum <= s:
		print(ans)
	else:
		pw = 1
		for i in range(18):
			last_digit = n // pw % 10
			add_digit = pw * ((10 - last_digit) % 10)
			pw *= 10
			n += add_digit
			ans += add_digit
			if sum_of_digits(n) <= s:
				print(ans)
				break


res = []
t = int(input())
for i in range(t):
	(a, b) = [int(x) for x in input().split()]
	curr = a % b
	if curr == 0:
		res.append(0)
	else:
		res.append(min(abs(curr - b), abs(b - curr)))
for item in res:
	print(item)


import sys
input = sys.stdin.readline

def f(n):
	res = 0
	for _ in range(20):
		res += n % 10
		n //= 10
	return res
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	if f(n) <= s:
		print(0)
		continue
	now = 0
	for i in range(len(str(n))):
		now += (10 - n % 10) * pow(10, i)
		n //= 10
		n += 1
		if f(n) <= s:
			print(now)
			break


def su(tmp):
	ans = 0
	for i in tmp:
		ans += int(i)
	return ans
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	tmp = list(str(n))
	a = su(tmp)
	if s >= a:
		print(0)
	else:
		aa = ans = 0
		c = 1
		tmp = ['0'] + tmp
		for i in range(len(tmp) - 1, 0, -1):
			if tmp[i] == '0':
				c *= 10
				continue
			aa += int(tmp[i])
			ans += (10 - int(tmp[i])) * c
			tmp[i] = '0'
			j = i - 1
			while j >= 0 and tmp[j] == '9':
				tmp[j] = '0'
				j -= 1
			tmp[j] = str(int(tmp[j]) + 1)
			c *= 10
			if su(tmp) <= s:
				break
		if su(tmp) > s:
			ans += (10 - int(tmp[i])) * c
		print(ans)


test = int(input())
for t in range(test):
	(a, b) = map(int, input().split())
	moves = 0
	if a % b != 0:
		moves = a % b
		moves = b - moves
	print(moves)


t = int(input())
for i in range(0, t):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if a % b == 0:
		print(0)
	else:
		r = a % b
		print(abs(b - r))


import math
from collections import defaultdict
ml = lambda : map(int, input().split())
ll = lambda : list(map(int, input().split()))
ii = lambda : int(input())
ip = lambda : input()
t = ii()
for _ in range(t):
	(x, y) = ml()
	if x % y != 0:
		print((x // y + 1) * y - x)
	else:
		print(0)


cases = int(input())
for case in range(cases):
	numbers = input().split()
	(number, factor) = (int(numbers[0]), int(numbers[1]))
	remainder = number % factor
	if remainder:
		print(factor - remainder)
	else:
		print(0)


from math import ceil
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print('0')
	else:
		c = ceil(a / b)
		d = c * b
		print(abs(a - d))


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	r = list(map(int, str(n)))[::-1]
	d = sum(r)
	if d <= s:
		print(0)
		continue
	for i in range(1, len(r)):
		x = r[:i + 1]
		if x[-1] == 9:
			continue
		if d - sum(x) + x[-1] + 1 <= s:
			nr = r.copy()
			nr[:i] = [0] * len(nr[:i])
			nr[i] = x[-1] + 1
			print(int(''.join((str(i) for i in nr))[::-1]) - n)
			break
	else:
		print(int('1' + '0' * len(r)) - n)


t = int(input())
while t > 0:
	(a, b) = [int(ele) for ele in input().split()]
	div = int(a / b)
	rem = a % b
	if rem == 0:
		print(0)
	else:
		print(b * (div + 1) - (b * div + rem))
	t -= 1


def minmove(n, s):
	n1 = n
	digits = list(map(int, str(n)))
	move = 0
	i = 1
	while sum(digits) > s:
		new = (n // 10 ** i + 1) * 10 ** i
		digits = list(map(int, str(new)))
		i += 1
		move = new - n
	return move
t = int(input())
for i in range(t):
	(n, s) = map(int, input().split())
	print(minmove(n, s))


import sys

def answer(a, b):
	rem = a % b
	return 0 if rem == 0 else b - rem
count = int(input())
for x in range(count):
	(a, b) = sys.stdin.readline().split()
	print(answer(int(a), int(b)))


import math
st = ''

def func(a, b):
	k = a % b
	if (a + k) % b == 0:
		return k
	return b - k
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	st += str(func(a, b)) + '\n'
print(st)


def solve():
	t = int(input())
	for i in range(t):
		(a, b) = [int(s) for s in input().split()]
		print((b - a % b) % b)
solve()


import sys
lines = sys.stdin.readlines()
T = int(lines[0])
for t in range(T):
	(a, b) = map(int, lines[t + 1].strip().split(' '))
	res = a % b
	if res > 0:
		res = b - res
	print(res)


from math import ceil
for _ in range(int(input())):
	(A, B) = list(map(int, input().split()))
	print(ceil(A / B) * B - A)


def is_divisible(a, b):
	if b == 0:
		return 0
	if a % b == 0:
		return 0
	factor = a // b
	next_divisible = (factor + 1) * b
	count = next_divisible - a
	return count
t = int(input())
for i in range(t):
	(a, b) = input().split(' ')
	a = int(a)
	b = int(b)
	print(is_divisible(a, b))


t = int(input())
for ii in range(t):
	z = []
	(n, k) = map(int, input().split())
	if n % k == 0:
		print(0)
	else:
		a = n // k + 1
		s = a * k
		print(s - n)


for __ in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		c = int(a / b) + 1
		d = c * b - a
		print(d)


for _ in range(int(input())):
	(m, n) = map(int, input().split())
	i = 2
	val = m // n
	count = val + 1
	if m % n == 0:
		print(0)
	else:
		print(n * count - m)


import math
import os
import random
import re
import sys
from collections import defaultdict, Counter, deque
import heapq
from functools import lru_cache
from itertools import accumulate, chain, combinations, permutations, groupby, zip_longest
from math import floor, ceil, sqrt
t = int(input())
res = []

def f(n, s):
	if sum((int(ch) for ch in str(n))) <= s:
		return 0
	l = len(str(n))
	for p in range(1, l + 1):
		v = n % 10 ** p
		add = 10 ** p - v
		new = n + add
		if sum((int(ch) for ch in str(new))) <= s:
			return add
for _ in range(t):
	(n, s) = map(int, input().split())
	res += (f(n, s),)
for v in res:
	print(v)


def sod(n):
	sum = 0
	while n:
		sum += n % 10
		n //= 10
	return sum
t = int(input())
for _ in range(t):
	(n, s) = map(int, input().split())
	sum = sod(n)
	if sum <= s:
		print(0)
		continue
	t = list(str(n))
	m = len(t)
	idx = -1
	cnt = 0
	for i in range(m):
		cnt += int(t[i])
		if cnt < s:
			idx = i
	while idx >= 0 and t[idx] == '9':
		idx -= 1
	if idx == -1:
		t = '0' * (m + 1)
		t = list(t)
		t[0] = '1'
	else:
		t[idx] = chr(ord(t[idx]) + 1)
		idx += 1
		for i in range(idx, m):
			t[i] = '0'
	x = str()
	for c in t:
		x = x + c
	print(int(x) - n)


import sys, bisect
from math import gcd
input = sys.stdin.readline

def inp():
	return int(input().rstrip())

def inlt():
	return list(map(int, input().rstrip().split()))

def insr():
	s = input().rstrip()
	return s[:len(s) - 1]

def invr():
	return map(int, input().rstrip().split())
t = inp()
for _ in range(t):
	(a, b) = invr()
	if b >= a:
		print(b - a)
	elif a % b == 0:
		print(0)
	else:
		need = a // b
		result = b * (need + 1)
		print(result - a)


t = int(input())
for i in range(0, t):
	ab = input().split(' ')
	ab = [int(i) for i in ab]
	a = ab[0]
	b = ab[1]
	i = 1
	g = b
	h = 0
	if a % b == 0:
		print(0)
	elif b <= 1000:
		while a % b != 0:
			a += 1
			h += 1
		print(h)
	else:
		while a > g:
			g = b * i
			i += 1
		print(g - a)


x = int(input())
y = 0
while y < int(x):
	(a, b) = [int(l) for l in input().split()]
	c = a % b
	if c == 0:
		print('0')
	else:
		print(b - c)
	y = y + 1


tc = int(input())
for i in range(tc):
	A = input().split()
	if int(A[0]) <= int(A[1]):
		print(int(A[1]) - int(A[0]))
	elif int(A[0]) % int(A[1]) == 0:
		print(0)
	else:
		print(int(A[1]) * (int(A[0]) // int(A[1]) + 1) - int(A[0]))


import io
import os
from collections import Counter, defaultdict, deque

def solve(A, B):
	m = A % B
	if m == 0:
		return 0
	return B - m
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	(A, B) = [int(x) for x in input().split()]
	ans = solve(A, B)
	print(ans)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n % k == 0:
		print(0)
	else:
		v = n // k
		v = v + 1
		print(k * v - n)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	z = a // b
	if a / b != a // b:
		z += 1
	print(z * b - a)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
from math import sqrt, floor, factorial, gcd, log, ceil
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
from math import gcd
from bisect import bisect

def solution():
	for i in range(int(input())):
		(a, b) = map(int, input().split())
		ans = 0
		if a % b != 0:
			ans = b - a % b
		print(ans)
solution()
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
read = lambda : list(map(int, input().strip().split(' ')))


from sys import stdin

def steps(a, b):
	if a < b:
		return b - a
	remainder = a % b
	if remainder == 0:
		return 0
	return b - remainder

def main():
	data = stdin.readline().strip()
	n = int(data)
	for i in range(n):
		(a, b) = map(int, stdin.readline().strip().split())
		print(steps(a, b))
main()


for ad in range(int(input())):
	(n, s) = list(map(int, input().split()))
	x = list(str(n))
	x = list(map(int, x))
	add = sum(x)
	if add <= s:
		print(0)
	else:
		ans = ''
		t = 0
		c = 0
		for i in range(len(x)):
			if c + x[i] < s and t == 0:
				c += x[i]
			elif t == 1:
				if i != len(x) - 1:
					ans += str(9 - x[i])
				elif x[i] == 0:
					ans += '0'
					ans = str(int(ans) + 10)
				else:
					ans += str(10 - x[i])
			else:
				t = 1
				if i != len(x) - 1:
					ans += str(9 - x[i])
				elif x[i] == 0:
					ans += '0'
					ans = str(int(ans) + 10)
				else:
					ans += str(10 - x[i])
		print(int(ans))


import math
import sys
from sys import stdin, stdout
sys.setrecursionlimit(100000)
MOD = 10 ** 9 + 7
int_input = lambda : int(stdin.readline())
list_input = lambda : list(map(int, stdin.readline().split()))
sum_of_digit = lambda n: sum(map(int, list(str(n))))

def factors(n):
	fact = [1, n]
	for i in range(2, int(sqrt(n)) + 1):
		if n % i == 0:
			fact.append(i)
			if n // i != i:
				fact.append(n // i)
	return fact

def sieve(n):
	primes = [True] * (n + 1)
	(primes[0], primes[1]) = (False, False)
	for i in range(2, int(math.sqrt(n)) + 1):
		if primes[i]:
			for j in range(i * i, n + 1, i):
				primes[j] = False
	return primes
for _ in range(int_input()):
	(a, b) = list_input()
	x = sum_of_digit(a)
	if x <= b:
		print(0)
		continue
	s = str(a)
	(ind, val) = (0, 0)
	ans = ''
	while ind < len(s) and val + int(s[ind]) < b:
		ans += s[ind]
		val += int(s[ind])
		ind += 1
	if ans:
		ans = str(int(ans) + 1)
	else:
		ans = '1'
	ans += '0' * (len(s) - ind)
	print(int(ans) - a)


def solution():
	(n, s) = map(int, input().split())
	x = n
	l = []
	while x > 0:
		l.append(x % 10)
		x //= 10
	l.reverse()
	l = [0] + l
	i = len(l) - 1
	while sum(l) > s:
		l[i] = 0
		i -= 1
		l[i] += 1
	p = len(l) - 1
	num = 0
	for i in range(len(l)):
		num += l[i] * 10 ** p
		p -= 1
	print(num - n)
t = int(input())
for _ in range(t):
	solution()


q = int(input())
while q:
	(n, s) = map(int, input().split())
	tmp = str(n)
	(res, ans) = ([], 0)
	for i in reversed(tmp):
		res.append(int(i))
	carry = 1
	idx = 0
	while sum(res) > s:
		if res[idx] == 0:
			carry *= 10
			idx += 1
			continue
		d = 10 - res[idx]
		ans += carry * d
		carry *= 10
		res[idx] = 0
		idx += 1
		if idx < len(res):
			res[idx] += 1
		else:
			res.append(1)
		t = idx
		while res[t] >= 10:
			(x, y) = (res[t] % 10, res[t] // 10)
			if t >= len(res) - 1:
				res.append(y)
			else:
				res[t + 1] += 1
			res[t] = x
			t += 1
	print(ans)
	q -= 1


t = int(input())
a = []
for i in range(t):
	(x, y) = map(int, input().split())
	if x != 0 and x % y == 0:
		x = y
	else:
		x = x % y
	a.append(y - x)
for i in range(t):
	print(a[i])


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	print([0, b - a % b][bool(a % b)])


from sys import stdin, stdout
from collections import Counter
from itertools import permutations
import bisect
import math
I = lambda : map(int, stdin.readline().split())
I1 = lambda : stdin.readline()

def fun(n):
	s = 0
	while n:
		s += n % 10
		n //= 10
	return s
for _ in range(int(I1())):
	(n, s) = I()
	c = 0
	r = 10
	while fun(n) > s:
		x = n % r
		c += r - x
		n += r - x
		r *= 10
	print(c)


cases = int(input())

def digits(n):
	l = []
	while n > 0:
		l.append(n % 10)
		n //= 10
	l.reverse()
	return l

def form(l):
	n = 0
	for i in l:
		n *= 10
		n += i
	return n
for case in range(cases):
	(n, s) = map(int, input().split())
	d = digits(n)
	if sum(d) <= s:
		print(0)
		continue
	num_acceptable = 0
	this_sum = 0
	for i in d:
		if this_sum + i < s:
			num_acceptable += 1
			this_sum += i
		else:
			break
	if num_acceptable == 0:
		d = [1] + [0] * len(d)
		print(form(d) - n)
	else:
		d = d[:num_acceptable] + [0] * (len(d) - num_acceptable)
		d[num_acceptable - 1] += 1
		print(form(d) - n)


n = int(input())
for i in range(n):
	(a, b) = list(map(int, input().split()))
	ans = (a // b + (not a % b == 0)) * b - a
	print(ans)


for T in range(int(input())):
	(a, b) = map(int, input().split())
	ans = 0
	if a <= b:
		print(b - a)
	elif a % b == 0:
		print(0)
	else:
		print(b - a % b)


t = int(input())
result = []
for _ in range(t):
	(a, b) = map(int, input().split())
	x = a % b
	if x == 0:
		result.append(0)
	else:
		result.append(b - x)
for x in result:
	print(x)


def func(x, y):
	res = 1
	while y:
		if y % 2:
			res *= x
		y //= 2
		x *= x
	return res
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	k = n
	(ans, S, j, V) = (0, 0, 0, [])
	while k:
		V.append(k % 10)
		S += k % 10
		k //= 10
	while S > s and j < len(V):
		if V[j] != 0:
			S -= V[j] - 1
			ans += (10 - V[j]) * func(10, j)
			if j < len(V) - 1:
				V[j + 1] += 1
		j += 1
	print(ans)


from math import *
t = int(input())
while t:
	t = t - 1
	(a, s) = input().split()
	n = len(a)
	s = int(s)
	flag = 0
	l = []
	ss = 0
	z = -1
	for i in a:
		ss += int(i)
		l.append(ss)
	if ss <= s:
		print(0)
		continue
	for i in range(n - 1, -1, -1):
		if a[i] != '9':
			if l[i] + 1 <= s:
				flag = 1
				z = i
				break
		else:
			temp = a[:i + 1]
			temp = int(temp) + 1
			temp = str(temp)
			sum = 0
			for j in temp:
				sum += int(j)
			if sum <= s:
				flag = 1
				z = i
				break
	out1 = ''
	out2 = ''
	if flag == 0:
		out = '1' + '0' * n
		print(int(out) - int(a))
		continue
	for i in range(n):
		if i <= z:
			out1 += a[i]
		else:
			out2 += '0'
	out1 = int(out1) + 1
	out1 = str(out1)
	out1 = out1 + out2
	print(int(out1) - int(a))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = I()
	rr = []
	for _ in range(t):
		(n, s) = LI()
		if sum((int(c) for c in str(n))) <= s:
			rr.append(0)
			continue
		t = [0] + [int(c) for c in str(n)]
		u = sum(t)
		l = len(t)
		for i in range(l - 1, -1, -1):
			if t[i] == 9:
				continue
			v = sum(t[:i])
			a = v + t[i] + 1
			b = v + (l - i) * 9
			if a > s:
				continue
			t[i] += 1
			for j in range(l - 1, i, -1):
				t[j] = 0
			break
		rr.append(int(JA(t, '')) - n)
	return JA(rr, '\n')
print(main())


for case in range(int(input())):
	(a, b) = [int(a) for a in input().split()]
	if a < b:
		ans = b - a
	elif a == b:
		ans = 0
	elif a % b == 0:
		ans = 0
	else:
		mod = a // b + 1
		ans = b * mod - a
	print(ans)


n = int(input())
for i in range(n):
	(n1, n2) = map(int, input().split())
	maxMultipliador = int(n1 // n2)
	calculado = n2 * maxMultipliador
	if calculado == n1:
		print(0)
	else:
		print(n2 * (maxMultipliador + 1) - n1)


t = int(input())

def nextMultiple(n, m):
	q = n // m
	n2 = 0
	if n * m > 0:
		n2 = m * (q + 1)
	else:
		n2 = m * (q - 1)
	return n2
for _ in range(t):
	(a, b) = list(map(int, input().split(' ')))
	if a % b == 0:
		print(0, '\n')
	else:
		print(int(nextMultiple(a, b)) - a, '\n')


t = int(input())
l = []
for i in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		l.append(0)
	elif a % b != 0:
		l.append(b - a % b)
for i in l:
	print(i)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	s = 0
	ans = 0
	a = str(a)
	n = len(a)
	all = 0
	for i in range(n):
		s += int(a[i])
		if a[i] == 0:
			j += 1
		if s >= b:
			ans = 10 ** (n - i) - int(a[i:])
			if i < n - 1:
				all = s + int(a[i + 1:])
			elif i == n - 1:
				all = s
			break
	if all == b:
		ans = 0
	print(ans)


from functools import reduce
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def arr():
	return [int(i) for i in input().split()]

def sarr():
	return [int(i) for i in input()]

def starr():
	return [str(x) for x in input().split()]

def inn():
	return int(input())

def svalue():
	return tuple(map(str, input().split()))

def parr():
	return [value() for i in range(n)]
mo = 1000000007
for _ in range(inn()):
	(val, s) = value()
	a = [int(x) for x in str(val)]
	if sum(a) <= s:
		print(0)
	else:
		ans = 0
		res = 10
		flag = 0
		while True:
			if val % res == 0:
				res *= 10
			else:
				rem = val % res
				new = val + (res - rem)
				if sum([int(x) for x in str(new)]) <= s:
					ans = new
					flag = 1
					break
				else:
					res *= 10
			if res > val:
				break
		if flag == 1:
			print(ans - val)
		else:
			print(res - val)


t = int(input())
list0 = [0] * t
for i in range(t):
	list0[i] = input()

def divisAdd(a, b):
	if a % b == 0:
		return 0
	else:
		return b - a % b
for i in range(t):
	print(str(divisAdd(int(list0[i].split(' ')[0]), int(list0[i].split(' ')[1]))))


total = int(input())
for i in range(total):
	(a, b) = [int(x) for x in input().split()]
	diff = 0
	if a % b != 0:
		min = a // b + 1
		diff = b * min - a
	print(diff)


import sys
import math
from collections import defaultdict, Counter
input = sys.stdin.readline

def print(x):
	sys.stdout.write(str(x) + '\n')
t = int(input())
for i in range(t):
	(n, s) = map(int, input().split())
	n1 = str(n)
	ans = 0
	ind = -2
	for j in range(len(n1)):
		ans += int(n1[j])
		if ans == s and ind == -2:
			ind = j
		elif ans > s:
			if ind == -2:
				ind = j
				break
	if ans <= s:
		print(0)
		continue
	if ind == -1:
		ans1 = pow(10, len(n1)) - n
	else:
		ans1 = pow(10, len(n1) - ind) - int(n1[ind:])
	print(ans1)


t = int(input())
out = ''
while t > 0:
	t -= 1
	(a, b) = [int(i) for i in input().split(' ')]
	x = a % b
	if x == 0:
		out += f'0\n'
	else:
		out += f'{b - x}\n'
print(out)


for _ in range(int(input())):
	(num, target) = map(int, input().split())
	res = 0
	power = 1
	while sum((int(x) for x in str(num))) > target:
		d = num // power % 10
		add = power * (10 - d)
		num += add
		res += add
		power *= 10
	print(res)


t = int(input())
for i in range(1, t + 1):
	(a, b) = map(int, input().split(' '))
	modulus = a % b
	if modulus == 0:
		print(0)
	else:
		value = b - modulus
		print(value)


import math

def solve(n, s):
	digits = []
	nn = n
	sums = []
	(sm, c) = (0, 0)
	while nn > 0:
		x = nn % 10
		digits.append(x)
		sums.append(sm)
		sm -= x
		c += x
		nn = nn // 10
	more = 0
	m = 1
	for (i, x) in enumerate(sums):
		if x + c + more <= s:
			break
		more = 1 if more or digits[i] > 0 else 0
		m *= 10
	if m == 1:
		return 0
	return m - n % m
t = int(input())
for _ in range(t):
	(n, s) = (int(x) for x in input().split())
	print(solve(n, s))


T = int(input())
for i in range(T):
	(N, D) = map(int, input().split())
	if N % D == 0:
		print('0')
	else:
		x = N // D
		print(int(D * (x + 1) - N))


import math
a = int(input())
i = 0
while i < a:
	b = input().split(' ')
	c = int(b[0])
	d = int(b[1])
	g = math.ceil(c / d)
	if c < d:
		print(d - c)
	if c > d:
		print(g * d - c)
	if c == d:
		print(0)
	i = i + 1


from sys import *
from sys import *
t = int(stdin.readline())
for _ in range(t):
	(n, s) = map(int, stdin.readline().split())
	a = []
	cnt = 0
	i = n
	while i > 0:
		a.append(i % 10)
		i = i // 10
		cnt += 1
	a = a[::-1]
	sum = a[0]
	cnt1 = 1
	f = 0
	f1 = 0
	cnt2 = 0
	for i in range(1, cnt):
		if sum == s and f1 == 0:
			f1 = 1
			j = i
		if sum > s:
			if f1 == 1:
				a[j - 1] = 10
				cnt1 -= cnt2
			else:
				a[i - 1] = 10
			f = 1
			break
		sum += a[i]
		cnt1 += 1
		if f1 == 1:
			cnt2 += 1
	if f1 == 1 and sum > s and (f == 0):
		a[j - 1] = 10
		cnt1 -= cnt2
	elif f == 0 and sum > s:
		a[i] += 10 - a[i]
	x = 10 ** (cnt - 1)
	a1 = 0
	for i in range(cnt1):
		a1 += a[i] * x
		x = x // 10
	print(a1 - n)


T = int(input())
for it in range(T):
	s = input().split()
	a = int(s[0])
	b = int(s[1])
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


import math
for h in range(int(input())):
	(a, b) = map(int, input().strip().split())
	print(b * math.ceil(a / b) - a)


import time, math as mt, bisect, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

def II():
	return int(stdin.readline())

def IO():
	return stdin.readline()

def IP():
	return map(int, stdin.readline().split())

def L():
	return list(map(int, stdin.readline().split()))

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

def lcm(a, b):
	return a * b // gcd(a, b)

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * 1000001
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(1000001):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count
mx = 10 ** 7
spf = [mx] * (mx + 1)

def SPF():
	spf[1] = 1
	for i in range(2, mx + 1):
		if spf[i] == mx:
			spf[i] = i
			for j in range(i * i, mx + 1, i):
				if i < spf[j]:
					spf[j] = i
	return

def readTree(v):
	adj = [set() for i in range(v + 1)]
	for i in range(v - 1):
		(u1, u2) = In()
		adj[u1].add(u2)
		adj[u2].add(u1)
	return adj
mod = 10 ** 9 + 7

def sum_dig(num):
	sm = 0
	while num > 0:
		sm += num % 10
		num = num // 10
	return sm

def solve():
	(n, s) = IP()
	if sum_dig(n) <= s:
		print(0)
		return
	else:
		for i in range(19):
			new_num = (n // 10 ** i + 1) * 10 ** i
			if sum_dig(new_num) <= s:
				print(new_num - n)
				break
t = II()
for i in range(t):
	solve()


t = int(input())
for i in range(t):
	(n, s) = map(int, input().split())
	c = 0
	i = 0
	j = 0
	ans = 0
	while sum(list(map(int, list(str(n))))) > s:
		c = (10 - n // 10 ** j % 10) % 10 * 10 ** j
		n += c
		ans += c
		j += 1
	print(ans)


t = int(input())
for _ in range(t):
	[a, b] = [*map(int, input().split())]
	if a <= b:
		print(b - a)
		continue
	if a % b == 0:
		print(0)
		continue
	times = a // b
	print((times + 1) * b - a)


t = int(input().strip(' '))
for _ in range(t):
	(a, b) = tuple(map(int, input().strip(' ').split(' ')))
	moves = 0
	if a % b > 0:
		moves = b - a % b
	print(moves)


t = int(input())

def dgt_sum(num):
	return sum([int(x) for x in str(num)])

def clps(val, left=0):
	if len(str(val)) == 1:
		return (1, left + 1)
	return (int(str(val)[:-1]) + 1, left + 1)

def solve(n, s):
	n_str = str(n)
	_s = 0
	target = n
	for (i, d) in enumerate(n_str):
		d = int(d)
		_s += d
		if _s > s:
			cl = (int(n_str[:i + 1]), 0)
			while dgt_sum(cl[0]) > s:
				cl = clps(*cl)
			target = cl[0] * pow(10, cl[1] + len(n_str) - i - 1)
			break
	return target - n
for _ in range(t):
	(n, s) = [int(x) for x in input().split(' ')]
	print(solve(n, s))


from math import *
from sys import *
t = int(stdin.readline())
for _ in range(t):
	(n, k) = map(int, stdin.readline().split())
	ans = k - n % k
	if ans == k:
		ans = 0
	print(ans)


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	(a, b) = map(int, stdin.readline().split())
	if a % b == 0:
		stdout.write('0\n')
	else:
		moves = b - a % b
		stdout.write('%d\n' % moves)