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:  If one of the numbers is shorter than the other, Tanya adds leading zeros so that the numbers are the same length.  The numbers are processed from right to left (that is, from the least significant digits to the most significant).  In the first step, she adds the last digit of $$$a$$$ to the last digit of $$$b$$$ and writes their sum in the answer.  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.

The first line of input data contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of a single line containing two positive integers $$$a$$$ and $$$s$$$ ($$$1 \le a \lt s \le 10^{18}$$$) separated by a space.

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.

NoteThe 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.

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
            return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
        let n = readline().split(' ');
        let a = '';
        a += n[0]
        let s = '';
        s += n[1]
        var j = a.length-1;
        var b = '';
        var y = false;
        for(var i=s.length-1;i>=0 && j>=0;i--) {
            if(s[i] !== '\r') {
              if(s[i] < a[j]) {
        		if(i > 0 && s[i-1] <= '1') {
        	  	  var d = s[i-1]+s[i];
        		  b += d-a[j];
        		  i--;
        		  j--;
        		} else {
        		   // console.log(s[i-1])
        			y = false;
        			break;
        		}
        	  } else {
        		b += s[i]-a[j]
        		j--;
        	  }
            }
        }
        while(i>=0) {
        	b += s[i];
        	i--;
        }
        var ans = '';
        if(j == -1 && i == -1) {
        	var an = '';
        	y = true;
        	for(var t = b.length-1;t>=0;t--) {
        		if(b[t] !== '0') {
        			break;
        		}
        		if(b[t] == '-') {
        		    y = false;
        		    break;
        		}
        	}
        	while(t >= 0) {
        	    if(b[t] == '-') {
        	        y = false;
        	        break;
        	    }
        		an += b[t]
        		t--;
        	}
        	ans = an;
        } else {
        	y = false;
        }
        //console.log(y)
        y == true ? console.log(ans) : console.log('-1');
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [a, s] = lines[l++].trim().split(' ')
        output[i] = solve(a, s)
    }
    console.log(output.join('\n'))
// })()
})

function solve(a, s) {
    let i = a.length - 1
    let j = s.length - 1
    const b = []
    while (i >= 0 && j >= 0) {
        const x = +a[i]
        const y = +s[j]
        if (y >= x) {
            b.unshift(y - x)
            i--
            j--
        } else if (s[j - 1] === '1') {
            b.unshift(y + 10 - x)
            i--
            j -= 2
        } else {
            return -1
        }
    }
    // console.log(i, j, b.join(''))
    if (i >= 0) return -1
    while (j >= 0) b.unshift(s[j--])
    return BigInt(b.join('')).toString()
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});
function readLine() {
  return inputString[currentLine++];
};
process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });
  main();
  // cmd: node cp.js < input.txt > output.txt
});
function main() {
  let t = parseInt(readLine());
  while (t--) {
    solve();
  }
}
function solve() {
  let inpArr = readLine().split(" ");
  let a = BigInt(inpArr[0]);
  let s = BigInt(inpArr[1]);
  let b = [];
  while (s > 0) {
    let x = a % 10n, y = s % 10n;
    if (x <= y) {
      b.unshift(y - x);
    } else {
      s = (s / 10n);
      y += 10n * (s % 10n);
      if (x < y && y >= 10 && y <= 19) {
        b.unshift(y - x);
      } else {
        console.log(-1);
        return;
      }
    }
    a = (a / 10n);
    s = (s / 10n)
  }
  if (a) {
    console.log(-1);
  } else {
    console.log(BigInt(b.join("")).toString());
  }
}

let buffer = '';
process.stdin.on('data', c => buffer += c);
process.stdin.on('end', () => {
  const { EOL } = require('os');
  const lines = buffer.split(EOL);
  lines.pop();

  main(lines);
});

function main(lines) {
  let index = 0;
  let T = Number(lines[index++]);
  let a, s;

  while (T--) {
    [a, s] = lines[index++].split(' ');
    solve(a, s);
  }
}

function solve(aIn, sIn) {
  let a = aIn.split('').map(Number);
  let s = sIn.split('').map(Number);
  let value, b = '';
  let oneDigitNumber;
  let twoDigitsNumber;

  for (let i = s.length - 1; i >= 0; --i) {
    oneDigitNumber = s[i];
    twoDigitsNumber = s[i - 1] * 10 + s[i];

    if (oneDigitNumber >= a[a.length - 1]) {
      value = oneDigitNumber - a[a.length - 1];
    } else if (twoDigitsNumber > a[a.length - 1] && twoDigitsNumber - a[a.length - 1] < 10) {
      value = twoDigitsNumber - a[a.length - 1];
      i--;
    } else if (!a.length) {
      value = s[i];
    } else {
      console.log('-1');
      return;
    }

    b = value + b;
    a.pop();
  }

  if (Number(a.join('')) > 0) {
    console.log('-1');
    return;
  }

  b = b.replace(/^0+/, '') || '0';

  console.log(b);
}

// https://codeforces.com/problemset/problem/1619/C

const readline = require('readline')
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
})

const getLine = (function () {
  const getLineGen = (async function* () {
    for await (const line of rl) {
      yield line
    }
  })()
  return async () => {
    let next
    do {
      next = await getLineGen.next()
    } while (!next.done && next.value === '')
    return next.value
  }
})()

let solve = async () => {
  const strLine = parseInt(await getLine())
  for (let i = 0; i < strLine; i++) {
    const str = await getLine()
    let param = str.split(' ')
    a = Array.from(param[0])
    s = Array.from(param[1])

    let suitable = true

    if (a.length > s.length) {
      suitable = false
    }
    let res = []
    let atemp = []
    let stemp = []

    while (a.length > 0) {
      if (s.length === 0) suitable = false
      atemp = a.pop()
      stemp = s.pop()
      if (parseInt(stemp) >= parseInt(atemp))
        res.unshift(parseInt(stemp) - parseInt(atemp))
      else {
        if (s.length === 0) suitable = false
        if (s.pop() != '1') suitable = false
        res.unshift(parseInt(stemp) + 10 - parseInt(atemp))
      }
    }
    while (s.length > 0) res.unshift(parseInt(s.pop()))
    while (res[0] === 0) res.shift()
    console.log(suitable ? res.join('') : '-1')
  }
  //   process.exit()
  process.stdin.unref()
}

solve()

// https://codeforces.com/problemset/problem/1619/C

const readline = require('readline')
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
})

const getLine = (function () {
  const getLineGen = (async function* () {
    for await (const line of rl) {
      yield line
    }
  })()
  return async () => {
    let next
    do {
      next = await getLineGen.next()
    } while (!next.done && next.value === '')
    return next.value
  }
})()

let solve = async () => {
  const strLine = parseInt(await getLine())
  for (let i = 0; i < strLine; i++) {
    const str = await getLine()
    let param = str.split(' ')
    a = Array.from(param[0])
    s = Array.from(param[1])

    if (a.length > s.length) {
      console.log('-1')
      break
    }
    let res = Array.from('')
    let atemp = ''
    let stemp = ''
    let n = ''
    flag = true
    while (a.length > 0) {
      if (s.length === 0) {
        console.log('-1')
        flag = false
        break
      }
      atemp = a.pop()
      stemp = s.pop()
      if (parseInt(stemp) >= parseInt(atemp)) {
        res.push(parseInt(stemp) - parseInt(atemp))
      } else {
        if (s.length === 0) {
          console.log('-1')
          flag = false
          break
        }
        n = s.pop()
        if (n != '1') {
          console.log('-1')
          flag = false
          break
        }
        stemp = n + stemp
        res.push(parseInt(stemp) - parseInt(atemp))
      }
    }
    if (flag) {
      while (s.length > 0) {
        res.push(parseInt(s.pop()))
      }
      while (res[res.length - 1] === 0) {
        res.pop()
      }
      let resstr = ''
      while (res.length > 0) {
        resstr += res.pop()
      }
      console.log(resstr)
    }
  }

  //   process.exit()
  process.stdin.unref()
}

solve()

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function main() {
    let [t] = readline().split(' ').map(num => parseInt(num));
    for (let i = 0; i < t; i++) {
        let [a, s] = readline().split(' ');

        function getDigitB() {
            if (s.length === 0) {
                return null;
            }
            let ad = a.length > 0 ? parseInt(a[a.length - 1]) : 0;
            let sd = parseInt(s[s.length - 1]);
            let sdd = s.length > 1 ? parseInt(s[s.length - 2]) : null;
            if (ad <= sd) {
                a = a.length > 0 ? a.slice(0, a.length - 1) : a;
                s = s.slice(0, s.length - 1);
                return sd - ad;
            } else if (sdd === 1 && sd < 9) {
                a = a.length > 0 ? a.slice(0, a.length - 1) : a;
                s = s.slice(0, s.length - 2);
                return sdd * 10 + sd - ad;
            } else {
                return null;
            }
        }

        let b = '';
        let bd = getDigitB();
        while (bd !== null) {
            b = bd.toString() + b;
            bd = getDigitB();
        }
        let start = -1;
        for (let i = 0; i < b.length; i++) {
            if (b[i] !== '0') {
                start = i;
                break;
            }
        }
        if (!s && !a && start !== -1) {
            console.log(b.slice(start));
        } else {
            console.log('-1');
        }
    }
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let [n, s] = readline().trim().split(" ");
    let b = [];
    let i = n.length - 1,
      j = s.length - 1,
      ans = true;
    while (i >= 0) {
      if (j < 0) {
        ans = false;
        break;
      }
      let n1 = parseInt(n[i]),
        n2 = parseInt(s[j]);
      if (n1 <= n2) {
        b.push(n2 - n1);
        i--;
        j--;
      } else if (n1 > n2) {
        if (j - 1 < 0) {
          ans = false;
          break;
        }
        j--;
        n2 = parseInt(s[j]) * 10 + n2;
        if (n2 >= 10 && n2 <= 18) {
          b.push(n2 - n1);
          j--;
        } else {
          ans = false;
          break;
        }
        i--;
      }
    }
    if (ans === false) console.log(-1);
    else {
      while (j >= 0) b.push(s[j--]);
      let res = "",
        is = true;
      for (let i = b.length - 1; i >= 0; i--) {
        if (b[i] === 0 && is) continue;
        else {
          res += b[i];
          is = false;
        }
      }
      console.log(res);
    }
  }
};
solve();

process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********
function main() {
  var num = parseInt(readline())
	while(num--){
    var line = readline().split(' ').map(String)
    var a = '0'.repeat(50) + line[0]
    var b = '0'.repeat(50) + line[1]

    const arr = []
    let ok = true
    for (let i = a.length - 1, j = b.length - 1; ok && i && j; i--, j--){
      if(b[j] >= a[i]){
        let tmp = Number(b[j]) - Number(a[i])
        arr.unshift(tmp)
      }
      else{
        let tmp = Number(b[j-1])*10 + Number(b[j]) - Number(a[i])
        if(tmp > 9 || tmp < 0){
          ok = false
        }
        else{
          arr.unshift(tmp)
        }
        j--
      }
    }
    while (arr[0] == 0) arr.shift()
    print(ok?arr.join(''):-1)
  }

}

process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********
function main() {
  var num = parseInt(readline())
	while(num--){
    var line = readline().split(' ').map(String)
    var a = '0'.repeat(50) + line[0]
    var b = '0'.repeat(50) + line[1]

    const arr = []
    let ok = true
    for (let i = a.length - 1, j = b.length - 1; ok && i && j; i--, j--){
      if(b[j] >= a[i]){
        let tmp = Number(b[j]) - Number(a[i])
        arr.unshift(tmp)
      }
      else{
        let tmp = Number(b[j-1])*10 + Number(b[j]) - Number(a[i])
        if(tmp > 9 || tmp < 0){
          ok = false
        }
        else{
          arr.unshift(tmp)
        }
        j--
      }
    }
    while (arr[0] == 0) arr.shift();
    print(ok?arr.join(''):-1)
  }

}

process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********
function main() {
  let num = parseInt(readline());
  while (num--) {
    let line = readline().split(" ").map(String);
    let a = "0".repeat(50) + line[0];
    let b = "0".repeat(50) + line[1];

    const arr = [];
    let ok = true;
    for (let i = a.length - 1, j = b.length - 1; ok && i && j; i--, j--) {
      if (b[j] >= a[i]) {
        let tmp = Number(b[j]) - Number(a[i]);
        arr.unshift(tmp);
      } else {
        let tmp = Number(b[j - 1]) * 10 + Number(b[j]) - Number(a[i]);
        if (tmp > 9 || tmp < 0) {
          ok = false;
        } else {
          arr.unshift(tmp);
        }
        j--;
      }
    }
    while (arr[0] == 0) arr.shift();
    print(ok ? arr.join("") : -1);
  }
}

var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

function main () {
	let T = rn();
	while (T--) {
		let [a, s] = rl().split(' ');

		a = '0'.repeat(50) + a;
		s = '0'.repeat(50) + s;

		const b = [];
		let ok = true;
		for (let i = a.length - 1, j = s.length - 1; ok && i && j; i--, j--) {
			if (s[j] >= a[i]) {
				b.unshift(Number(s[j]) - Number(a[i]));
			} else {
				let res = Number(s[j-1])*10 + Number(s[j]) - Number(a[i]);
				if (res > 9 || res < 0)
					ok = false;
				else
					b.unshift(res);
				j--;
			}
		}

		while (b[0] == 0) b.shift();

		console.log(ok ? b.join('') : -1);
	}
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
            return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
        let n = readline().split(' ');
        let a = '';
        a += n[0]
        let s = '';
        s += n[1]
        var j = a.length-1;
        var b = '';
        var y = false;
        for(var i=s.length-1;i>=0 && j>=0;i--) {
            if(s[i] !== '\r') {
              if(s[i] < a[j]) {
        		if(i > 0 && s[i-1] <= '1') {
        	  	  var d = s[i-1]+s[i];
        		  b += d-a[j];
        		  i--;
        		  j--;
        		} else {
        		   // console.log(s[i-1])
        			y = false;
        			break;
        		}
        	  } else {
        		b += s[i]-a[j]
        		j--;
        	  }
            }
        }
        while(i>=0) {
        	b += s[i];
        	i--;
        }
        var ans = '';
        if(j == -1 && i == -1) {
        	var an = '';
        	y = true;
        	for(var t = b.length-1;t>=0;t--) {
        		if(b[t] !== '0') {
        			break;
        		}
        	}
        	while(t >= 0) {
        		an += b[t]
        		t--;
        	}
        	ans = an;
        } else {
        	y = false;
        }
        //console.log(y)
        y == true ? console.log(ans) : console.log('-1');
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
            return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
        let n = readline().split(' ');
        let a = '';
        a += n[0]
        let s = '';
        s += n[1]
        var j = a.length-1;
        var b = '';
        var y = false;
        for(var i=s.length-1;i>=0 && j>=0;i--) {
              if(s[i] < a[j]) {
                  console.log([s[i], a[j]])
        		if(i > 0 && s[i-1] <= '1') {
        	  	  var d = s[i-1]+s[i];
        		  b += d-a[j];
        		  i--;
        		  j--;
        		} else {
        		    console.log(s[i-1])
        			y = false;
        			break;
        		}
        	  } else {
        		b += s[i]-a[j]
        		j--;
        	  }
        }
        while(i>=0) {
        	b += s[i];
        	i--;
        }
        var ans = '';
        if(j == -1 && i == -1) {
        	var an = '';
        	y = true;
        	for(var t = b.length-1;t>=0;t--) {
        		if(b[t] !== '0') {
        			break;
        		}
        	}
        	while(t >= 0) {
        		an += b[t]
        		t--;
        	}
        	ans = an;
        } else {
        	y = false;
        }
        //console.log(y)
        y == true ? console.log(ans) : console.log('-1');
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
            return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
        let n = readline().split(' ');
        let a = '';
        a += n[0]
        let s = '';
        s += n[1]
        var j = a.length-1;
        var b = '';
        var y = false;
        for(var i=s.length-1;i>=0 && j>=0;i--) {
              if(s[i] < a[j]) {
        		if(i > 0 && s[i-1] <= '1') {
        	  	  var d = s[i-1]+s[i];
        		  b += d-a[j];
        		  i--;
        		  j--;
        		} else {
        		    console.log(b)
        		    console.log(s[i-1])
        			y = false;
        			break;
        		}
        	  } else {
        		b += s[i]-a[j]
        		j--;
        	  }
        }
        while(i>=0) {
        	b += s[i];
        	i--;
        }
        var ans = '';
        if(j == -1 && i == -1) {
        	var an = '';
        	y = true;
        	for(var t = b.length-1;t>=0;t--) {
        		if(b[t] !== '0') {
        			break;
        		}
        	}
        	while(t >= 0) {
        		an += b[t]
        		t--;
        	}
        	ans = an;
        } else {
        	y = false;
        }
        //console.log(y)
        y == true ? console.log(ans) : console.log('-1');
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
            return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
        let n = readline().split(' ');
        let a = '';
        a += n[0]
        let s = '';
        s += n[1]
        var j = a.length-1;
        var b = '';
        var y = false;
        for(var i=s.length-1;i>=0 && j>=0;i--) {
              if(s[i] < a[j]) {
        		if(i > 0 && s[i-1] <= '1') {
        	  	  var d = s[i-1]+s[i];
        		  b += d-a[j];
        		  i--;
        		  j--;
        		} else {
        		    console.log(s[i-1])
        			y = false;
        			break;
        		}
        	  } else {
        		b += s[i]-a[j]
        		j--;
        	  }
        }
        while(i>=0) {
        	b += s[i];
        	i--;
        }
        var ans = '';
        if(j == -1 && i == -1) {
        	var an = '';
        	y = true;
        	for(var t = b.length-1;t>=0;t--) {
        		if(b[t] !== '0') {
        			break;
        		}
        	}
        	while(t >= 0) {
        		an += b[t]
        		t--;
        	}
        	ans = an;
        } else {
        	y = false;
        }
        //console.log(y)
        y == true ? console.log(ans) : console.log('-1');
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
            return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
        let n = readline().split(' ');
        let a = '';
        a += n[0]
        let s = '';
        s += n[1]
        var j = a.length-1;
        var b = '';
        var y = false;
        for(var i=s.length-1;i>=0 && j>=0;i--) {
              if(s[i] < a[j]) {
        		if(s[i-1] <= '1') {
        		  console.log(s[i-1])
        	  	  var d = s[i-1]+s[i];
        		  b += d-a[j];
        		  i--;
        		  j--;
        		} else {
        			y = false;
        			break;
        		}
        	  } else {
        		b += s[i]-a[j]
        		j--;
        	  }
        }
        while(i>=0) {
        	b += s[i];
        	i--;
        }
        var ans = '';
        if(j == -1 && i == -1) {
        	var an = '';
        	y = true;
        	for(var t = b.length-1;t>=0;t--) {
        		if(b[t] !== '0') {
        			break;
        		}
        	}
        	while(t >= 0) {
        		an += b[t]
        		t--;
        	}
        	ans = an;
        } else {
        	y = false;
        }
        //console.log(y)
        y == true ? console.log(ans) : console.log('-1');
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
            return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
        let n = readline().split(' ');
        let a = '';
        a += n[0]
        let s = '';
        s += n[1]
        var j = a.length-1;
        var b = '';
        var y = false;
        for(var i=s.length-1;i>=0 && j>=0;i--) {
              if(s[i] < a[j]) {
        		if(i > 0 && s[i-1] <= '1') {
        	  	  var d = s[i-1]+s[i];
        		  b += d-a[j];
        		  i--;
        		  j--;
        		} else {
        			y = false;
        			break;
        		}
        	  } else {
        		b += s[i]-a[j]
        		j--;
        	  }
        }
        while(i>=0) {
        	b += s[i];
        	i--;
        }
        var ans = '';
        if(j == -1 && i == -1) {
        	var an = '';
        	y = true;
        	for(var t = b.length-1;t>=0;t--) {
        		if(b[t] !== '0') {
        			break;
        		}
        	}
        	while(t >= 0) {
        		an += b[t]
        		t--;
        	}
        	ans = an;
        } else {
        	y = false;
        }
        //console.log(y)
        y == true ? console.log(ans) : console.log('-1');
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
            return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
        let n = readline().split(' ');
        let a = '';
        a += n[0]
        let s = '';
        s += n[1]
        var j = a.length-1;
        var b = '';
        var y = false;
        for(var i=s.length-1;i>=0 && j>=0;i--) {
          if(s[i] !== '\r' && a[j] !== '\r') {
              if(s[i] < a[j]) {
        		if(i > 0 && s[i-1] <= 1) {
        	  	  var d = s[i-1]+s[i];
        		  b += d-a[j];
        		  i--;
        		  j--;
        		} else {
        			y = false;
        			break;
        		}
        	  } else {
        		b += s[i]-a[j]
        		j--;
        	  }
          } else {
              console.log(s[i], a[j])
              j--;
          }
        }
        while(i>=0) {
        	b += s[i];
        	i--;
        }
        var ans = '';
        if(j == -1 && i == -1) {
        	var an = '';
        	y = true;
        	for(var t = b.length-1;t>=0;t--) {
        		if(b[t] !== '0') {
        			break;
        		}
        	}
        	while(t >= 0) {
        		an += b[t]
        		t--;
        	}
        	ans = an;
        } else {
        	y = false;
        }
        //console.log(y)
        y == true ? console.log(ans) : console.log(-1);
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
            return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
        let n = readline().split(' ');
        let a = '';
        a += n[0]
        let s = '';
        s += n[1]
        var j = a.length-1;
        var b = '';
        var y = false;
        for(var i=s.length-1;i>=0 && j>=0;i--) {
          if(s[i] !== '\r' && a[j] !== '\r') {
              if(s[i] < a[j]) {
        		if(i > 0 && s[i-1] <= 1) {
        	  	  var d = s[i-1]+s[i];
        		  b += d-a[j];
        		  i--;
        		  j--;
        		} else {
        			y = false;
        			break;
        		}
        	  } else {
        		b += s[i]-a[j]
        		j--;
        	  }
          } else {
              j--;
          }
        }
        while(i>=0) {
        	b += s[i];
        	i--;
        }
        var ans = '';
        if(j == -1 && i == -1) {
        	var an = '';
        	y = true;
        	for(var t = b.length-1;t>=0;t--) {
        		if(b[t] !== '0') {
        			break;
        		}
        	}
        	while(t >= 0) {
        		an += b[t]
        		t--;
        	}
        	ans = an;
        } else {
        	y = false;
        }
        //console.log(y)
        y == true ? console.log(ans) : console.log(-1);
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
            return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
        let n = readline().split(' ');
        let a = '';
        a += n[0]
        let s = '';
        s += n[1]
        var j = a.length-1;
        var b = '';
        var y = false;
        for(var i=s.length-1;i>=0 && j>=0;i--) {
        	if(s[i] < a[j]) {
        	    console.log(s[i])
        		if(i > 0 && s[i-1] <= 1) {
        	  	  var d = s[i-1]+s[i];
        		  b += d-a[j];
        		  i--;
        		  j--;
        		} /*else {
        			y = false;
        			break;
        		}*/
        	} else {
        		b += s[i]-a[j]
        		j--;
        	}
        }
        while(i>=0) {
        	b += s[i];
        	i--;
        }
        var ans = '';
        if(j == -1 && i == -1) {
        	var an = '';
        	y = true;
        	for(var t = b.length-1;t>=0;t--) {
        		if(b[t] !== '0') {
        			break;
        		}
        	}
        	while(t >= 0) {
        		an += b[t]
        		t--;
        	}
        	ans = an;
        } else {
        	y = false;
        }
        console.log(y)
        y == true ? console.log(ans) : console.log(-1);
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
            return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
        let n = readline().split(' ');
        let a = '';
        a += n[0]
        let s = '';
        s += n[1]
        var j = a.length-1;
        var b = '';
        var y = false;
        for(var i=s.length-1;i>=0;i--) {
        	if(s[i] < a[j]) {
        	    console.log(s[i])
        		if(i > 0 && s[i-1] <= 1) {
        	  	  var d = s[i-1]+s[i];
        		  b += d-a[j];
        		  i--;
        		  j--;
        		} else {
        			y = false;
        			break;
        		}
        	} else {
        		b += s[i]-a[j]
        		j--;
        	}
        }
        while(i>=0) {
        	b += s[i];
        	i--;
        }
        var ans = '';
        if(j == -1 && i == -1) {
        	var an = '';
        	y = true;
        	for(var t = b.length-1;t>=0;t--) {
        		if(b[t] !== '0') {
        			break;
        		}
        	}
        	while(t >= 0) {
        		an += b[t]
        		t--;
        	}
        	ans = an;
        } else {
        	y = false;
        }
        console.log(y)
        y == true ? console.log(ans) : console.log(-1);
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
            return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
        let n = readline().split(' ');
        let a = '';
        a += n[0]
        let s = '';
        s += n[1]
        var j = a.length-1;
        var b = '';
        var y = false;
        for(var i=s.length-1;i>=0 && j>=0;i--) {
        	if(s[i] < a[j]) {
        	    console.log(s[i])
        		if(i > 0 && s[i-1] <= 1) {
        	  	  var d = s[i-1]+s[i];
        		  b += d-a[j];
        		  i--;
        		  j--;
        		} else {
        			y = false;
        			break;
        		}
        	} else {
        		b += s[i]-a[j]
        		j--;
        	}
        }
        while(i>=0) {
        	b += s[i];
        	i--;
        }
        var ans = '';
        if(j == -1 && i == -1) {
        	var an = '';
        	y = true;
        	for(var t = b.length-1;t>=0;t--) {
        		if(b[t] !== '0') {
        			break;
        		}
        	}
        	while(t >= 0) {
        		an += b[t]
        		t--;
        	}
        	ans = an;
        } else {
        	y = false;
        }
        console.log(y)
        y == true ? console.log(ans) : console.log(-1);
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
            return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
        let n = readline().split(' ');
        let a = '';
        a += n[0]
        let s = '';
        s += n[1]
        var j = a.length-1;
        var b = '';
        var y = false;
        for(var i=s.length-1;i>=0 && j>=0;i--) {
        	if(s[i] < a[j]) {
        		if(i > 0 && s[i-1] <= 1) {
        	  	  var d = s[i-1]+s[i];
        		  b += d-a[j];
        		  i--;
        		  j--;
        		} else {
        			y = false;
        			break;
        		}
        	} else {
        		b += s[i]-a[j]
        		j--;
        	}
        }
        while(i>=0) {
        	b += s[i];
        	i--;
        }
        var ans = '';
        if(j == -1 && i == -1) {
        	var an = '';
        	y = true;
        	for(var t = b.length-1;t>=0;t--) {
        		if(b[t] !== '0') {
        			break;
        		}
        	}
        	while(t >= 0) {
        		an += b[t]
        		t--;
        	}
        	ans = an;
        } else {
        	y = false;
        }
       // console.log(a, s)
        y == true ? console.log(ans) : console.log(-1);
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
            return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
        let n = readline().split(' ');
        let a = '';
        a += n[0]
        let s = '';
        s += n[1]
        var j = a.length-1;
        var b = '';
        var y = false;
        for(var i=s.length-1;i>=0;i--) {
            console.log(s[i])
            console.log(a[i])
        }
        for(var i=s.length-1;i>=0 && j>=0;i--) {
        	if(s[i] < a[j]) {
        		if(i > 0 && s[i-1] <= 1) {
        	  	  var d = s[i-1]+s[i];
        		  b += d-a[j];
        		  i--;
        		  j--;
        		} else {
        			y = false;
        			break;
        		}
        	} else {
        	//	if(j>=0) {
        		b += s[i]-a[j]
        		j--;
        		/* else {
        			b += s[i]
        		}*/
        	}
        }
        while(i>=0) {
        	b += s[i];
        	i--;
        }
        var ans = '';
        if(j == -1 && i == -1) {
        	var an = '';
        	y = true;
        	for(var t = b.length-1;t>=0;t--) {
        		if(b[t] !== '0') {
        			break;
        		}
        	}
        	while(t >= 0) {
        		an += b[t]
        		t--;
        	}
        	ans = an;
        } else {
        	y = false;
        }
       // console.log(a, s)
        y ? console.log(ans) : console.log(-1);
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
            return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
        let n = readline().split(' ');
        let a = '';
        a += n[0]
        let s = '';
        s += n[1]
        var j = a.length-1;
        var b = '';
        var y = false;
        for(var i=0;i<a.length;i++) console.log(a[i])
        for(var i=s.length-1;i>=0 && j>=0;i--) {
            console.log(s[i])
        	if(s[i] < a[j]) {
        		if(i > 0 && s[i-1] <= 1) {
        	  	  var d = s[i-1]+s[i];
        		  b += d-a[j];
        		  i--;
        		  j--;
        		} else {
        			y = false;
        			break;
        		}
        	} else {
        	//	if(j>=0) {
        		b += s[i]-a[j]
        		j--;
        		/* else {
        			b += s[i]
        		}*/
        	}
        }
        while(i>=0) {
        	b += s[i];
        	i--;
        }
        var ans = '';
        if(j == -1 && i == -1) {
        	var an = '';
        	y = true;
        	for(var t = b.length-1;t>=0;t--) {
        		if(b[t] !== '0') {
        			break;
        		}
        	}
        	while(t >= 0) {
        		an += b[t]
        		t--;
        	}
        	ans = an;
        } else {
        	y = false;
        }
       // console.log(a, s)
        y ? console.log(ans) : console.log(-1);
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
            return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
        let n = readline().split(' ');
        let a = '';
        a += n[0]
        let s = '';
        s += n[1]
        var j = a.length-1;
        var b = '';
        var y = false;
        for(var i=0;i<s.length;i++) console.log(s[i])
        for(var i=s.length-1;i>=0 && j>=0;i--) {
        	if(s[i] < a[j]) {
        		if(i > 0 && s[i-1] <= 1) {
        	  	  var d = s[i-1]+s[i];
        		  b += d-a[j];
        		  i--;
        		  j--;
        		} else {
        			y = false;
        			break;
        		}
        	} else {
        	//	if(j>=0) {
        		b += s[i]-a[j]
        		j--;
        		/* else {
        			b += s[i]
        		}*/
        	}
        }
        while(i>=0) {
        	b += s[i];
        	i--;
        }
        var ans = '';
        if(j == -1 && i == -1) {
        	var an = '';
        	y = true;
        	for(var t = b.length-1;t>=0;t--) {
        		if(b[t] !== '0') {
        			break;
        		}
        	}
        	while(t >= 0) {
        		an += b[t]
        		t--;
        	}
        	ans = an;
        } else {
        	y = false;
        }
       // console.log(a, s)
        y ? console.log(ans) : console.log(-1);
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
            return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
        let n = readline().split(' ');
        let a = '';
        a += n[0]
        let s = '';
        s += n[1]
        var j = a.length-1;
        var b = '';
        var y = false;
        for(var i=s.length-1;i>=0 && j>=0;i--) {
            console.log(s[i])
            console.log(a[j])
        	if(s[i] < a[j]) {
        		if(i > 0 && s[i-1] <= 1) {
        	  	  var d = s[i-1]+s[i];
        		  b += d-a[j];
        		  i--;
        		  j--;
        		} else {
        			y = false;
        			break;
        		}
        	} else {
        	//	if(j>=0) {
        		b += s[i]-a[j]
        		j--;
        		/* else {
        			b += s[i]
        		}*/
        	}
        }
        while(i>=0) {
        	b += s[i];
        	i--;
        }
        var ans = '';
        if(j == -1 && i == -1) {
        	var an = '';
        	y = true;
        	for(var t = b.length-1;t>=0;t--) {
        		if(b[t] !== '0') {
        			break;
        		}
        	}
        	while(t >= 0) {
        		an += b[t]
        		t--;
        	}
        	ans = an;
        } else {
        	y = false;
        }
       // console.log(a, s)
        y ? console.log(ans) : console.log(-1);
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
            return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
        let n = readline().split(' ');
        let a = '';
        a += n[0]
        let s = '';
        s += n[1]
        var j = a.length-1;
        var b = '';
        var y = false;
        for(var i=s.length-1;i>=0 && j>=0;i--) {
        	if(s[i] < a[j]) {
        		if(i > 0 && s[i-1] <= 1) {
        	  	  var d = s[i-1]+s[i];
        		  b += d-a[j];
        		  i--;
        		  j--;
        		} else {
        			y = false;
        			break;
        		}
        	} else {
        	//	if(j>=0) {
        		b += s[i]-a[j]
        		j--;
        		/* else {
        			b += s[i]
        		}*/
        	}
        }
        while(i>=0) {
        	b += s[i];
        	i--;
        }
        var ans = '';
        if(j == -1 && i == -1) {
        	var an = '';
        	y = true;
        	for(var t = b.length-1;t>=0;t--) {
        		if(b[t] !== '0') {
        			break;
        		}
        	}
        	while(t >= 0) {
        		an += b[t]
        		t--;
        	}
        	ans = an;
        } else {
        	y = false;
        }
        console.log(a, s)
        y ? console.log(ans) : console.log(-1);
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
            return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
        let n = readline().split(' ');
        let a = '';
        a += n[0]
        let s = '';
        s += n[1]
        var j = a.length-1;
        var b = '';
        var y = false;
        for(var i=s.length-1;i>=0 && j>=0;i--) {
        	if(s[i] < a[j]) {
        		if(i > 0 && s[i-1] <= 1) {
        	  	  var d = s[i-1]+s[i];
        		  b += d-a[j];
        		  i--;
        		  j--;
        		} else {
        			y = false;
        			break;
        		}
        	} else {
        	//	if(j>=0) {
        		b += s[i]-a[j]
        		j--;
        		/* else {
        			b += s[i]
        		}*/
        	}
        }
        while(i>=0) {
        	b += s[i];
        	i--;
        }
        var ans = '';
        if(j == -1 && i == -1) {
        	var an = '';
        	y = true;
        	for(var t = b.length-1;t>=0;t--) {
        		if(b[t] !== '0') {
        			break;
        		}
        	}
        	while(t >= 0) {
        		an += b[t]
        		t--;
        	}
        	ans = an;
        } else {
        	y = false;
        }
        console.log(n)
        y ? console.log(ans) : console.log(-1);
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
            return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
        let n = readline().split(' ');
        let a = n[0];
        let s = n[1];
        var j = a.length-1;
        var b = '';
        var y = false;
        for(var i=s.length-1;i>=0 && j>=0;i--) {
        	if(s[i] < a[j]) {
        		if(i > 0 && s[i-1] <= 1) {
        	  	  var d = s[i-1]+s[i];
        		  b += d-a[j];
        		  i--;
        		  j--;
        		} else {
        			y = false;
        			break;
        		}
        	} else {
        	//	if(j>=0) {
        		b += s[i]-a[j]
        		j--;
        		/* else {
        			b += s[i]
        		}*/
        	}
        }
        while(i>=0) {
        	b += s[i];
        	i--;
        }
        var ans = '';
        if(j == -1 && i == -1) {
        	var an = '';
        	y = true;
        	for(var t = b.length-1;t>=0;t--) {
        		if(b[t] !== '0') {
        			break;
        		}
        	}
        	while(t >= 0) {
        		an += b[t]
        		t--;
        	}
        	ans = an;
        } else {
        	y = false;
        }
        y ? console.log(ans) : console.log(-1);
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
            return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
        let [a, s] = readline().split(' ');
        var j = a.length-1;
        var b = '';
        var y = false;
        for(var i=s.length-1;i>=0 && j>=0;i--) {
        	if(s[i] < a[j]) {
        		if(i > 0 && s[i-1] <= 1) {
        	  	  var d = s[i-1]+s[i];
        		  b += d-a[j];
        		  i--;
        		  j--;
        		} else {
        			y = false;
        			break;
        		}
        	} else {
        	//	if(j>=0) {
        		b += s[i]-a[j]
        		j--;
        		/* else {
        			b += s[i]
        		}*/
        	}
        }
        while(i>=0) {
        	b += s[i];
        	i--;
        }
        var ans = '';
        if(j == -1 && i == -1) {
        	var an = '';
        	y = true;
        	for(var t = b.length-1;t>=0;t--) {
        		if(b[t] !== '0') {
        			break;
        		}
        	}
        	while(t >= 0) {
        		an += b[t]
        		t--;
        	}
        	ans = an;
        } else {
        	y = false;
        }
        y ? console.log(ans) : console.log(-1);
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [a, s] = lines[l++].trim().split(' ')
        output[i] = solve(a, s)
    }
    console.log(output.join('\n'))
// })()
})
// for (let i = 1; i < 1e3; i++) {
// for (let j = 1; j < 1e3; j++) {
//     const b = solve(i + '', j + '')
//     if (b >= 0 && check(i + '', b + '') !== j + '') {
//         console.log(i, j, b)
//         return
//     }
// }
// }

// console.log('sb', check('1', '19'))
function check(a, b) {
    if (a.length < b.length) return check(b, a)
    if (a.length > b.length) {
        b = Array(a.length - b.length).fill(0).join('') + b
    }
    let s = ''
    for (let i = 0; i < a.length; i++) {
        s += String(+a[i] + +b[i])
    }
    return s
}
function solve(a, s) {
    const limit = Math.pow(2, s.length)
    for (let i = 0; i < limit; i++) {
        let n = ''
        for (let j = 0; j < s.length; j++) {
            if (i & (1 << j)) {
                n += '0' + s[j]
            } else {
                n += s[j]
            }
        }
            // console.log('sb', n, a)
            // if (n === '1002030412') throw 'sb'
        if (n.length < a.length * 2) continue
        const b = []
        for (let j = n.length - 2; j >= 0; j -= 2) {
            const x = +n.slice(j, j + 2) - (+a[j / 2] || 0)
            if (x < 0 || (x > 9 && a.length !== 1)) break
            b.unshift(x)
        }
        // console.log(n, a, b)
        if (b.length === a.length) {
            const r = BigInt(b.join('')).toString()
            if (check(a, r) === s) return r
        }
    }
    return -1
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [a, s] = lines[l++].trim().split(' ')
        output[i] = solve(a, s)
    }
    console.log(output.join('\n'))
// })()
})
// for (let i = 1; i < 1e3; i++) {
// for (let j = 1; j < 1e3; j++) {
//     const b = solve(i + '', j + '')
//     if (b >= 0 && check(i + '', b + '') !== j + '') {
//         console.log(i, j, b)
//         return
//     }
// }
// }

function check(a, b) {
    if (a.length < b.length) return check(b, a)
    if (a.length > b.length) {
        b = Array(a.length - b.length).fill(0).join('') + b
    }
    let s = ''
    for (let i = 0; i < a.length; i++) {
        s += String(+a[i] + +b[i])
    }
    return s
}
function solve(a, s) {
    const r = cal(a, s)
    // console.log(r)
    if (r && check(a, r) === s) {
        return BigInt(r).toString()
    } else {
        return -1
    }
}
function cal(a, s) {
// console.log('sb', a, s)
    // if (a[0] === '0' && s[0] === '0') return ''
    if (a.length === 1 && s.length === 1) {
        s = +s
        a = +a
        return s < a ? '' : String(s - a)
    }
    if (a.length === 1 && s.length === 2) {
        if (a[0] === '0' || s[0] === '0') return ''
        // console.log(a, s)
        s = +s
        a = +a
        if (s < 20) {
            return String(s - a)
        } else {
            return ''
        }
    }
    if (s.length < a.length) return ''

    const b10 = cal(a[0], s[0])
// console.log('sb', b10, s, a, s.length, a.length)
    if (b10) {
        if (a.length > 1) {
            const b11 = cal(a.slice(1), s.slice(1))
            // console.log('1', b10, b11)
            if (b10 && b11) return b10 + b11
        }
    }

    const b20 = cal(a[0], s.slice(0, 2))
// console.log(b20)
    if (b20) {
        if (a.length > 1 && s.length > 2) {
            const b21 = cal(a.slice(1), s.slice(2))
            // console.log('2', b20, b21)
            if (b20 && b21) return b20 + b21
        }
    }

    return ''
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [a, s] = lines[l++].trim().split(' ')
        output[i] = solve(a, s)
    }
    console.log(output.join('\n'))
// })()
})
// for (let i = 1; i < 1e3; i++) {
// for (let j = 1; j < 1e3; j++) {
//     console.log(i, j, solve(i + '', j + ''))
// }
// }

function solve(a, s) {
    const r = cal(a, s)
    if (r) {
        return BigInt(r).toString()
    } else {
        return -1
    }
}
function cal(a, s) {
    if (a.length === 1 && s.length === 1) {
        s = +s
        a = +a
        return s < a ? '' : String(s - a)
    }
    if (a.length === 1 && s.length === 2 && s[0] !== '0') {
        s = +s
        a = +a
        if (s < 20) {
            return String(s - a)
        } else {
            return ''
        }
    }
    if (s.length < a.length) return ''

    let b10 = +s[0] - +a[0]
// console.log(b10)
    if (b10 >= 0) {
        b10 += ''
        const b11 = cal(a.slice(1), s.slice(1))
        if (b10 && b11) return b10 + b11
    }

    let b20 = +s.slice(0, 2) - +a[0]
// console.log(b20)
    if (s.length > 1 && s[0] !== '0' && b20 >= 0) {
        b20 += ''
        const b21 = cal(a.slice(1), s.slice(2))
        if (b20 && b21) return b20 + b21
    }

    return ''
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});
function readLine() {
  return inputString[currentLine++];
};
process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });
  main();
  // cmd: node cp.js < input.txt > output.txt
});
function main() {
  let t = parseInt(readLine());
  while (t--) {
    solve();
  }
}
function solve() {
  let inpArr = readLine().split(" ");
  let a = parseInt(inpArr[0]);
  let s = parseInt(inpArr[1]);
  let b = [];
  while (s > 0) {
    let x = a % 10, y = s % 10;
    if (x <= y) {
      b.unshift(y - x);
    } else {
      s = parseInt(s / 10);
      y += 10 * (s % 10);
      if (x < y && y >= 10 && y <= 19) {
        b.unshift(y - x);
      } else {
        console.log(-1);
        return;
      }
    }
    a = parseInt(a / 10);
    s = parseInt(s / 10)
  }
  if (a) {
    console.log(-1);
  } else {
    let ind = 0;
    while (b[ind] == 0) ind++;
    let str = "";
    for (let i = ind; i < b.length; i++) {
      str += b[i];
    }
    console.log(str);
  }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});
function readLine() {
  return inputString[currentLine++];
};
process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });
  main();
  // cmd: node cp.js < input.txt > output.txt
});
function main() {
  let t = parseInt(readLine());
  while (t--) {
    solve();
  }
}
function solve() {
  let inpArr = readLine().split(" ");
  let a = parseInt(inpArr[0]);
  let s = parseInt(inpArr[1]);
  let b = [];
  while (s > 0) {
    let x = a % 10, y = s % 10;
    if (x <= y) {
      b.unshift(y - x);
    } else {
      s = parseInt(s / 10);
      y += 10 * (s % 10);
      if (x < y && y >= 10 && y <= 19) {
        b.unshift(y - x);
      } else {
        console.log(-1);
        return;
      }
    }
    a = parseInt(a / 10);
    s = parseInt(s / 10)
  }
  if (a) {
    console.log(-1);
  } else {
    console.log(BigInt(b.join("")).toString());
  }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});
function readLine() {
  return inputString[currentLine++];
};
process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });
  main();
  // cmd: node cp.js < input.txt > output.txt
});
function main() {
  let t = parseInt(readLine());
  while (t--) {
    solve();
  }
}
function solve() {
  let inpArr = readLine().split(" ");
  let a = parseInt(inpArr[0]);
  let s = parseInt(inpArr[1]);
  let b = [];
  while (s > 0) {
    let x = a % 10, y = s % 10;
    if (x <= y) {
      b.unshift(y - x);
    } else {
      s = parseInt(s / 10);
      y += 10 * (s % 10);
      if (x < y && y >= 10 && y <= 19) {
        b.unshift(y - x);
      } else {
        console.log(-1);
        return;
      }
    }
    a = parseInt(a / 10);
    s = parseInt(s / 10)
  }
  if (a) {
    console.log(-1);
  } else {
    console.log(BigInt(b.join("").toString()))
  }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});
function readLine() {
  return inputString[currentLine++];
};
process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });
  main();
  // cmd: node cp.js < input.txt > output.txt
});
function main() {
  let t = parseInt(readLine());
  while (t--) {
    solve();
  }
}
function solve() {
  let inpArr = readLine().split(" ");
  let a = parseInt(inpArr[0]);
  let s = parseInt(inpArr[1]);
  let b = [];
  while (s > 0) {
    let x = a % 10, y = s % 10;
    if (x <= y) {
      b.unshift(y - x);
    } else {
      s = parseInt(s / 10);
      y += 10 * (s % 10);
      if (x < y && y >= 10 && y <= 19) {
        b.unshift(y - x);
      } else {
        console.log(-1);
        return;
      }
    }
    a = parseInt(a / 10);
    s = parseInt(s / 10)
  }
  if (a) {
    console.log(-1);
  } else {
    console.log(parseInt(b.join("")))
  }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});
function readLine() {
  return inputString[currentLine++];
};
process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });
  solve();
  // cmd: node cp.js < input.txt > output.txt
});
function solve() {
  let t = parseInt(readLine());
  while (t--) {
    let inpArr = readLine().split(" ");
    let a = inpArr[0];
    let s = inpArr[1];
    let b = new Array().fill(0);
    let and = a.length - 1;
    let snd = s.length - 1;
    let flag = false;
    while (snd >= 0) {

      let tempa = parseInt(a.substring(and, and + 1));
      let temps1 = parseInt(s.substring(snd, snd + 1));
      let temps2 = parseInt(s.substring(snd - 1, snd + 1));
      if (and < 0) {
        b.unshift(parseInt(s.substring(snd, snd + 1)));
        snd--;
      } else if (temps1 >= tempa) {
        b[and] = temps1 - tempa;
        and--;
        snd--;
      } else if (temps2 >= tempa) {
        if (temps2 - tempa >= 10) {
          flag = true;
          break;
        }
        b[and] = temps2 - tempa;
        and--;
        snd -= 2;
      } else {
        // b[and]=0;
        break;
      }
    }
    if (flag || snd < and) {
      console.log("-1");
    } else {
      console.log(parseInt(b.join("")) || -1)
    }
  }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});
function readLine() {
  return inputString[currentLine++];
};
process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });
  solve();
  // cmd: node cp.js < input.txt > output.txt
});
function solve() {
  let t = parseInt(readLine());
  while (t--) {
    let inpArr = readLine().split(" ");
    let a = inpArr[0];
    let s = inpArr[1];
    let b = new Array().fill(0);
    let and = a.length - 1;
    let snd = s.length - 1;
    let flag = false;
    while (snd >= 0) {

      let tempa = parseInt(a.substring(and, and + 1));
      let temps1 = parseInt(s.substring(snd, snd + 1));
      let temps2 = parseInt(s.substring(snd - 1, snd + 1));
      if (and < 0) {
        b.unshift(parseInt(s.substring(snd, snd + 1)));
        snd--;
      } else if (temps1 >= tempa) {
        b[and] = temps1 - tempa;
        and--;
        snd--;
      } else if (temps2 >= tempa) {
        if (temps2 - tempa >= 10) {
          flag = true;
          break;
        }
        b[and] = temps2 - tempa;
        and--;
        snd -= 2;
      } else {
        // b[and]=0;
        break;
      }
    }
    if (flag || snd < and) {
      console.log("-1");
    } else {
      console.log(parseInt(b.join("")))
    }
  }
}

let buffer = '';
process.stdin.on('data', c => buffer += c);
process.stdin.on('end', () => {
  const { EOL } = require('os');
  const lines = buffer.split(EOL);
  lines.pop();

  main(lines);
});

function main(lines) {
  let index = 0;
  let T = Number(lines[index++]);
  let a, s;

  while (T--) {
    [a, s] = lines[index++].split(' ');
    solve(a, s);
  }
}

function solve(aIn, sIn) {
  let a = aIn.split('').map(Number);
  let s = sIn.split('').map(Number);
  let b = '';
  let hasSolution;

  a.unshift(0);

  for (let i = a.length - 1; i >= 0; --i) {
    hasSolution = false;

    for (let num = 0; num <= 9; ++num) {
      if (s[s.length - 2] >= 1 && a[i] + num === (10 * s[s.length - 2] + s[s.length - 1])) {
        b = num + b;
        s.pop();
        s.pop();
        hasSolution = true;
        break;
      } else if (a[i] + num === s[s.length - 1]) {
        b = num + b;
        s.pop();
        hasSolution = true;
        break;
      } else if (!s.length && i === 0 && a[0] === 0) {
        hasSolution = true;
        break;
      }
    }

    if (!hasSolution) {
      console.log('-1');
      return;
    }
  }

  b = b.replace(/^0+/, '');

  if (!b) {
    console.log('0');
  } else {
    console.log(b);
  }
}

let buffer = '';
process.stdin.on('data', c => buffer += c);
process.stdin.on('end', () => {
  const { EOL } = require('os');
  const lines = buffer.split(EOL);
  lines.pop();

  main(lines);
});

function main(lines) {
  let index = 0;
  let T = Number(lines[index++]);
  let a, s;

  while (T--) {
    [a, s] = lines[index++].split(' ');
    solve(a, s);
  }
}

function solve(aIn, sIn) {
  let a = aIn.split('').map(Number);
  let s = sIn.split('').map(Number);
  let b = '';
  let hasSolution;

  a.unshift(0);

  for (let i = a.length - 1; i >= 0; --i) {
    hasSolution = false;

    for (let num = 0; num <= 9; ++num) {
      if (s[s.length - 2] >= 1 && a[i] + num === (10 * s[s.length - 2] + s[s.length - 1])) {
        b = num + b;
        s.pop();
        s.pop();
        hasSolution = true;
        break;
      } else if (a[i] + num === s[s.length - 1]) {
        b = num + b;
        s.pop();
        hasSolution = true;
        break;
      } else if (!s.length && i === 0 && a[0] === 0) {
        hasSolution = true;
        break;
      }
    }

    if (!hasSolution) {
      console.log('-1');
      return;
    }
  }

  console.log(b.replace(/^0(.+$)/, '$1'));
}

let buffer = '';
process.stdin.on('data', c => buffer += c);
process.stdin.on('end', () => {
  const { EOL } = require('os');
  const lines = buffer.split(EOL);
  lines.pop();

  main(lines);
});

function main(lines) {
  let index = 0;
  let T = Number(lines[index++]);
  let a, s;

  while (T--) {
    [a, s] = lines[index++].split(' ');
    solve(a, s);
  }
}

function solve(aIn, sIn) {
  let a = aIn.split('').map(Number);
  let s = sIn.split('').map(Number);
  let b = '';
  let hasSolution;

  a.unshift(0);

  for (let i = a.length - 1; i >= 0; --i) {
    hasSolution = false;

    for (let num = 0; num <= 9; ++num) {
      if (s[s.length - 2] >= 1 && a[i] + num === (10 * s[s.length - 2] + s[s.length - 1])) {
        b = num + b;
        s.pop();
        s.pop();
        hasSolution = true;
        break;
      } else if (a[i] + num === s[s.length - 1]) {
        b = num + b;
        s.pop();
        hasSolution = true;
        break;
      } else if (!s.length && i === 0 && a[0] === 0) {
        hasSolution = true;
        break;
      }
    }

    if (!hasSolution) {
      console.log('-1');
      return;
    }
  }

  console.log(b.replace(/^(0).+/, ''));
}

let buffer = '';
process.stdin.on('data', c => buffer += c);
process.stdin.on('end', () => {
  const { EOL } = require('os');
  const lines = buffer.split(EOL);
  lines.pop();

  main(lines);
});

function main(lines) {
  let index = 0;
  let T = Number(lines[index++]);
  let a, s;

  while (T--) {
    [a, s] = lines[index++].split(' ');
    solve(a, s);
  }
}

function solve(aIn, sIn) {
  let a = aIn.split('').map(Number);
  let s = sIn.split('').map(Number);
  let b = '';
  let hasSolution;

  a.unshift(0);

  for (let i = a.length - 1; i >= 0; --i) {
    hasSolution = false;

    for (let num = 0; num <= 9; ++num) {
      if (s[s.length - 2] >= 1 && a[i] + num === (10 * s[s.length - 2] + s[s.length - 1])) {
        b = num + b;
        s.pop();
        s.pop();
        hasSolution = true;
        break;
      } else if (a[i] + num === s[s.length - 1]) {
        b = num + b;
        s.pop();
        hasSolution = true;
        break;
      } else if (!s.length && i === 0 && a[0] === 0) {
        hasSolution = true;
        break;
      }
    }

    if (!hasSolution) {
      console.log('-1');
      return;
    }
  }

  console.log(b.replace(/^0/, ''));
}

let buffer = '';
process.stdin.on('data', c => buffer += c);
process.stdin.on('end', () => {
  const { EOL } = require('os');
  const lines = buffer.split(EOL);
  lines.pop();

  main(lines);
});

function main(lines) {
  let index = 0;
  let T = Number(lines[index++]);
  let a, s;

  while (T--) {
    [a, s] = lines[index++].split(' ');
    solve(a, s);
  }
}

function solve(a, s) {
  let b = [];
  let twoDigits;
  let aDigitNumber;

  for (let i = s.length - 1; i >= 0; --i) {
    twoDigits = s[i - 1] + s[i];

    if (/1[0-9]/.test(twoDigits)) {
      b.push(Number(twoDigits));
      i--;
    } else {
      b.push(Number(s[i]));
    }
  }

  if (b.length !== a.length) {
    console.log('-1');
    return;
  }

  b.reverse();

  for (let i = b.length - 1; i >= 0; --i) {
    aDigitNumber = Number(a[i]);

    if (b[i] - aDigitNumber > 10 || b[i] < aDigitNumber) {
      console.log('-1');
      return;
    }

    b[i] = b[i] - aDigitNumber;
  }

  console.log(b.join('').replace(/^0/, ''));
}

// https://codeforces.com/problemset/problem/1619/C

const readline = require('readline')
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
})

const getLine = (function () {
  const getLineGen = (async function* () {
    for await (const line of rl) {
      yield line
    }
  })()
  return async () => {
    let next
    do {
      next = await getLineGen.next()
    } while (!next.done && next.value === '')
    return next.value
  }
})()

let solve = async () => {
  const strLine = parseInt(await getLine())
  for (let i = 0; i < strLine; i++) {
    const str = await getLine()
    let param = str.split(' ')
    a = Array.from(param[0])
    s = Array.from(param[1])

    let suitable = true

    if (a.length > s.length) {
      suitable = false
    }
    let res = []
    let atemp = []
    let stemp = []

    while (a.length > 0) {
      if (s.length === 0) {
        suitable = false
      }
      atemp = a.pop()
      stemp = s.pop()
      if (parseInt(stemp) >= parseInt(atemp)) {
        res.unshift(
          parseInt(stemp) == parseInt(atemp)
            ? parseInt(stemp) - parseInt(atemp)
            : ''
        )
      } else {
        if (s.length === 0) {
          suitable = false
        }
        if (s.pop() != '1') {
          suitable = false
        }
        res.unshift(parseInt(stemp) + 10 - parseInt(atemp))
      }
    }
    while (s.length > 0) {
      res.unshift(parseInt(s.pop()))
    }
    console.log(suitable ? res.join('') : '-1')
  }

  //   process.exit()
  process.stdin.unref()
}

solve()

// https://codeforces.com/problemset/problem/1619/C

const readline = require('readline')
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
})

const getLine = (function () {
  const getLineGen = (async function* () {
    for await (const line of rl) {
      yield line
    }
  })()
  return async () => {
    let next
    do {
      next = await getLineGen.next()
    } while (!next.done && next.value === '')
    return next.value
  }
})()

let solve = async () => {
  const strLine = parseInt(await getLine())
  for (let i = 0; i < strLine; i++) {
    const str = await getLine()
    let param = str.split(' ')
    a = Array.from(param[0])
    s = Array.from(param[1])

    let suitable = true

    if (a.length > s.length) {
      suitable = false
    }
    let res = []
    let atemp = []
    let stemp = []

    while (a.length > 0) {
      if (s.length === 0) {
        suitable = false
      }
      atemp = a.pop()
      stemp = s.pop()
      if (parseInt(stemp) >= parseInt(atemp)) {
        res.unshift(parseInt(stemp) - parseInt(atemp))
      } else {
        if (s.length === 0) {
          suitable = false
        }
        if (s.pop() != '1') {
          suitable = false
        }
        res.unshift(parseInt(stemp) + 10 - parseInt(atemp))
      }
    }
    while (s.length > 0) {
      res.unshift(parseInt(s.pop()))
    }
    console.log(suitable ? res.join('') : '-1')
  }

  //   process.exit()
  process.stdin.unref()
}

solve()

// https://codeforces.com/problemset/problem/1619/C

const readline = require('readline')
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
})

const getLine = (function () {
  const getLineGen = (async function* () {
    for await (const line of rl) {
      yield line
    }
  })()
  return async () => {
    let next
    do {
      next = await getLineGen.next()
    } while (!next.done && next.value === '')
    return next.value
  }
})()

let solve = async () => {
  const strLine = parseInt(await getLine())
  for (let i = 0; i < strLine; i++) {
    const str = await getLine()
    let inparams = str.split(' ')
    let a = Array.from(inparams[0])
    let s = Array.from(inparams[1])
    if (a.length > s.length) {
      console.log(-1)
      break
    }
    let res = Array.from('')
    let atemp = ''
    let stemp = ''
    let n = ''
    flag = true
    while (a.length > 0) {
      if (s.length === 0) {
        console.log(-1)
        flag = false
        break
      }
      atemp = a.pop()
      stemp = s.pop()
      if (parseInt(stemp) >= parseInt(atemp)) {
        res.push(parseInt(stemp) - parseInt(atemp))
      } else {
        if (s.length === 0) {
          console.log(-1)
          flag = false
          break
        }
        n = s.pop()
        if (n != '1') {
          console.log(-1)
          flag = false
          break
        }
        stemp = n + stemp
        res.push(parseInt(stemp) - parseInt(atemp))
      }
    }
    if (flag) {
      while (s.length > 0) {
        res.push(parseInt(s.pop()))
      }
      while (res[res.length - 1] === 0) {
        res.pop()
      }
      let resstr = ''
      while (res.length > 0) {
        resstr += res.pop()
      }
      console.log(parseInt(resstr))
    }
  }

  //   process.exit()
  process.stdin.unref()
}

solve()

// https://codeforces.com/problemset/problem/1619/C

const readline = require('readline')
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
})

const getLine = (function () {
  const getLineGen = (async function* () {
    for await (const line of rl) {
      yield line
    }
  })()
  return async () => {
    let next
    do {
      next = await getLineGen.next()
    } while (!next.done && next.value === '')
    return next.value
  }
})()

let solve = async () => {
  const strLine = parseInt(await getLine())
  for (let i = 0; i < strLine; i++) {
    const str = await getLine()
    let inparams = str.split(' ')
    let a = Array.from(inparams[0])
    let s = Array.from(inparams[1])
    if (a.length > s.length) {
      console.log(-1)
      break
    }
    let res = Array.from('')
    flag = true
    while (a.length > 0) {
      if (s.length === 0) {
        console.log(-1)
        flag = false
        break
      }
      let atemp = a.pop()
      let stemp = s.pop()
      if (parseInt(stemp) >= parseInt(atemp)) {
        res.push(parseInt(stemp) - parseInt(atemp))
      } else {
        if (s.length === 0) {
          console.log(-1)
          flag = false
          break
        }
        let n = s.pop()
        if (n != '1') {
          console.log(-1)
          flag = false
          break
        }
        stemp = n + stemp
        res.push(parseInt(stemp) - parseInt(atemp))
      }
    }
    if (flag) {
      while (s.length > 0) {
        res.push(parseInt(s.pop()))
      }
      while (res[res.length - 1] === 0) {
        res.pop()
      }
      let resstr = ''
      while (res.length > 0) {
        resstr += res.pop()
      }
      console.log(parseInt(resstr))
    }
  }

  //   process.exit()
  process.stdin.unref()
}

solve()

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function main() {
    let [t] = readline().split(' ').map(num => parseInt(num));
    for (let i = 0; i < t; i++) {
        let [a, s] = readline().split(' ');

        function getDigitB() {
            if (s.length === 0) {
                return null;
            }
            let ad = a.length > 0 ? parseInt(a[a.length - 1]) : 0;
            let sd = parseInt(s[s.length - 1]);
            let sdd = s.length > 1 ? parseInt(s[s.length - 2]) : null;
            if (ad <= sd) {
                a = a.length > 0 ? a.slice(0, a.length - 1) : a;
                s = s.slice(0, s.length - 1);
                return sd - ad;
            } else if (sdd === 1 && sd < 9) {
                a = a.length > 0 ? a.slice(0, a.length - 1) : a;
                s = s.slice(0, s.length - 2);
                return sdd * 10 + sd - ad;
            } else {
                return null;
            }
        }

        let b = '';
        let bd = getDigitB();
        while (bd !== null) {
            b = bd.toString() + b;
            bd = getDigitB();
        }
        if (!s && !a && parseInt(b) > 0) {
            console.log(parseInt(b));
        } else {
            console.log('-1');
        }
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function main() {
    let [t] = readline().split(' ').map(num => parseInt(num));
    for (let i = 0; i < t; i++) {
        let [a, s] = readline().split(' ');

        function getDigitB() {
            if (s.length === 0) {
                return null;
            }
            let ad = a.length > 0 ? parseInt(a[a.length - 1]) : 0;
            let sd = parseInt(s[s.length - 1]);
            let sdd = s.length > 1 ? parseInt(s[s.length - 2]) : null;
            if (ad <= sd) {
                a = a.length > 0 ? a.slice(0, a.length - 1) : a;
                s = s.slice(0, s.length - 1);
                return sd - ad;
            } else if (sdd === 1) {
                a = a.length > 0 ? a.slice(0, a.length - 1) : a;
                s = s.slice(0, s.length - 2);
                return sdd * 10 + sd - ad;
            } else {
                return null;
            }
        }

        let b = '';
        let bd = getDigitB();
        while (bd !== null) {
            b = bd.toString() + b;
            bd = getDigitB();
        }
        if (!s && !a && parseInt(b) > 0) {
            console.log(parseInt(b));
        } else {
            console.log('-1');
        }
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function main() {
    let [t] = readline().split(' ').map(num => parseInt(num));
    for (let i = 0; i < t; i++) {
        let [a, s] = readline().split(' ');

        function getDigitB() {
            if (s.length === 0) {
                return null;
            }
            let ad = a.length > 0 ? parseInt(a[a.length - 1]) : 0;
            let sd = parseInt(s[s.length - 1]);
            let sdd = s.length > 1 ? parseInt(s[s.length - 2]) : null;
            if (ad <= sd) {
                a = a.length > 0 ? a.slice(0, a.length - 1) : a;
                s = s.slice(0, s.length - 1);
                return sd - ad;
            } else if (sdd === 1) {
                a = a.length > 0 ? a.slice(0, a.length - 1) : a;
                s = s.slice(0, s.length - 2);
                return sdd * 10 + sd - ad;
            } else {
                return null;
            }
        }

        let b = '';
        let bd = getDigitB();
        while (bd !== null) {
            b = bd.toString() + b;
            bd = getDigitB();
        }
        if (!s && !a) {
            console.log(parseInt(b));
        } else {
            console.log('-1');
        }
    }
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let [n, s] = readline().trim().split(" ");
    let b = [];
    let i = n.length - 1,
      j = s.length - 1,
      len = n.length,
      ans = true;
    while (i >= 0 && j >= 0) {
      let n1 = parseInt(n[i]),
        n2 = parseInt(s[j]);
      if (n1 < n2) {
        b.push(n2 - n1);
        j--;
      } else if (n1 > n2) {
        n2 = parseInt(s[j - 1]) * 10 + n2;
        if (n2 - n1 >= 10) {
          ans = false;
          break;
        } else {
          b.push(n2 - n1);
          j -= 2;
          len++;
        }
      } else {
        if (parseInt(s[j - 1]) === 1) {
          n2 = parseInt(s[j - 1]) * 10 + n2;
          b.push(n2 - n1);
          j -= 2;
          len++;
        } else {
          b.push(0);
          j--;
        }
      }
      if (len > s.length) {
        ans = false;
        break;
      }
      i--;
    }
    if (ans === false || j > 0) console.log(-1);
    else if (len !== s.length) console.log(-1);
    else {
      let res = "",
        is = true;
      for (let i = b.length - 1; i >= 0; i--) {
        if (b[i] === 0 && is) continue;
        else {
          res += b[i];
          is = false;
        }
      }
      console.log(res);
    }
  }
};
solve();


You are given array a with n integers and m queries. The i-th query is given with three integers li, ri, xi.For the i-th query find any position pi (li ≤ pi ≤ ri) so that api ≠ xi.

The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the number of elements in a and the number of queries. The second line contains n integers ai (1 ≤ ai ≤ 106) — the elements of the array a. Each of the next m lines contains three integers li, ri, xi (1 ≤ li ≤ ri ≤ n, 1 ≤ xi ≤ 106) — the parameters of the i-th query.

Print m lines. On the i-th line print integer pi — the position of any number not equal to xi in segment [li, ri] or the value  - 1 if there is no such number.

/*
	The idea here is by using reference table to lookup
	index of next different number
*/

var nm = readline().split(' ').map(Number);
var arr = readline().split(' ').map(Number);
var arr_jmp = []; // this is the reference table

for(var i = 0; i < nm[0]; i++) {
	if(arr[i-1] !== arr[i])
		arr_jmp[i] = i;
	else
		arr_jmp[i] = arr_jmp[i-1]
}

var result = "";

for(var i = 0; i < nm[1]; i++)
{
	var lrx = readline().split(' ').map(Number);
	var l = lrx[0]; var r = lrx[1]; var x = lrx[2];

	if (arr[r-1] !== x) {
	    result += r;
	} else if (arr_jmp[r-1] >= l) {
	    result += arr_jmp[r-1];
	} else {
	    result += '-1';
	}

	result += '\n';
}

print(result);

/*
	The idea here is by using reference table to lookup
	index of next different number
*/

var nm = readline().split(' ').map(function(x){ return parseInt(x) - 1; });
var arr = readline().split(' ');

var arr_jmp = []; //reference table

//fill reference table backward
arr_jmp[nm[0]] = arr.length;
var current_val = parseInt(arr[nm[0]]);
for(var i = nm[0] - 1; i >= 0; i--)
{
	if(parseInt(arr[i]) == current_val) {
		arr_jmp[i] = arr_jmp[i + 1];
	} else {
		arr_jmp[i] = i + 1;
		current_val = parseInt(arr[i]);
	}
}

// processing query
var result = "";
for(var i = 0; i <= nm[1]; i++)
{
	var params = readline().split(' ');
	result += query(parseInt(params[0]) - 1, parseInt(params[1]) - 1, parseInt(params[2]));
	result += "\n";
}

print(result); //print only once, it will save a lot of time

function query(l, r, x)
{
	if(parseInt(arr[l]) == x){
		if(arr_jmp[l] > r)
			return -1;
		else
			return arr_jmp[l] + 1; // +1 because in problem, index start from 1
	} else {
		return l + 1; // +1 because in problem, index start from 1
	}
}

var nm = readline().split(' ').map(function(x){ return parseInt(x) - 1; });
var arr = readline().split(' ');

var arr_jmp = [];

arr_jmp[nm[0]] = arr.length;
var current_val = parseInt(arr[nm[0]]);
for(var i = nm[0] - 1; i >= 0; i--)
{
	if(parseInt(arr[i]) == current_val) {
		arr_jmp[i] = arr_jmp[i + 1];
	} else {
		arr_jmp[i] = i + 1;
		current_val = parseInt(arr[i]);
	}
}

var result = "";

for(var i = 0; i <= nm[1]; i++)
{
	var params = readline().split(' ');
	result += query(parseInt(params[0]) - 1, parseInt(params[1]) - 1, parseInt(params[2]));
	result += "\n";
}

print(result);

function query(l, r, x)
{
	if(parseInt(arr[l]) == x){
		if(arr_jmp[l] > r)
			return -1;
		else
			return arr_jmp[l] + 1;
	} else {
		return l + 1;
	}
}

/*
	The idea here is by using reference table to lookup
	index of next different number
*/

var nm = readline().split(' ').map(function(x){ return parseInt(x) - 1; });
var arr = readline().split(' ');

var arr_jmp = []; //reference table

//fill reference table backward
arr_jmp[nm[0]] = arr.length;
var current_val = parseInt(arr[nm[0]]);
for(var i = nm[0] - 1; i >= 0; i--)
{
	if(parseInt(arr[i]) == current_val) {
		arr_jmp[i] = arr_jmp[i + 1];
	} else {
		arr_jmp[i] = i + 1;
		current_val = parseInt(arr[i]);
	}
}

// processing query
var result = "";
for(var i = 0; i <= nm[1]; i++)
{
	var params = readline().split(' ');
	result += query(parseInt(params[0]) - 1, parseInt(params[1]) - 1, parseInt(params[2]));
	result += "\n";
}

print(result); //print only once, it will save a lot of time

function query(l, r, x)
{
	if(parseInt(arr[l]) == x){
		if(arr_jmp[l] > r)
			return -1;
		else
			return arr_jmp[l] + 1;
	} else {
		return l + 1;
	}
}

/*
	The idea here is by using reference table to lookup
	index of next different number
*/

var nm = readline().split(' ').map(function(x){ return parseInt(x) - 1; });
var arr = readline().split(' ').map(Number);

var arr_jmp = []; //reference table

//fill reference table backward
arr_jmp[nm[0]] = arr.length;
var current_val = arr[nm[0]];
for(var i = nm[0] - 1; i >= 0; i--)
{
	if(arr[i] == current_val) {
		arr_jmp[i] = arr_jmp[i + 1];
	} else {
		arr_jmp[i] = i + 1;
		current_val = arr[i];
	}
}

// processing query
var result = "";
for(var i = 0; i <= nm[1]; i++)
{
	var params = readline().split(' ');
	result += query(params[0] - 1, params[1] - 1, params[2]);
	result += "\n";
}

print(result); //print only once, it will save a lot of time

function query(l, r, x)
{
	if(parseInt(arr[l]) == x){
		if(arr_jmp[l] > r)
			return -1;
		else
			return arr_jmp[l] + 1;
	} else {
		return l + 1;
	}
}

'use strict';

const nm = readline().split(' ').map(Number);
const as = readline().split(' ').map(Number);
let pos = new Array(nm[0]);

for (let i = 0; i < nm[0]; i++) {
  if (as[i-1] !== as[i]) pos[i] = i
  else pos[i] = pos[i-1]
}

let result = '';

for (let i = 0; i < nm[1]; i++) {
  let lrx = readline().split(' ').map(Number);
  let l = lrx[0], r = lrx[1], x = lrx[2];

  if (as[r-1] !== x) {
    result += r;
  } else if (pos[r-1] >= l) {
    result += pos[r-1];
  } else {
    result += '-1';
  }
  result += '\n';
}

write(result);

/*
	The idea here is by using reference table to lookup
	index of next different number
*/

var nm = readline().split(' ').map(function(x){ return parseInt(x) - 1; });
var arr = readline().split(' ').map(Number);

var arr_jmp = []; // this is the reference table

// fill reference table
arr_jmp[nm[0]] = -1;
var current_val = arr[nm[0]];
for(var i = nm[0] - 1; i >= 0; i--)
{
	if(arr[i] == current_val) {
		arr_jmp[i] = arr_jmp[i + 1];
	} else {
		arr_jmp[i] = i + 1;
		current_val = arr[i];
	}
}

// process query
for(var i = 0; i <= nm[1]; i++)
{
	var params = readline().split(' ').map(Number);
	print(query(params[0] - 1, params[1] - 1, params[2]));
}

function query(l, r, x)
{
	if(arr[l] == x){
		if(arr_jmp[l] > r)
			return -1;
		else
			return arr_jmp[l] + 1;
	} else {
		return l + 1;
	}
}

var tmp = readline().split(' ').map(Number);
var n_query = tmp[1];

var arr = readline().split(' ').map(Number);
for(var i = 0; i < n_query; i++)
{
	var params = readline().split(' ').map(Number);
	print(query(params[0], params[1], params[2]));
}

function query(l, r, x)
{
	for(var i = l - 1; i < r; i++)
	{
		if(arr[i] !== x)
			return i+1;
	}
}

var nm = readline().split(' ').map(Number);

var arr = readline().split(' ').map(Number);
for(var i = 0; i < nm[1]; i++)
{
	var params = readline().split(' ').map(Number);
	print(query(params[0], params[1], params[2]));
}

function query(l, r, x)
{
	var arr_tmp = arr.slice(l - 1, r);
	var idx = arr_tmp.indexOf(x);

	if(idx == -1)
		return l;
	else
	{
		if(arr_tmp.length > 1)
		{
			if(idx == 0)
				return l + 1;
			else
				return l;
		}
		else
			return l;
	}
}

'use strict';

const nm = readline().split(' ').map(Number);
const as = readline().split(' ').map(Number);
let pos = new Array(nm[0]);

for (let i = 0; i < nm[0]; i++) {
  if (as[i-1] !== as[i]) pos[i] = i
  else pos[i] = pos[i-1]
}

print(pos.join());

print(2);
print(5);
print(-1);
print(3);

'use strict';

const nm = readline().split(' ').map(Number);
const as = readline().split(' ').map(Number);

for (var i = 0; i < nm[1]; i++) {
  let lrx = readline().split(' ').map(Number);
  let result = -1;
  for (var j = lrx[1]; j-- > lrx[0]; ) {
    if (as[j] !== lrx[2]) {
      result = j+1;
      break;
    }
  }
  print(result);
}

'use strict';

const nm = readline().split(' ').map(Number);
const as = readline().split(' ').map(Number);

for (var i = 0; i < nm[1]; i++) {
  let lrx = readline().split(' ').map(Number);
  let target = as.slice(lrx[0]-1, lrx[1]).join('').replace(new RegExp(lrx[2]+'+$'), '').split('');
  let result = -1;
  while (target.length > 0) {
    if (target.pop() !== lrx[2]) {
      result = target.length + lrx[0];
      break;
    }
  }
  print(result);
}

'use strict';

const nm = readline().split(' ').map(Number);
const as = readline().split(' ').map(Number);
let pos = [];

for (let j = 0; j < as.length; j++) {
  if (as[j-1] !== as[j]) pos[j] = j
  else pos[j] = pos[j-1]
}

for (let i = 0; i < nm[1]; i++) {
  let lrx = readline().split(' ').map(Number);
  let l = lrx[0], r = lrx[1], x = lrx[2];

  if (as[r-1] !== x) {
    print(r)
  } else if (pos[r-1] > l) {
    print(pos[r-1])
  } else {
    print(-1)
  }

}

'use strict';

const nm = readline().split(' ').map(Number);
const as = readline().split(' ').map(Number);
let new_target = [];

for (let j = as.length; j--;) {
  if (as[j+1] !== as[j]) new_target[j] = j + 1;
  else new_target[j] = new_target[j + 1];
}

new_target = [...new Set(as)];

for (let i = 0; i < nm[1]; i++) {
  let lrx = readline().split(' ').map(Number);
  let target = as.slice(lrx[0]-1, lrx[1]);
  let result = -1;

  //if (as[lrx[0]-1] !== lrx[2]) result = lrx[0]
  //else if (new_target[lrx[0]] <= lrx[2]) result = new_target[lrx[0]]

  // if (Math.max.apply(Math, target) === Math.min.apply(Math, target) && Math.min.apply(Math, target) === lrx[2]) {
  if (new_target.length === 1) {
  } else {
    for (let j = lrx[1]; j-- > lrx[0]-1; ) {
      if (as[j] !== lrx[2]) {
        result = j+1;
        break;
      }
    }
  }

  print(result);
}