description: Tanya is learning how to add numbers, but so far she is not doing it correctly. She is adding two numbers a and b using the following algorithm:
  
    1. If one of the numbers is shorter than the other, Tanya adds leading zeros so that the numbers are the same length. 
    2. The numbers are processed from right to left (that is, from the least significant digits to the most significant). 
    3. In the first step, she adds the last digit of a to the last digit of b and writes their sum in the answer. 
    4. At each next step, she performs the same operation on each pair of digits in the same place and writes the result to the left side of the answer. 
  
  
  
  For example, the numbers a = 17236 and b = 3465 Tanya adds up as follows:
  
  $$$ \large{ \begin{array}{r} + \begin{array}{r} 17236\\\ 03465\\\ \end{array} \\\ \hline \begin{array}{r} 1106911 \end{array} \end{array}} $$$
  
    * calculates the sum of 6 + 5 = 11 and writes 11 in the answer. 
    * calculates the sum of 3 + 6 = 9 and writes the result to the left side of the answer to get 911. 
    * calculates the sum of 2 + 4 = 6 and writes the result to the left side of the answer to get 6911. 
    * calculates the sum of 7 + 3 = 10, and writes the result to the left side of the answer to get 106911. 
    * calculates the sum of 1 + 0 = 1 and writes the result to the left side of the answer and get 1106911. 
  
  
  
  As a result, she gets 1106911.
  
  You are given two positive integers a and s. Find the number b such that by adding a and b as described above, Tanya will get s. Or determine that no suitable b exists.
  
  Input
  
  The first line of input data contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases.
  
  Each test case consists of a single line containing two positive integers a and s (1 ≤ a < s ≤ 10^{18}) separated by a space.
  
  Output
  
  For each test case print the answer on a separate line.
  
  If the solution exists, print a single positive integer b. The answer must be written without leading zeros. If multiple answers exist, print any of them.
  
  If no suitable number b exists, output -1.
  
  Example
  
  Input
  
  
  6
  17236 1106911
  1 5
  108 112
  12345 1023412
  1 11
  1 20
  
  
  Output
  
  
  3465
  4
  -1
  90007
  10
  -1
  
  Note
  
  The first test case is explained in the main part of the statement.
  
  In the third test case, we cannot choose b that satisfies the problem statement.
solution: import java.io.*;
  import java.util.ArrayList;
  import java.util.StringTokenizer;
  
  public class WorngAdd {
  
      //Fast Input
      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());
          }
  
      }
  
      //Printing an array
      static void print(long[][] a, int r, int c) {
          PrintWriter pw = new PrintWriter(System.out);
          for (int i = 0; i < r; i++) {
              for (int j = 0; j < c; j++) {
                  pw.print(a[i][j] + " ");
              }
              pw.println();
          }
          pw.flush();
      }
  
      //Used to generate random test cases
      //Must be changed according to input format
      static void testCaseGenerator(int t, int lowN, int highN, long lowA, long highA) throws FileNotFoundException {
          File input = new File("C:\\Users\\debar\\OneDrive\\Documents\\input.txt");
          PrintWriter pw = new PrintWriter(input);
          pw.println(t);
          for (int i = 0; i < t; i++) {
              int n = (int) (Math.random() * (highN - lowN)) + lowN;
              pw.println(n);
              for (int j = 0; j < n; j++) {
                  long a = (long) (Math.random() * (highA - lowA)) + lowA;
                  pw.print(a + " ");
              }
              pw.println();
          }
          pw.flush();
      }
  
      //Find factorial of numbers from 1 to n
      //Check the size of factorial array
      static long[] factorial(int n, long mod) {
          long[] factorial = new long[n];
          factorial[0] = 1;
          for (int i = 1; i <= n; i++) {
              factorial[i] = (factorial[i - 1] * i) % mod;
          }
          return factorial;
      }
  
      //Find factorial inverse from 1 to n
      //Check the size of inverse_factorial array
      static long[] factorialInverse(int n, long mod) {
          long[] inverse_factorial = modularInverse(n, mod);
          for (int i = 2; i <= n; i++) {
              inverse_factorial[i] = (inverse_factorial[i] * inverse_factorial[i - 1]) % mod;
          }
          return inverse_factorial;
      }
  
      //Inverse exist when two number are relatively prime
      //Based on Fermat little theorem (a^mod-1)%mod=1 when mod is prime
      //a * a^(mod - 2) % mod = 1
      //a^(mod - 2) % mod =a^-1
      //When mod != prime use Extended euclidean theorem to calculate x and y for equation a*x + mod*y = gcd(a,b)=1
      //(a*x + mod*y = gcd(a,b)=1) % mod = a*x %mod =1
      //https://www.geeksforgeeks.org/find-initial-integral-solution-of-linear-diophantine-equation-if-finite-solution-exists/?ref=rp
      //Used for only one number
      static long modularInverse(long a, long mod) {
          return binaryExponentiation(a, mod - 2, mod);
      }
  
      //Modular inverse for number from 1 to n - 1
      //Time complexity O(n) for n numbers
      //Proof https://cp-algorithms.com/algebra/module-inverse.html
      static long[] modularInverse(int n, long mod) {
          long[] inv = new long[n];
          inv[1] = 1;
          for (int i = 2; i < n; i++) {
              inv[i] = mod - (mod / i) * inv[(int) (mod % i)] % mod;
          }
          return inv;
      }
  
      //GCD calculation of a and b with complexity O(log(Max(a,b))
      static long gcd(long a, long b) {
          long r;
          while (b != 0) {
              r = a % b;
              a = b;
              b = r;
          }
          return a;
      }
  
      //Find prime number upto n with complexity O(n*log(log(n)))
      //Travel through the multiple of prime number and set it to false
      static boolean[] sieveOfEratosthenes(int n) {
  
          boolean[] prime = new boolean[n + 1];
          for (int i = 0; i <= n; i++)
              prime[i] = true;
  
          for (int p = 2; p * p <= n; p++) {
              if (prime[p]) {
                  for (int i = p * p; i <= n; i += p)
                      prime[i] = false;
              }
          }
  
          prime[0] = prime[1] = false;
          return prime;
      }
  
      //Find Prefix sum in O(n)
      static long[] PrefixSum(long[] arr, int n) {
  
          long[] prefixSum = new long[n];
  
          prefixSum[0] = arr[0];
          for (int i = 1; i < n; ++i)
              prefixSum[i] = prefixSum[i - 1] + arr[i];
          return prefixSum;
      }
  
      //Find a^n in O(log n)
      //If n=11 then n in binary is equal to 1011
      //a^n=a^(8+2+1) that is multiply with result when bit is set.
      //https://youtu.be/L-Wzglnm4dM
      static long binaryExponentiation(long a, long n, long mod) {
          long result = 1L;
          n = n % (mod - 1);
          //n = (mod - 1) * floor(n / (mod - 1)) + n % (mod - 1)
          //a^((mod - 1) * floor(n / (mod - 1))) % mod = 1 so a^n % mod =a^(n % (mod - 1)) % mod when mod is prime
          //Using fermat little theorem a^(p-1) % p = 1 when p is prime
          while (n > 0) {
              if ((n & 1) == 1) {
                  result = (result * a) % mod;
              }
              a = (a * a) % mod;
              n /= 2;
          }
          return result;
      }
  
      //Matrix multiplication
      static long[][] matrixMultiply(long[][] a, long[][] b, int row, int col, int mid, long mod) {
          long[][] c = new long[row][col];
          for (int i = 0; i < row; i++) {
              for (int j = 0; j < col; j++) {
                  c[i][j] = 0;
                  for (int k = 0; k < mid; k++) {
                      c[i][j] = (c[i][j] + (a[i][k] * b[k][j]) % mod) % mod;
                  }
              }
          }
          return c;
      }
  
      //Matrix Exponentiation
      static long[][] matrixExponentiation(long[][] a, long n, int size, long mod) {
          if (n == 0) {
              long[][] temp = new long[size][size];
              for (int i = 0; i < size; i++) {
                  temp[i][i] = 1;
              }
              return temp;//Returns identity matrix
          } else {
              long[][] temp = matrixExponentiation(a, n / 2, size, mod);
              if (n % 2 == 0) {
                  return matrixMultiply(temp, temp, size, size, size, mod);
              } else {
                  return matrixMultiply(matrixMultiply(temp, temp, size, size, size, mod), a, size, size, size, mod);
              }
          }
      }
  
      //Solution starts here
      public static void main(String[] args) {
  
          //Input output class reference
          FastReader sc = new FastReader();
          PrintWriter pw = new PrintWriter(System.out);
  
          //Number of test case
          int t = sc.nextInt();
  
          //For each test case
          for (int i = 0; i < t; i++)
          {
              long a1=sc.nextLong();
              long b1=sc.nextLong();
  
              StringBuilder a= new StringBuilder(Long.toString(a1));
              StringBuilder b= new StringBuilder(Long.toString(b1));
              if(a1>b1)
                  pw.println(-1);
              else
              {
                  b.reverse();
                  a.reverse();
                  int j1=0;
                  boolean flag=false;
                  ArrayList<String> digits=new ArrayList<>();
                  for(int j=0;j<a.length();j++)
                  {
                      if(j1<b.length())
                      {
                          if (a.charAt(j) <= b.charAt(j1))
                          {
                              digits.add(Character.toString(b.charAt(j1)));
                              j1++;
                          }
                          else
                          {
                              if(j1+1<b.length())
                              {
                                  if(Integer.parseInt(new StringBuilder(b.substring(j1, j1 + 2)).reverse().toString())<Integer.parseInt(Character.toString(a.charAt(j))))
                                  {
                                      flag = true;
                                      break;
                                  }
                                  else
                                  {
                                      digits.add(new StringBuilder(b.substring(j1, j1 + 2)).reverse().toString());
                                      j1 += 2;
                                  }
                              }
                              else
                              {
                                  flag=true;
                                  break;
                              }
                          }
                      }
                      else
                      {
                         flag=true;
                         break;
                      }
                  }
  
                  //System.out.println(digits);
                  StringBuilder ans=new StringBuilder();
                  if(flag)
                      pw.println(-1);
                  else
                  {
                      for(int j=0;j<a.length();j++)
                      {
                          if(Integer.parseInt(digits.get(j))-Integer.parseInt(Character.toString(a.charAt(j)))<=9)
                              ans.append(Integer.parseInt(digits.get(j))-Integer.parseInt(Character.toString(a.charAt(j))));
                          else
                          {
                              flag=true;
                          }
                      }
                      if(flag)
                          pw.println(-1);
                      else
                      {
                          ans.append(b.substring(j1));
                          pw.println(Long.parseLong(ans.reverse().toString()));
                      }
                  }
              }
          }
          pw.flush();
      }
      //Solution ends here
  }