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: introductory

Starter code:

Solutions:
import sys


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


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


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

# d-decrease-the-sum-of-digits.yml

def dsum(x):
    res = 0
    while x:
        res += x % 10
        x //= 10
    return res

for _ in range(int(input())):
    n, s = list(map(int, input().split()))
    # print(f'init: n={n}, s={s}')

    p = 1
    ans = 0
    csum = dsum(n)
    # its=10
    while csum > s:
        # print(f'n={n}')
        add = 10 * p - n % (10 * p)
        if add == 10 * p: add = 0
        ans += add
        n += add
        csum = dsum(n)
        p *= 10
        # print(f'n={n},p={p},csum={csum},add={add}')

        # its-=1
        # assert its

    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 _ in range(int(input())):
    s,k=list(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
            # print(ans)
            break
    su=0    
    for i in range(len(s)):
        su+=int(s[i])
    if su<=k:
        print(0)
    else:
        print(ans)


# Fast IO (be careful about bytestring)

# import os,io
# input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

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


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

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

import sys

input = sys.stdin.readline


############ ---- Input Functions ---- ############
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 (list(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
    # Try next power of 10
    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))


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)

z = int(input())

def sm(x):
    ans = 0
    while x>0:
        ans += x%10
        x //= 10
    return ans

for _ in range(z):
    n, s = list(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)


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)


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 = list(map(int, input().strip().split()))
    if f(n) <= s:
        print(0)
        continue
    b = 1
    ans = int(1e20)
    while b <= n*10:
        rn = n//b*b+b
        # print(rn, f(rn))
        if f(rn) <= s: ans = min(ans, rn-n)
        b *= 10
    print(ans)


import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
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
# from itertools import permutations,combinations
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
# from fractions import Fraction
# sys.setrecursionlimit(100000)
mod = int(1e9) + 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)

'''
Author: AsilenceBTF
Blog: asilencebtf.top
Date: 2020-05-28 13:02:12
LastEditTime: 2020-09-04 23:11:19
'''

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)
    



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

        # So we start counting digits from left to right
        # The first digits where the sum is greater than or equal to S and every digit following
        # needs to be set to 0, and the last digit we safely counted gets incremented
        # Our answer is the difference between this number and N

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

for t in range(int(input())):
    # n,s = map(int,input().split())
    n,s = input().split()
    s = int(s)

    nn =['0','0','0'] + list(n)

    su = 0
    for i in n:
        su += int(i)

    ptr = 1
    # cost = 0
    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
        # if int(nn[-ptr-1])>=10:
            
            
            
            
        ptr+=1

    print(int(''.join(nn))-int(n))

    # nn = n
    # ctr = 0
    # cost = []
    # su = 0
    # while nn:
    #     su += nn%10
    #     cost.append((10-nn%10)*10**ctr)
    #     nn//=10
    #     ctr+=1

    # ptr = 1
    # while su>s:
    #     su-=n%10**ptr
    #     su+=1
    #     n


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


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)

	


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:
            # print(n)
            closest = pow*((n+pow-1)//pow)
            # print(closest)
            moves += (closest-n)
            n = closest
            if checksum(n)<=s:
                break
            pow*=10
        print(moves)

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) 

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)


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

#!/usr/bin/env pypy3

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

# print(ans(2,2))
# print(ans_slow(2,2))

# return

# for s in range(1, 162):
# 	for n in range(1, 10000):
# 		if ans(n,s) != ans_slow(n, s):
# 			print(n, s)

# return

T = int(input())
for t in range(T):
	n,s = input().split()
	n = int(n)
	s = int(s)

	print(ans(n, s))