function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn, init) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);
  if (b < a) return [];
  let arr = Array(b - a + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i++) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn ? fn(v) : v).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}

function gcd(a, b) {
  while (b) [a, b] = [b, a % b];
  return a;
}
function mul(a, b, m) {
  return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m
}
function pow(a, n, m) {
  let r = 1;
  while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]
  return r;
}
let MOD = 998244353
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);
  return (u + MOD) % MOD;
}
// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));
// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));
// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });
// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);

// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1
// for (i = pos; i; i -= i & -i) ans += fen[i];

// let p = [2];
// for (let i = 3; i < 1e5; i += 2) {
//   let j, x = Math.sqrt(i);
//   for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;
//   if (i % p[j] != 0) p.push(i);
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let n = $(), a = $(n), m = { 0: 1 }, s = 0, res = 0;
  For(n, i => {
    if (m[s + a[i]]) { res++; s = a[i]; m = { [s]: 1, 0: 1 } }
    else m[s += a[i]] = 1;
  })
  log(res)
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  const len = +readLine();
  const arr = readLine()
    .split(" ")
    .map((n) => parseInt(n));

  let [count, cSum, map] = [0, 0, {}];

  for (let i = 0; i < len; i++) {
    cSum += arr[i];
    if (!cSum || map[cSum]) {
      map = {};
      count++;
      cSum = arr[i];
    }
    map[cSum] = true;
  }

  console.log(count);
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n↑入力 ↓出力');
  Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  var list = nextIntArray();
  var output = 0;
  var now = 0;
  var used = new Set([0]);
  for(var i = 0; i < N; i++){
    now += list[i];
    if(used.has(now)){
      output++;
      used = new Set([0]);
      now = list[i];
    }
    used.add(now);
  }
  myout(output);
}

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn, init) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);
  if (b < a) return [];
  let arr = Array(b - a + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i++) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn ? fn(v) : v).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);
// let MOD = 998244353n;
// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);
// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);
// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;
// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;
// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1

// let p = [2, 3, 5];
// for (let i = 6; i < 1e5; i += 6) {
//   let j, x = i + 1;
//   for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;
//   if (x % p[j] != 0) p.push(x);
//   x = i + 5;
//   for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;
//   if (x % p[j] != 0) p.push(x);
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let n = $(), a = $(n), m = { 0: 1 }, s = 0, res = 0;
  For(n, i => {
    if (m[s + a[i]]) { res++; s = a[i]; m = { [s]: 1, 0: 1 } }
    else m[s += a[i]] = 1;
  })
  log(res)
}

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();
    });

    D();
});

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

function pi(a) {
    return parseInt(a);
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = pi(a[i]);

    return a;
}

function D(){
    let n = pi(readline());
    let a = ti(readline().split(' '));
    let map = {};
    map[0] = 1;
    let sum = 0;
    let count = 0;
    for(let i = 0; i < a.length; i++){
        sum += a[i];
        if(map[sum] !== undefined){
            count += 1;
            map = {};
            map[0] = 1;
            sum = a[i];
        }

        map[sum] = 1;
    }

    console.log(count);
}

'use strict'
function mlt() { return readline().split(' ').map(x => parseInt(x)); }
function inp() { return parseInt(readline()) }
function solv() {
    var x = inp();
    var s = mlt();
    var st = new Set()
    var pf = 0
    st.add(pf)
    var res = 0
    for (var n = 0; n < x; n++) {
        pf += s[n];
        if (!st.has(pf)) {
            st.add(pf)
        }
        else {
            st.add(pf + 1e10);
            st.add(pf + 1e10 + s[n]);
            res++;
            pf = 1e10 + s[n] + pf;
        }
    }
    print(res)
}
var tc = 1;
// tc= parseInt(readline())
while (tc--) solv()

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();
    });

    D();
});

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

function pi(a) {
    return parseInt(a);
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = pi(a[i]);

    return a;
}

function D(){
    let n = pi(readline());
    let a = ti(readline().split(' '));
    let map = {};
    let sum = 0;
    let count = 0;
    let arr = new Array(n);
    let f = 0;
    for(let i = 0; i < a.length; i++){
        sum += a[i];
        if(map[sum] !== undefined){
            count += 1;
        }else{
            map[sum] = i;
        }
        if(sum === 0)
            f = 1;
        arr[i] = sum;
    }

    console.log(arr);
    console.log(f === 0 ? count : count + 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();
    });

    D();
});

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

function pi(a) {
    return parseInt(a);
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = pi(a[i]);

    return a;
}

function D(){
    let n = pi(readline());
    let a = ti(readline().split(' '));
    let map = {};
    let sum = 0;
    let count = 0;
    //let arr = new Array(n);
    let f = 0;
    for(let i = 0; i < a.length; i++){
        sum += a[i];
        if(map[sum] !== undefined){
            count += 1;
        }else{
            map[sum] = i;
        }
        if(sum === 0)
            f = 1;
    }

    //console.log(arr);
    console.log(f === 0 ? count : count + 1);
}


// 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;
});
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());
  }
}

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');
}

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()

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();

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");

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();


/*
	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
	}
}

'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(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);

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;
	}
}

/*
	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);
}