You are given two positive integers $a$ and $b$. In one move you can increase $a$ by $1$ (replace $a$ with $a+1$). Your task is to find the minimum number of moves you need to do in order to make $a$ divisible by $b$. It is possible, that you have to make $0$ moves, as $a$ is already divisible by $b$. You have to answer $t$ independent test cases.


-----Input-----

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

The only line of the test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).


-----Output-----

For each test case print the answer — the minimum number of moves you need to do in order to make $a$ divisible by $b$.


-----Example-----
Input
5
10 4
13 9
100 13
123 456
92 46

Output
2
5
4
333
0

Difficulty: EASY

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


n = int(input())

def baze(n, d):
	p1 = n - n % d
	p2 = p1 + d
	lst = []
	lst.append(abs(n - p2))
	return lst[0]
sum = []
for i in range(n):
	(n, d) = map(int, input().split())
	if n % d != 0:
		sum.append(baze(n, d))
	else:
		sum.append(0)
for ozv in sum:
	print(ozv)


n = int(input())
lst = []
while n > 0:
	lst.append(tuple(map(int, input().split(' '))))
	n -= 1
lk = []
for (a, b) in lst:
	k = 0
	if a % b == 0:
		lk.append(0)
	elif a <= b:
		lk.append(b - a)
	else:
		lk.append(abs(b - a % b))
for x in lk:
	print(x)


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


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


n = int(input())
alist = []
blist = []
for i in range(0, n):
	listt = input().split()
	alist.append(int(listt[0]))
	blist.append(int(listt[1]))
reslist = []
for i in range(0, n):
	a = alist[i]
	b = blist[i]
	if not a % b == 0:
		ans = b - a % b
	else:
		ans = a % b
	reslist.append(ans)
for i in reslist:
	print(i, end='\n')


import math
t = int(input())
while t > 0:
	t -= 1
	(a, b) = list(map(int, input().split()))
	if a == b:
		print(0)
	elif a < b:
		print(b - a)
	else:
		print(math.ceil(a / b) * b - a)


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


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)


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)


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


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


n = int(input(''))
answers = []
s = 0
while n > 0:
	(a, b) = input('').split()
	a = int(a)
	b = int(b)
	if a % b == 0:
		s = 0
	else:
		s = (a // b + 1) * b - a
	answers.append(s)
	n = n - 1
for too in answers:
	print(too)


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


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


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


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


import sys, time
import math
start_time = time.time()

def solved():
	n = in_int()
	for _ in range(n):
		(a, b) = in_int_map()
		if a % b:
			print(b - a % b)
		else:
			print(0)
ONLINE_JUDGE = True

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	for tt in range(1, t + 1):
		solved()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

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

def in_float():
	return float(input().strip())

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

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

def in_float_list():
	return list(map(float, input().split()))

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

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

def in_str_list():
	return input().split()
if ONLINE_JUDGE:
	import io, os
	input = sys.stdin.readline
main()


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


number = int(input())
a = []
b = []
for i in range(number):
	case = str(input())
	y = case.split()
	a.append(int(y[0]))
	b.append(int(y[1]))
for i in range(number):
	if a[i] > b[i]:
		x = a[i] % b[i]
		if x == 0:
			print(0)
		else:
			print(b[i] - x)
	elif a[i] < b[i]:
		print(b[i] - a[i])
	elif a[i] == b[i]:
		print(0)


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


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


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


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


t = int(input())
v = []
for i in range(t):
	s = input().split(' ')
	(a, b) = (int(s[0]), int(s[1]))
	k = -a % b
	v += [k]
for i in v:
	print(i)


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


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

	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())
	print('0' if a % b == 0 else b - a % b)


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


list1 = []
t = int(input())
for i in range(0, t):
	y = list(map(int, input().split()[:2]))
	list1.append(y)
for i in range(0, t):
	if list1[i][0] % list1[i][1] != 0:
		r = list1[i][0] % list1[i][1]
		b = list1[i][1] - r
		print(b)
	else:
		print('0')


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


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 list(map(int, data().split()))

def ssp():
	return list(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)


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


n = int(input())
s = []
for i in range(n):
	s.append(input().split())
result = []
for i in range(n):
	if int(s[i][0]) % int(s[i][1]) != 0:
		result.append(int(s[i][1]) - int(s[i][0]) % int(s[i][1]))
	else:
		result.append(0)
for i in result:
	print(i)


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


import sys
put = sys.stdin.readline
t = int(put())
while t:
	t -= 1
	(a, b) = map(int, put().split())
	r = a // b + 1 if a % b else a // b
	print(b * r - a)


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

def __starting_point():
	solve()
__starting_point()


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


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


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)


t = int(input())

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


import math
a = int(input())
for i in range(a):
	(x, y) = input().split()
	if int(x) % int(y) != 0:
		z = int(y) - (int(x) / int(y) - int(x) // int(y)) * int(y)
		print(round(z))
	else:
		print(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))


t = int(input())
while t:
	t = t - 1
	(a, b) = map(int, input().split(' '))
	if a > b and a % b != 0:
		cc = a // b
		print((cc + 1) * b - a)
	elif a % b == 0:
		print('0')
	else:
		print(b - a)


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)


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 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)


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()


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


def divisibility_problem(a: int, b: int) -> int:
	mod = a % b
	if mod == 0:
		return 0
	return b - a % b
t = int(input())
cases = []
for i in range(t):
	(a, b) = list(map(lambda i: int(i), input().split()))
	cases.append((a, b))
for i in range(t):
	(a, b) = cases[i]
	result = divisibility_problem(a, b)
	print(result)


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


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


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


def closestNumber(n, m):
	q = int(n / m)
	if n * m > 0:
		n2 = m * (q + 1)
	else:
		n2 = m * (q - 1)
	return n2
for i in range(int(input())):
	(a, b) = map(int, input().split())
	x = closestNumber(a, b)
	if a % b != 0:
		print(x - a)
	else:
		print(0)


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


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


L1 = []
L2 = []
t = eval(input())
for i in range(0, t):
	(a, b) = input().split(' ')
	L1.append(int(a))
	L2.append(int(b))
for i in range(len(L1)):
	if L1[i] >= L2[i]:
		if L1[i] % L2[i] != 0:
			c = int(L1[i] / L2[i] + 1) * L2[i]
			print(c - L1[i])
		else:
			print(0)
	else:
		print(L2[i] - L1[i])


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


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)


def main():
	n = int(input())
	anss = []
	for c in range(n):
		(a, b) = map(int, input().split())
		anss.append((b - a % b) % b)
	print('\n'.join([str(i) for i in anss]))
main()


import sys
input = sys.stdin.readline
output = sys.stdout.write

def main():
	test_cases = int(input().rstrip())
	for i in range(test_cases):
		(num, divisor) = map(int, input().rstrip().split())
		remainder = num % divisor
		if remainder == 0:
			output('0')
		else:
			ans = str(divisor - remainder)
			output(ans)
		output('\n')
main()


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)


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()


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)


t = int(input())
l = []
for i in range(t):
	l1 = list(map(int, input().split()))
	l.append(l1)
for j in l:
	r = j[0] % j[1]
	if r != 0:
		print(j[1] - r)
	else:
		print(r)


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


j = []
t = int(input())
for c in range(t):
	(a, b) = map(int, input().split())
	index = 0
	if 1 <= a <= 10 ** 9 and 1 <= b <= 10 ** 9 and (1 <= t <= 10 ** 4):
		j.append((b - a % b) % b)
	else:
		pass
for c in j:
	print(c)


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


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):
	(u, v) = map(int, input().split())
	if u % v == 0:
		print('0')
	else:
		d = v - u % v
		print(d)


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)


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()


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


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]))


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()


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


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


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


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)

def __starting_point():
	main()
__starting_point()


n = int(input(''))
number_holder = list()
for i in range(n):
	temp = list(map(int, input('').split(' ')))
	number_holder.append(temp)
for j in range(len(number_holder)):
	if number_holder[j][0] % number_holder[j][1] == 0:
		print(0)
	else:
		print(number_holder[j][1] - number_holder[j][0] % number_holder[j][1])


n = int(input())
lst = [input().split() for i in range(n)]
r = []
for (a, b) in lst:
	(a, b) = (int(a), int(b))
	if a % b != 0:
		r.append(str(b - a % b))
	else:
		r.append('0')
print('\n'.join(r))


casos = int(input())
lista = [0] * casos
for prueba in range(casos):
	(a, b) = [int(x) for x in input().split()]
	if a % b == 0:
		lista[prueba] = a % b
	elif a < b:
		lista[prueba] = b - a
	else:
		lista[prueba] = (a // b + 1) * b - a
print('\n'.join(map(str, lista)))


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


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))


n = int(input())
test_cases = []
for _ in range(n):
	test_cases.append([int(x) for x in input().split()])
for test_case in test_cases:
	x = test_case[0]
	y = test_case[1]
	print(y - x % y if x % y != 0 else 0)


n = int(input())
li = []
ki = []
for i in range(n):
	li.append([int(x) for x in input().split(' ')])
	pass
for i in range(n):
	m = -(-li[i][0] // li[i][1])
	ki.append(m * li[i][1] - li[i][0])
	pass
for i in ki:
	print(i)


for _ in range(int(input())):
	(x, y) = list(map(int, input().split()))
	if x < y:
		print(y - x)
	elif x % y == 0:
		print('0')
	else:
		print(y - x % y)


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


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


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


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]))


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


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


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


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


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


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


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 asd():
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)
x = int(input())
for i in range(x):
	asd()


t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	print((m - n % m) % m)


import sys

def input():
	return sys.stdin.readline()[:-1]
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(0)
	else:
		print(b - a % b)


import sys

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

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

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


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


n = int(input())
i = 0
lis = []
while i < n:
	lis2 = list(map(int, input().split()))
	lis.append(lis2)
	i = i + 1
for e in range(len(lis)):
	a = int(lis[e][0])
	b = int(lis[e][1])
	if a % b == 0:
		print('0')
	else:
		m = int(a / b)
		n = m + 1
		k = n * b
		final = abs(k - a)
		print(final)


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)


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)))


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


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


n = int(input())
ans = []
for i in range(n):
	l = input().split()
	a = int(l[0])
	b = int(l[1])
	x = a % b
	ans.append((b - x) % b)
for i in ans:
	print(i)


n = int(input())
mylist = []
for i in range(n):
	s = input().split()
	if int(s[0]) % int(s[1]) == 0:
		mylist.append(0)
	else:
		mylist.append(int(s[1]) - int(s[0]) % int(s[1]))
for i in range(len(mylist)):
	print(mylist[i])


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()


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)


def get_result(pairs_of_numbers):
	result = []
	for i in pairs_of_numbers:
		(a, b) = (i[0], i[1])
		num = b - a % b
		res = 0 if num == b else num
		result.append(res)
	return result

def main():
	length = int(input())
	pairs_of_numbers = [[int(x) for x in input().split()] for __ in range(length)]
	print(*get_result(pairs_of_numbers), sep='\n')
main()


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))


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_int = lambda : int(sys.stdin.readline())
for _ in range(get_int()):
	(n, d) = get_int_list()
	t = d - n % d
	if n % d == 0:
		print(0)
	else:
		print(t)


import sys
tehteid = int(sys.stdin.readline())
vastused = []
for i in range(tehteid):
	liikmed = list(map(int, sys.stdin.readline().split()))
	vastus = 0
	jagatav = liikmed[0]
	jagaja = liikmed[1]
	n = int(jagatav // jagaja)
	while n * jagaja < jagatav:
		n += 1
	vastused.append(n * jagaja - jagatav)
sys.stdout.write('\n'.join(map(str, vastused)))


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


def main():
	for x in range(int(input())):
		temp = list(map(int, input().split()))
		if temp[0] % temp[1] != 0:
			print(temp[1] - temp[0] % temp[1])
		else:
			print(0)
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)


n = int(input())
s = []
for i in range(n):
	(x, y) = map(int, input().split())
	if x % y == 0:
		s.append(0)
	else:
		z = y - x % y
		s.append(z)
for a in s:
	print(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)


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


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)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

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 MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, 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 main():
	(a, b) = MI()
	x = int(a / b)
	if a % b != 0:
		x += 1
		return x * b - a
	else:
		return x * b - a
n = I()
while n > 0:
	print(main())
	n -= 1


def div():
	t = int(input())
	counts = []
	for _ in range(t):
		ab = [int(x) for x in input().split()]
		(a, b) = (ab[0], ab[1])
		if a % b != 0:
			count = b - a % b
		else:
			count = 0
		counts.append(count)
	for i in range(t):
		print(counts[i])
div()


n = int(input())
while n > 0:
	(x, y) = map(int, input().split())
	if x % y == 0:
		print('0')
	else:
		t = x % y
		z = y - t
		print(z)
	n = n - 1


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)


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)
	return

def __starting_point():
	main()
__starting_point()


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


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


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)


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()


v = []
n = int(input())
for i in range(n):
	arr = input()
	lst = arr.split()
	rem = int(lst[1]) - int(lst[0]) % int(lst[1])
	if rem == int(lst[1]):
		v.append(0)
	else:
		v.append(rem)
for i in v:
	print(i)


t = int(input())
for idx in range(t):
	ab = input()
	abs = list(map(int, ab.split(' ')))
	if abs[1] >= abs[0]:
		print(abs[1] - abs[0])
	elif abs[0] % abs[1] == 0:
		print(0)
	else:
		print(abs[1] - abs[0] % abs[1])


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


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)


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


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


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)


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


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


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


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


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 list(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)


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


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 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)


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))


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


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


import sys, os.path, math
pwd = os.path.dirname(__file__)
if os.path.exists(os.path.join(pwd, '../iostream/input.txt')):
	sys.stdin = open(os.path.join(pwd, '../iostream/input.txt'), 'r')
	sys.stdout = open(os.path.join(pwd, '../iostream/output.txt'), 'w')

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


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 i in range(T):
	(A, B) = map(int, input().split())
	if A % B == 0:
		print(0)
	else:
		print(B - A % B)


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()


cases = int(input())
while cases > 0:
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if a % b == 0:
		print(0)
	else:
		print(abs(a % b - b))
	cases -= 1


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


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


n = int(input())
tup_list = [input().split() for i in range(0, n)]
min_step = 0
for i in range(0, n):
	a = int(tup_list[i][0])
	b = int(tup_list[i][1])
	if a < b:
		min_step = b - a
	elif a % b == 0:
		min_step = 0
	else:
		min_step = b - a % b
	print(min_step)


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


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


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)


def main():
	n = int(input())
	while n > 0:
		(a, b) = [int(x) for x in input().split()]
		c = (b - a % b) % b
		print(c)
		n = n - 1
main()


n = int(input())
z = []
for i in range(n):
	(a, b) = map(int, input().split())
	if a < b:
		z.append(b - a)
	elif a % b == 0:
		z.append(0)
	else:
		d = a % b
		e = b - d
		z.append(e)
for i in z:
	print(i)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	print(-a % b)


def solve():
	(a, b) = [int(x) for x in input().split()]
	ans = a % b
	if ans > 0:
		print(b - ans)
	else:
		print(0)
n = int(input())
while n > 0:
	solve()
	n -= 1


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())
print(*[b - a % b if a % b else 0 for (a, b) in [map(int, input().split()) for _ in range(t)]], sep='\n')


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


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


def func(n):
	for _ in range(n):
		(n, m) = map(int, input().split())
		if n % m == 0:
			k.append(str(0))
		elif n % m != 0:
			if n > m:
				m *= n // m + 1
				k.append(str(m - n))
			else:
				k.append(str(m - n))
	print('\n'.join(k))
k = []
func(int(input()))