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.*;
import java.lang.reflect.Array;
import java.util.*;

public class D {
    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;
        }
    }

    static FastReader s = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);

    private static int[] rai(int n) {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextInt();
        }
        return arr;
    }

    private static int[][] rai(int n, int m) {
        int[][] arr = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = s.nextInt();
            }
        }
        return arr;
    }

    private static long[] ral(int n) {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextLong();
        }
        return arr;
    }

    private static long[][] ral(int n, int m) {
        long[][] arr = new long[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = s.nextLong();
            }
        }
        return arr;
    }

    private static int ri() {
        return s.nextInt();
    }

    private static long rl() {
        return s.nextLong();
    }

    private static String rs() {
        return s.next();
    }

    static int MOD=1000000007;
    static int dfs(List<Integer>[] arr,int node,boolean[] vis,List<Long> count,int n)
    {
        vis[node]=true;
//        List<Integer> list=new ArrayList<>();
//        list.add(node);

        int c=1;
        for(int i:arr[node])
        {
            if(!vis[i])
            {
                c+=dfs(arr,i,vis,count,n);
            }
        }

        long val=((long)c)*(n-c);
//        val%=MOD;
        if(node!=0) {
            count.add(val);
        }
        return c;

    }

    static boolean dfs(int[] arr,int prev,int turn)
    {
        int flag=0;
        System.out.println("turn= "+turn);
        for(int i:arr)
        {
            System.out.print(i+" ");
            if(i!=0)
            {
                flag=1;
            }
        }
        System.out.println();
        if(flag==0)
        {
            return turn==1;
        }

        boolean check=false;
        for(int i=0;i<arr.length;i++)
        {
            if(prev!=i && arr[i]>0) {
                arr[i] -= 1;
                check|=dfs(arr, i, 1 - turn);
//                if(check)
//                {
//                    return true;
//                }
                arr[i] += 1;
            }
        }
        if(turn ==1)
        {
            return !check;
        }
        else
        {
            return check;
        }




    }
    public static void main(String[] args) {
        StringBuilder ans = new StringBuilder();
        int t = ri();
//        int t=1;
        while (t-- > 0) {
            String first=rs();
            char[] arr=first.toCharArray();
            int total=ri();
            int n=arr.length;
            int sum=0;
            int ind=n-1;
            int f=1;
            int currInd=-1;
            for(int i=0;i<n;i++)
            {
                sum+=arr[i]-'0';
                if(sum==total)
                {
                    currInd=i;
                    break;
                }
//                if(sum<=total && i==n-1)
//                {
//                    f=1;
//                    break;
//                }
                if(sum>total)
                {
                    f=0;
                    sum-=arr[i]-'0';
                    if(sum==total)
                    {
                        ind=i-2;
                    }
                    else {
                        ind = i - 1;
                    }
                    break;
                }
            }

            if(currInd!=-1) {
                for (int i=currInd+1;i<n;i++)
                {
                    if(arr[i]!='0')
                    {
                        f=0;
                        ind=currInd-1;
                        break;
                    }
                }
            }

//            System.out.println(ind);
            StringBuilder str=new StringBuilder();
            if(ind==-1)
            {
                str.append("1");
            }
            else {
                List<Integer> list=new ArrayList<>();
                for (int i = 0; i <=ind; i++) {
                    list.add(arr[i]-'0');
//                    str.append(arr[i]);
                }
                if(f==0) {
                    int flag = 0;
                    int i = list.size() - 1;
                    while (i >= 0) {
                        if (list.get(i) == 9) {
                            list.set(i, 0);
                        } else {
                            flag = 1;
                            list.set(i, list.get(i) + 1);
                            break;
                        }
                        i--;
                    }
                    if (flag == 0) {
                        list.add(0, 1);
                    }
                }

                for(int j:list)
                {
                    str.append(j);
                }



            }
            for(int i=ind+1;i<n;i++)
            {
                str.append("0");
            }

//            System.out.println(str.toString());

            ans.append(Long.parseLong(str.toString())-Long.parseLong(first)).append("\n");

        }
        out.print(ans.toString());
        out.flush();

    }
}