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.util.*;
import static java.lang.Math.*;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Codeforces {
    public static void main(String[] args) throws IOException {
        // InputStream inputStream = new FileInputStream("input.txt");
        // OutputStream outputStream = new FileOutputStream("output.txt");
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(in.nextInt(), in, out);
        out.close();
    }
    static class TaskA {
        long mod = (long)(1000000007);
        long fact[];
        int depth[];
        int parentTable[][];
        int degree[];
        ArrayList<Integer> leaves;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;

        public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
            while(testNumber-->0){
                long n = in.nextLong();
                int s = in.nextInt();

                long ans = 0;
                while(true){
                    long x = n;
                    String a = Long.toString(x);
                    int sum = 0;
                    int i;
                    for(i=a.length()-1;i>=0;i--){
                        sum += a.charAt(i) - '0';
                        if(sum > s){
                            break;
                        }
                    }

                    if(i == -1)
                        break;

                    long y = x;
                    int count = 0;
                    while(true){
                        long q = y%10;
                        y/=10;
                        if(q == 0){
                            count++;
                            continue;
                        }
                        long add = (10 - q)*pow(10 , count);
                        ans += add;
                        n += add;
                        break;
                    }

                }
                out.println(ans);

            }
        }

        public long ans(long a , long x , long b , long y , long n){
            long pA = a - x;
            if(n >= pA){
                // a = x;
                n -= pA;
                if(b-y <= n){
                    // System.out.println(x + " " + y);
                    return x*y;
                }
                else
                    return x*(b-n);
            }

            return (a - n)*b;

        }

        public int[][] rotateLeft(int a[][]){
            int n = a.length;
            int m = a[0].length;
            int ans[][] = new int[n][m];
            // for(int j=0;j<m;j++){
            //     for(int i=0;i<n;i++){
            //         ans[n-j-1][i] = a[i][j];
            //     }
            // }

            for(int i=0;i<n;i++)
                for(int j=i;j<n;j++){
                    int x = a[i][j];
                    int y = a[j][i];
                    ans[i][j] = y;
                    ans[j][i] = x;
                }

            for(int j=0;j<n/2;j++){
                for(int i=0;i<n;i++){
                    int x = ans[i][j];
                    ans[i][j] = ans[i][n-j-1];
                    ans[i][n-j-1] = x;
                }
            }

            // System.out.println("\nrotateLeft");
            // for(int i=0;i<n;i++){
            //     for(int j=0;j<n;j++)
            //         System.out.print(ans[i][j]);
            //     System.out.println();
            // }

            return ans;
        }

        public void rotateMatrix(int N, int mat[][]) 
        { 
            // Consider all squares one by one 
            for (int x = 0; x < N / 2; x++) { 
                // Consider elements in group 
                // of 4 in current square 
                for (int y = x; y < N - x - 1; y++) { 
                    // Store current cell in 
                    // temp variable 
                    int temp = mat[x][y]; 
      
                    // Move values from right to top 
                    mat[x][y] = mat[y][N - 1 - x]; 
      
                    // Move values from bottom to right 
                    mat[y][N - 1 - x] 
                        = mat[N - 1 - x][N - 1 - y]; 
      
                    // Move values from left to bottom 
                    mat[N - 1 - x][N - 1 - y] = mat[N - 1 - y][x]; 
      
                    // Assign temp to left 
                    mat[N - 1 - y][x] = temp; 
                } 
            } 
        } 

        public int maxSquare(int a[][]){
            int n = a.length;
            int b[][] = new int[n][n];
            // for(int i=0;i<n;i++)
            //     for(int j=0;j<n;j++)
            //         b[i][j] = a[i][j];
            for(int j=0;j<n;j++){
                int count = 0;
                for(int i=0;i<n;i++)
                    count+=a[i][j];
                int i = n-1;
                while(count-->0){
                    b[i--][j] = 1;
                }
            }

            for(int i=0;i<n;i++)
                for(int j=0;j<n;j++)
                    b[i][j] ^= 1;

            // System.out.println("\nMax Compact");
            // for(int i=0;i<n;i++){
            //     for(int j=0;j<n;j++)
            //         System.out.print(b[i][j]);
            //     System.out.println();
            // }

            return printMaxSubSquare(b);
        }

        public int printMaxSubSquare(int a[][]) { 
            int s[][] = new int[a.length][a[0].length];
              
            int maxSize, maxI, maxJ;  
          
            for(int i = 0; i < a.length; i++) 
                s[i][0] = a[i][0];
          
            for(int j = 0; j < a[0].length; j++) 
                s[0][j] = a[0][j];
              
            for(int i = 1; i < a.length; i++) 
            { 
                for(int j = 1; j < a[i].length; j++) 
                { 
                    if(a[i][j] == 1)  
                        s[i][j] = min(s[i][j-1], 
                                    Math.min(s[i-1][j], s[i-1][j-1])) + 1; 
                    else
                        s[i][j] = 0; 
                }  
            }      
            
            maxSize = s[0][0]; 
            for(int i = 0; i < a.length; i++) 
            { 
                for(int j = 0; j < a[i].length; j++) 
                { 
                    if(maxSize < s[i][j]) 
                    { 
                        maxSize = s[i][j];
                    }      
                }                  
            }      
            return maxSize;
        } 

        public void dfs(ArrayList<ArrayList<Pair>> a , int index , int parent , long total[]){
            if(a.get(index).size() == 1 && a.get(index).get(0).v == parent){
                total[index] = 1;
                return;
            }
            int count = 0;
            for(int i=0;i<a.get(index).size();i++){
                int u = index;
                int v = a.get(index).get(i).v;
                if(v == parent)
                    continue;
                dfs(a , v , u , total);
            }
            for(int i=0;i<a.get(index).size();i++){
                int u = index;
                int v = a.get(index).get(i).v;
                if(v == parent)
                    continue;
                // System.out.println(u + " " + v + " ");
                // for(int j=0;j<a.get(v).size();j++){
                a.get(u).get(i).y += total[v];
                total[u] += total[v];
                // }
            }
            // return count;
        }

        class Pair{
            long x;
            long y;
            int v;
            long z;
            public Pair(long x , long y , int v , long z){
                this.x = x;
                this.y = y;
                this.v = v;
                this.z = z;
            }
        }

        class Sort implements Comparator<Pair>{
            public int compare(Pair a , Pair b){
                long difA = a.x*a.y - (a.x/2)*a.y;
                long difB = b.x*b.y - (b.x/2)*b.y;
                if(difA*b.z > difB*a.z)
                    return -1;
                if(difA*b.z == difB*a.z){
                    if(difA<difB)
                        return -1;
                    return 1;
                }
                return 1;
            }
        }

        class Node{
            char value;
            Node left;
            Node right;
            public Node(char value){
                this.value = value;
                left = null;
                right = null;
            }
        }
        

        public int[][] multiply(int a[][] , int b[][]){
            int c[][] = new int[a.length][b[0].length];
            for(int i=0;i<a.length;i++){
                for(int j=0;j<b[0].length;j++){
                    for(int k=0;k<b.length;k++)
                        c[i][j] += a[i][k]*b[k][j];
                }
            }
            return c;
        }

        public int[][] multiply(int a[][] , int b[][] , int mod){
            int c[][] = new int[a.length][b[0].length];
            for(int i=0;i<a.length;i++){
                for(int j=0;j<b[0].length;j++){
                    for(int k=0;k<b.length;k++){
                        c[i][j] += a[i][k]*b[k][j];
                        c[i][j]%=mod;
                    }
                }
            }
            return c;
        }

        public int[][] pow(int a[][] , long b){
            int res[][] = new int[a.length][a[0].length];
            for(int i=0;i<a.length;i++)
                res[i][i] = 1;
            while(b>0){
                if((b&1) == 1)
                    res = multiply(res , a , 10);
                a = multiply(a , a , 10);
                b>>=1;
            }
            return res;
        }

        public int distance(ArrayList<ArrayList<Integer>> a , int u , int v){
            return depth[u]+depth[v] - 2*depth[lca(a , u , v)];
        }

        public int lca(ArrayList<ArrayList<Integer>> a , int u , int v){
            if(depth[v]<depth[u]){
                int x = u;
                u = v;
                v = x;
            }
            int diff = depth[v] - depth[u];
            for(int i=0;i<parentTable[v].length;i++){
                // checking whether the ith bit is set in the diff variable
                if(((diff>>i)&1) == 1)
                    v = parentTable[v][i];
            }
            if(v == u)
                return v;
            for(int i=parentTable[v].length-1;i>=0;i--){
                if(parentTable[u][i] != parentTable[v][i]){
                    v = parentTable[v][i];
                    u = parentTable[u][i];
                }
            }
            return parentTable[u][0];
        }

        // for the min max problems
        public void build(int lookup[][] , int arr[], int n) { 
            for (int i = 0; i < n; i++) 
                lookup[i][0] = arr[i]; 
            for (int j = 1; (1 << j) <= n; j++) { 
                for (int i = 0; (i + (1 << j) - 1) < n; i++) { 
                    if (lookup[i][j - 1] > lookup[i + (1 << (j - 1))][j - 1]) 
                        lookup[i][j] = lookup[i][j - 1]; 
                    else
                        lookup[i][j] = lookup[i + (1 << (j - 1))][j - 1]; 
                } 
            } 
        }
        public int query(int lookup[][] , int L, int R) { 
            int j = (int)(Math.log(R - L + 1)/Math.log(2)); 
            if (lookup[L][j] >= lookup[R - (1 << j) + 1][j]) 
                return lookup[L][j]; 
            else
                return lookup[R - (1 << j) + 1][j]; 
        }

        // for printing purposes
        public void print1d(int a[] , PrintWriter out){
            for(int i=0;i<a.length;i++)
                out.print(a[i] + " ");
            out.println();
        }
        public void print1d(long a[] , PrintWriter out){
            for(int i=0;i<a.length;i++)
                out.print(a[i] + " ");
            out.println();
        }
        public void print2d(int a[][] , PrintWriter out){
            for(int i=0;i<a.length;i++){
                for(int j=0;j<a[i].length;j++)
                    out.print(a[i][j] + " ");
                out.println();
            }
            // out.println();
        }
        public void print2d(long a[][] , PrintWriter out){
            for(int i=0;i<a.length;i++){
                for(int j=0;j<a[i].length;j++)
                    out.print(a[i][j] + " ");
                out.println();
            }
            // out.println();
        }


        public void sieve(int a[]){
            a[0] = a[1] = 1;
            int i;
            for(i=2;i*i<=a.length;i++){
                if(a[i] != 0)
                    continue;
                a[i] = i;
                for(int k = (i)*(i);k<a.length;k+=i){
                    if(a[k] != 0)
                        continue;
                    a[k] = i;
                }
            }
        }

        public long nCrPFermet(int n , int r , long p){
            if(r==0)
                return 1l;
            // long fact[] = new long[n+1];
            // fact[0] = 1;
            // for(int i=1;i<=n;i++)
            //     fact[i] = (i*fact[i-1])%p;
            long modInverseR = pow(fact[r] , p-2 , p);
            long modInverseNR = pow(fact[n-r] , p-2 , p);
            long w = (((fact[n]*modInverseR)%p)*modInverseNR)%p;
            return w;
        }
        public long pow(long a, long b, long m) {
            a %= m;
            long res = 1;
            while (b > 0) {
                long x = b&1;
                if (x == 1)
                    res = res * a % m;
                a = a * a % m;
                b >>= 1;
            }
            return res;
        }
        public long pow(long a, long b) {
            long res = 1;
            while (b > 0) {
                long x = b&1;
                if (x == 1)
                    res = res * a;
                a = a * a;
                b >>= 1;
            }
            return res;
        }
        public void sortedArrayToBST(TreeSet<Integer> a , int start, int end) { 
            if (start > end) {
                return;
            }
            int mid = (start + end) / 2;
            a.add(mid);
            sortedArrayToBST(a, start, mid - 1);
            sortedArrayToBST(a, mid + 1, end); 
        }
        class Combine{
            int value;
            int delete;
            Combine(int val , int delete){
                this.value = val;
                this.delete = delete;
            }
        }
        class Sort2 implements Comparator<Combine>{
            public int compare(Combine a , Combine b){
                if(a.value > b.value)
                    return 1;
                else if(a.value == b.value && a.delete>b.delete)
                    return 1;
                else if(a.value == b.value && a.delete == b.delete)
                    return 0;
                return -1;
            }
        }
        public int lowerLastBound(ArrayList<Integer> a , int x){
            int l = 0;
            int r = a.size()-1;
            if(a.get(l)>=x)
                return -1;
            if(a.get(r)<x)
                return r;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a.get(mid) == x && a.get(mid-1)<x)
                    return mid-1;
                else if(a.get(mid)>=x)
                    r = mid-1;
                else if(a.get(mid)<x && a.get(mid+1)>=x)
                    return mid;
                else if(a.get(mid)<x && a.get(mid+1)<x)
                    l = mid+1;
            }
            return mid;
        }
        public int upperFirstBound(ArrayList<Integer> a , Integer x){
            int l = 0;
            int r = a.size()-1;
            if(a.get(l)>x)
                return l;
            if(a.get(r)<=x)
                return r+1;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a.get(mid) == x && a.get(mid+1)>x)
                    return mid+1;
                else if(a.get(mid)<=x)
                    l = mid+1;
                else if(a.get(mid)>x && a.get(mid-1)<=x)
                    return mid;
                else if(a.get(mid)>x && a.get(mid-1)>x)
                    r = mid-1;
            }
            return mid;
        }
        public int lowerLastBound(int a[] , int x){
            int l = 0;
            int r = a.length-1;
            if(a[l]>=x)
                return -1;
            if(a[r]<x)
                return r;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a[mid] == x && a[mid-1]<x)
                    return mid-1;
                else if(a[mid]>=x)
                    r = mid-1;
                else if(a[mid]<x && a[mid+1]>=x)
                    return mid;
                else if(a[mid]<x && a[mid+1]<x)
                    l = mid+1;
            }
            return mid;
        }
        public int upperFirstBound(long a[] , long x){
            int l = 0;
            int r = a.length-1;
            if(a[l]>x)
                return l;
            if(a[r]<=x)
                return r+1;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a[mid] == x && a[mid+1]>x)
                    return mid+1;
                else if(a[mid]<=x)
                    l = mid+1;
                else if(a[mid]>x && a[mid-1]<=x)
                    return mid;
                else if(a[mid]>x && a[mid-1]>x)
                    r = mid-1;
            }
            return mid;
        }
        public long log(float number , int base){
            return (long) Math.ceil((Math.log(number) / Math.log(base)) + 1e-9);
        }
        public long gcd(long a , long b){
            if(a<b){
                long c = b;
                b = a;
                a = c;
            }
            while(b!=0){
                long c = a;
                a = b;
                b = c%a;
            }
            return a;
        }
        public long[] gcdEx(long p, long q) {
            if (q == 0)
                return new long[] { p, 1, 0 };
            long[] vals = gcdEx(q, p % q);
            long d = vals[0];
            long a = vals[2];
            long b = vals[1] - (p / q) * vals[2];
            // 0->gcd 1->xValue 2->yValue
            return new long[] { d, a, b };
        }
        public void sievePhi(int a[]){
            a[0] = 0;
            a[1] = 1;
            for(int i=2;i<a.length;i++)
                a[i] = i-1;
            for(int i=2;i<a.length;i++)
                for(int j = 2*i;j<a.length;j+=i)
                    a[j] -= a[i];
        }
        public void lcmSum(long a[]){
            int sievePhi[] = new int[(int)1e6 + 1];
            sievePhi(sievePhi);
            a[0] = 0;
            for(int i=1;i<a.length;i++)
                for(int j = i;j<a.length;j+=i)
                    a[j] += (long)i*sievePhi[i];
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

    }
}