Problem: 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 ≤ t ≤ 2 ⋅ 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 ≤ n ≤ 10^{18}; 1 ≤ s ≤ 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

Solution (in JAVA):

Solution:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;

public class D {
    static Utility.FastReader fr = new Utility.FastReader();
    static PrintWriter out = new PrintWriter(System.out);

    static int cntDigits(String num){
        int cnt=0;
        for(int i=0; i<num.length(); ++i){
            cnt+=num.charAt(i)-'0';
        }
        return cnt;
    }

    public static void main(String[] args) {
        long timeStart = System.nanoTime();
        int t = fr.nextInt();
        while (t-- > 0) {
            long n=fr.nextLong();
            int s=fr.nextInt();
            String num=String.valueOf(n);
            int curr=0;
            int changePos=Integer.MIN_VALUE;
            for(int i=0; i<num.length(); ++i){
                int x=num.charAt(i)-'0';
                if(curr+x>s){
                    changePos=i-1;
                    break;
                }
                curr+=x;
            }
            long target=0;
            boolean done=false;
            debug(changePos);
            if(changePos==Integer.MIN_VALUE){
                target=n;
                done=true;
            }
            else{
                for(int i=changePos; i>=0; --i){
                    StringBuilder sb=new StringBuilder("");
                    for(int j=0; j<i; ++j){
                        sb.append(num.charAt(j));
                    }
                    char c=num.charAt(i);
                    if(c=='9') continue;
                    c+=1;
                    sb.append(c);
                    for(int j=i+1; j<num.length(); ++j){
                        sb.append("0");
                    }
                    int cnt=cntDigits(sb.toString());
                    if(cnt<=s){
                        target=Long.parseLong(sb.toString());
                        done=true;
                        break;
                    }
                }
            }
            if(!done){
                target=(long)Math.pow(10L, num.length());
            }
            System.out.println(target-n);
        }
        long timeEnd = System.nanoTime();
        System.err.println("Completed in :" + ((double) (timeEnd - timeStart) / 1000000) + " miliseconds");
        out.close();
    }

    static Supplier<List<String>> readListString = () -> Arrays.stream(fr.nextLine().split(" "))
            .collect(Collectors.toList());

    static Supplier<List<Integer>> readListInteger = () -> readListString.get().stream().map(x -> Integer.parseInt(x))
            .collect(Collectors.toList());

    static Supplier<List<Double>> readListDouble = () -> readListString.get().stream().map(x -> Double.parseDouble(x))
            .collect(Collectors.toList());

    static void debug(Object... o) {
        System.err.println(Arrays.deepToString(o));
    }

    static class Utility {

        static int getMaxInt(Integer... o) {
            int res = Integer.MIN_VALUE;
            for (int x : o) res = Math.max(x, res);
            return res;
        }

        static int getMinInt(Integer... o) {
            int res = Integer.MAX_VALUE;
            for (int x : o) res = Math.min(x, res);
            return res;
        }

        static long getMaxLong(Long... o) {
            long res = Long.MIN_VALUE;
            for (long x : o) res = Math.max(x, res);
            return res;
        }

        static long getMinLong(Long... o) {
            long res = Long.MAX_VALUE;
            for (long x : o) res = Math.min(x, res);
            return res;
        }


        static void sort(int[] a) {
            ArrayList<Integer> list = new ArrayList<>();
            for (int i : a) list.add(i);
            Collections.sort(list);
            for (int i = 0; i < a.length; i++) a[i] = list.get(i);
        }

        static void shuffleArray(long[] arr) {
            int n = arr.length;
            Random rnd = new Random();
            for (int i = 0; i < n; ++i) {
                long tmp = arr[i];
                int randomPos = i + rnd.nextInt(n - i);
                arr[i] = arr[randomPos];
                arr[randomPos] = tmp;
            }
        }

        static void shuffleArray(int[] arr) {
            int n = arr.length;
            Random rnd = new Random();
            for (int i = 0; i < n; ++i) {
                int tmp = arr[i];
                int randomPos = i + rnd.nextInt(n - i);
                arr[i] = arr[randomPos];
                arr[randomPos] = tmp;
            }
        }

        static int gcd(int a, int b) {
            if (b == 0)
                return a;
            return gcd(b, a % b);
        }

        static long gcd(long a, long b) {
            if (b == 0)
                return a;
            return gcd(b, a % b);
        }

        static class FastReader {
            BufferedReader br;
            StringTokenizer st;

            public FastReader() {
                br = new BufferedReader(new
                        InputStreamReader(System.in));
            }

            String next() {
                while (st == null || !st.hasMoreElements()) {
                    try {
                        st = new StringTokenizer(br.readLine());
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                return st.nextToken();
            }

            int nextInt() {
                return Integer.parseInt(next());
            }

            long nextLong() {
                return Long.parseLong(next());
            }

            double nextDouble() {
                return Double.parseDouble(next());
            }

            String nextLine() {
                String str = "";
                try {
                    str = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                return str;
            }
        }
    }
}