Tanya is learning how to add numbers, but so far she is not doing it correctly. She is adding two numbers $a$ and $b$ using the following algorithm:

If one of the numbers is shorter than the other, Tanya adds leading zeros so that the numbers are the same length.

The numbers are processed from right to left (that is, from the least significant digits to the most significant).

In the first step, she adds the last digit of $a$ to the last digit of $b$ and writes their sum in the answer.

At each next step, she performs the same operation on each pair of digits in the same place and writes the result to the left side of the answer.

For example, the numbers $a = 17236$ and $b = 3465$ Tanya adds up as follows:

$$ \large{ \begin{array}{r} + \begin{array}{r} 17236\\ 03465\\ \end{array} \\ \hline \begin{array}{r} 1106911 \end{array} \end{array}} $$

calculates the sum of $6 + 5 = 11$ and writes $11$ in the answer.

calculates the sum of $3 + 6 = 9$ and writes the result to the left side of the answer to get $911$.

calculates the sum of $2 + 4 = 6$ and writes the result to the left side of the answer to get $6911$.

calculates the sum of $7 + 3 = 10$, and writes the result to the left side of the answer to get $106911$.

calculates the sum of $1 + 0 = 1$ and writes the result to the left side of the answer and get $1106911$.

As a result, she gets $1106911$.

You are given two positive integers $a$ and $s$. Find the number $b$ such that by adding $a$ and $b$ as described above, Tanya will get $s$. Or determine that no suitable $b$ exists.


-----Input-----

The first line of input data contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases.

Each test case consists of a single line containing two positive integers $a$ and $s$ ($1 \le a \lt s \le 10^{18}$) separated by a space.


-----Output-----

For each test case print the answer on a separate line.

If the solution exists, print a single positive integer $b$. The answer must be written without leading zeros. If multiple answers exist, print any of them.

If no suitable number $b$ exists, output -1.


-----Examples-----

Input
6
17236 1106911
1 5
108 112
12345 1023412
1 11
1 20
Output
3465
4
-1
90007
10
-1


-----Note-----

The first test case is explained in the main part of the statement.

In the third test case, we cannot choose $b$ that satisfies the problem statement.

Source: codeforces | Difficulty: EASY
Tags: Implementation


Solutions:
for _ in range(int(input())):
	(a, s) = map(int, input().split())
	b = ''
	while s and a:
		if a > s:
			b = -1
			break
		(s1, s2, a1) = (s % 10, s % 100, a % 10)
		if s1 >= a1:
			b = str(s1 - a1) + b
			s //= 10
		elif s2 > a1 and s2 - a1 < 10:
			b = str(s2 - a1) + b
			s //= 100
		else:
			b = -1
			break
		a //= 10
	if b != -1:
		print(int(str(s) + b))
	else:
		print(b)


def ss(a, b, bi):
	if bi != 1:
		b = b[-bi:-bi + 1]
	else:
		b = b[-bi]
	if not b:
		return int(a)
	return int(a) - int(b)

def doit():
	(a, s) = input().strip().split()
	(p, q) = (len(a), len(s))
	(ai, si) = (1, 1)
	b = ''
	while si <= q:
		t = ss(s[-si], a, ai)
		if t >= 0:
			b += str(t)
			si += 1
		elif si < q:
			t = ss(s[-si - 1:][0:2], a, ai)
			if len(str(t)) > 1:
				print(-1)
				return 0
			else:
				b += str(t)
				si += 2
		else:
			print(-1)
			return 0
		ai += 1
	if ai > p:
		print(b[::-1].lstrip('0'))
	else:
		print(-1)
t = int(input())
for _ in range(t):
	doit()


t = int(input())
for i in range(0, t):
	l = list(map(int, input().split()))
	a = l[0]
	s = l[1]
	s1 = []
	a1 = []
	while s > 0:
		s1.append(s % 10)
		s = s // 10
	while a > 0:
		a1.append(a % 10)
		a = a // 10
	n = 0
	i = 0
	j = 0
	k = 0
	p = 0
	c1 = len(s1)
	c2 = len(a1)
	while j < len(s1):
		if i == len(a1):
			d = s1[j]
			n += d * 10 ** p
			j += 1
			p += 1
		elif i <= len(a1) - 1:
			d = s1[j] - a1[i]
			if d >= 0:
				n += d * 10 ** i
				i += 1
				j += 1
				p = i
				c1 -= 1
				c2 -= 1
			elif d < 0:
				if j < len(s1) - 1 and s1[j + 1] == 1:
					d = 10 + s1[j] - a1[i]
					n += d * 10 ** i
					i += 1
					j += 2
					p = i
					c1 -= 2
					c2 -= 1
				else:
					k = 1
					i += 1
					p = i
					j += 1
	if c2 > c1:
		k = 1
	if k == 1:
		print(-1)
	else:
		print(n)


from sys import stdin
from collections import deque, defaultdict
from heapq import heappush, heappop
t = int(stdin.buffer.readline())
for _ in range(t):
	(a, s) = map(int, stdin.readline().split())
	ans = ''
	n = len(str(s)) - 1
	ns = str(s)
	for i in str(a)[::-1]:
		if not ns[-1:].strip():
			break
		if int(i) <= int(ns[-1]):
			ans = str(abs(int(ns[-1]) - int(i))).strip() + ans
			ns = ns[:-1]
		else:
			if not ns[-2:].strip:
				break
			ans = str(abs(int(ns[-2:]) - int(i))).strip() + ans
			ns = ns[:-2]
	if ns.strip():
		ans = ns + ans
	nans = ''
	na = str(a)
	if len(ans) > len(na):
		na = '0' * (len(ans) - len(na)) + na
	elif len(na) > len(ans):
		ans = '0' * (len(na) - len(ans)) + ans
	for i in range(len(ans)):
		nans += str(int(ans[i]) + int(na[i]))
	if nans == str(s):
		print(int(ans))
	else:
		print(-1)


for _ in range(int(input())):
	(a, s) = input().split()
	b = ''
	q = 0
	(i, j) = (-1, -1)
	if len(s) < len(a):
		print(-1)
		break
	while i != -len(a) - 1 and j != -len(s) - 1:
		if not q:
			if int(a[i]) < int(s[j]):
				b += str(int(s[j]) - int(a[i]))
				i -= 1
				j -= 1
			elif int(a[i]) == int(s[j]):
				b += '0'
				i -= 1
				j -= 1
			else:
				b += str(10 + int(s[j]) - int(a[i]))
				q = 1
				j -= 1
		else:
			if s[j] == '1':
				q = 0
			else:
				print(-1)
				break
			i -= 1
			j -= 1
		if i != -len(a) - 1 and j == -len(s) - 1:
			print(-1)
			break
	else:
		if j != -len(s) - 1:
			b += s[:j + 1][::-1]
		print(int(b[::-1]))


i = int
m = -1
for s in [*open(0)][1:]:
	(a, s) = s.split()
	l = [(a.zfill(19), s, '')]
	for (a, s, b) in l:
		if s:
			if 0 <= (c := (i(s[m]) - i(a[m]))) <= 9:
				l += ((a[:m], s[:m], str(c) + b),)
			if s[1:] and c < (d := (c + i(s[-2]) * 10)) <= 9:
				l += ((a[:m], s[:-2], str(d) + b),)
	print(i(a) and m or i(b))


import sys

def wrong_addition(a, s):
	b = ''
	len_a = len(a)
	len_s = len(s)
	i = len_a - 1
	ls = len_s - 1
	while True:
		if ls < 0:
			if i < 0:
				break
			return -1
		if i < 0:
			d_in_a = 0
		else:
			d_in_a = int(a[i])
		i -= 1
		d_in_s = int(s[ls])
		if d_in_a <= d_in_s:
			b = str(d_in_s - d_in_a) + b
			ls -= 1
		else:
			ls -= 1
			if ls < 0:
				return -1
			d_in_s = int(s[ls:ls + 2])
			d_in_b = d_in_s - d_in_a
			if d_in_b > 9:
				return -1
			if d_in_b < 0:
				return -1
			b = str(d_in_b) + b
			ls -= 1
	b = int(b)
	return b
for _ in range(int(input())):
	(a, s) = input().split()
	sys.stdout.write(f'{wrong_addition(a, s)}\n')


from sys import stdin, stdout, setrecursionlimit
from math import gcd, sqrt, factorial, pi, inf
from collections import deque, defaultdict
from bisect import bisect, bisect_left
from time import time
from itertools import permutations as per
from heapq import heapify, heappush, heappop, heappushpop
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\r\n')
L = lambda : list(R())
P = lambda x: stdout.write(str(x) + '\n')
lcm = lambda x, y: x * y // gcd(x, y)
nCr = lambda x, y: f[x] * inv(f[y] * f[x - y] % N) % N
inv = lambda x: pow(x, N - 2, N)
sumx = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
for _ in range(I()):
	(x, y) = [list(i) for i in S().split()]
	ans = ''
	for i in range(len(x)):
		if x and (not y):
			ans = -1
			break
		if x[-1] > y[-1]:
			if len(y) == 1 or y[-2] != '1':
				ans = -1
				break
			else:
				ans += str(10 + int(y[-1]) - int(x[-1]))
				x.pop()
				y.pop()
				y.pop()
		else:
			ans += str(int(y[-1]) - int(x[-1]))
			x.pop()
			y.pop()
	if ans != -1 and y and (not x):
		ans += ''.join(y[::-1])
	print(int(ans[::-1]) if ans != -1 else ans)


def find(a, s):
	ans = ''
	i = len(a) - 1
	j = len(s) - 1
	while i > -1 and j > -1:
		if s[j] >= a[i]:
			ans += str(int(s[j]) - int(a[i]))
			j -= 1
			i -= 1
		elif j < 1:
			return -1
		else:
			y = int(s[j - 1:j + 1])
			if y > 9 and y < 19:
				ans += str(y - int(a[i]))
			else:
				return -1
			j -= 2
			i -= 1
	if j == -1 and i > -1:
		return -1
	elif j > -1 and i == -1:
		ans = s[:j + 1] + ans[::-1]
	else:
		ans = ans[::-1]
	return int(ans)
res = []
r = int(input())
for i in range(r):
	[a, s] = input().split()
	res.append(find(a, s))
for i in res:
	print(i)


for _ in range(int(input())):
	(a, s) = map(str, input().split())
	ans = ''
	a = a.rjust(30, '0')
	s = s.rjust(30, '0')
	j = 29
	for i in range(29, -1, -1):
		if s[j] < a[i]:
			if int(s[j - 1:j + 1]) - int(a[i]) > 9 or int(s[j - 1:j + 1]) - int(a[i]) < 0:
				print(-1)
				break
			ans += str(int(s[j - 1:j + 1]) - int(a[i]))
			j -= 2
		else:
			if int(s[j]) - int(a[i]) > 9 or int(s[j]) - int(a[i]) < 0:
				print(-1)
				break
			ans += str(int(s[j]) - int(a[i]))
			j -= 1
	else:
		print(int(ans[::-1][7:]))


for _ in range(int(input())):
	(a, s) = map(lambda x: ''.join(reversed(x)), input().split())
	b = ''
	n = len(a)
	ns = len(s)
	i = j = 0
	while j < ns:
		if i >= n:
			b += s[j]
		elif a[i] <= s[j]:
			t = int(s[j]) - int(a[i])
			if t <= 9:
				b += str(t)
			else:
				print(-1)
				break
		else:
			j += 1
			if j >= ns:
				print(-1)
				break
			t = int(s[j] + s[j - 1]) - int(a[i])
			if 0 <= t <= 9:
				b += str(t)
			else:
				print(-1)
				break
		i += 1
		j += 1
	else:
		if i >= n:
			print(int(b[::-1]))
		else:
			print(-1)


t = int(input())
for _ in range(t):
	(a, s) = map(int, input().split())
	b = 0
	i = 1
	while a > 0:
		lstdgt_a = a % 10
		lstdgt_s = s % 10
		if lstdgt_s < lstdgt_a:
			s = s // 10
			lstdgt_s += 10 * (s % 10)
		if lstdgt_s - lstdgt_a > 9 or lstdgt_s < lstdgt_a:
			b = -1
			break
		b += (lstdgt_s - lstdgt_a) * i
		i *= 10
		a = a // 10
		s = s // 10
	if b != -1:
		b += s * i
	print(b)


for _ in range(int(input())):
	(stra, strs) = input().split()
	(i, j) = (len(stra) - 1, len(strs) - 1)
	output = ''
	flag = False
	while i >= 0 and j >= 0:
		if int(stra[i]) <= int(strs[j]):
			output += str(int(strs[j]) - int(stra[i]))
			i -= 1
			j -= 1
		else:
			j -= 1
			if j < 0:
				flag = True
				break
			x = int(stra[i])
			y = int(strs[j:j + 2])
			if y - x > 9 or y - x < 0:
				flag = True
				break
			else:
				output += str(y - x)
				j -= 1
				i -= 1
	output = output[::-1]
	output = strs[0:j + 1] + output
	if flag or i > -1:
		print('-1')
	else:
		print(int(output))


for s in [*open(0)][1:]:
	(a, s) = s.split()
	a = int(a)
	b = 0
	k = 1
	while s and -1 < (c := (int(s[(m := (-1))]) - a % 10)) <= 9 or (s[1:] and -1 < (c := (c + int(s[(m := (m - 1))]) * 10)) <= 9):
		a //= 10
		s = s[:m]
		b = k * c + b
		k *= 10
	print((b, -1)[a > 0])


i = int
m = -1
for s in [*open(0)][1:]:
	(a, s) = s.split()
	l = [[a.zfill(len(s)), s, '']]
	r = m
	for (a, s, b) in l:
		if s:
			if 0 <= (c := (i(s[m]) - i(a[m]))) <= 9:
				l += ([a[:m], s[:m], str(c) + b],)
			if s[1:] and c < (d := (c + i(s[-2]) * 10)) <= 9:
				l += ([a[:m], s[:-2], str(d) + b],)
		elif '01' > a:
			r = b
			break
	print(i(r))


def solve():
	[a, s] = input().split(' ')
	i = len(a) - 1
	j = len(s) - 1
	b = ''
	while i >= 0 and j >= 0:
		x = int(a[i])
		y = int(s[j])
		if x <= y:
			b = str(y - x) + b
		if x > y:
			if j - 1 < 0:
				return -1
			y = 10 * int(s[j - 1]) + int(s[j])
			j -= 1
			if y >= 10 and y <= 18:
				b = str(y - x) + b
			else:
				return -1
		j -= 1
		i -= 1
	if j < 0 and i >= 0:
		return -1
	if i < 0 and j >= 0:
		return s[0:j + 1] + b
	return b.lstrip('0')
t = int(input())
for _ in range(t):
	print(solve())


import random
t = int(input())
for test in range(t):
	(x, a) = input().split(' ')
	ans = ''
	counter = len(a) - 1
	flag = False
	for i in range(len(x) - 1, -1, -1):
		if int(a[counter]) >= int(x[i]):
			if counter < 0:
				flag = True
				print(-1)
				break
			ans += str(int(a[counter]) - int(x[i]))
		elif int(a[counter]) < int(x[i]):
			if counter <= 0:
				flag = True
				print(-1)
				break
			if int(a[counter - 1:counter + 1]) - int(x[i]) > 9 or int(a[counter - 1:counter + 1]) - int(x[i]) < 0:
				print(-1)
				flag = True
				break
			ans += str(int(a[counter - 1:counter + 1]) - int(x[i]))
			counter -= 1
		counter -= 1
	if flag == False:
		if counter >= 0:
			ans += a[counter::-1]
		if int(ans[::-1]) > int(a):
			print(-1)
		else:
			print(int(ans[::-1]))


from sys import stdin, stdout
rd = lambda : list(map(int, stdin.readline().split()))
rds = lambda : stdin.readline().rstrip()
ii = lambda : int(stdin.readline())
INF = 1 << 62
mod = 10 ** 9 + 7

def solve(a, s):
	sp = '0' * abs(len(a) - len(s))
	if len(a) < len(s):
		a = sp + a
	else:
		s = sp + s
	i = len(a) - 1
	j = len(s) - 1
	b = []
	ok = True
	while i >= 0 and j >= 0:
		an = int(a[i])
		sn1 = int(s[j])
		if sn1 >= an:
			b.append(sn1 - an)
			i -= 1
			j -= 1
		elif j == 0:
			ok = False
			break
		else:
			sn1 = int(s[j - 1:j + 1])
			if sn1 > 18:
				ok = False
				break
			d = sn1 - an
			if d > 9 or d < 0:
				ok = False
				break
			b.append(d)
			i -= 1
			j -= 2
	if j >= 0:
		ok = False
	if i >= 0 and sum((int(a[p]) for p in range(0, i + 1))) != 0:
		ok = False
	if not ok:
		return -1
	else:
		b = b[::-1]
		return int(''.join(map(str, b)))
for _ in range(ii()):
	(a, s) = rds().split(' ')
	print(solve(a, s))


def solve(a: int, s: int):
	result = []
	while s > a >= 0:
		mod_a = a % 10
		mod_s = s % 10
		if mod_s < mod_a:
			mod_ss = s % 100
			if mod_ss // 10 != 1:
				print(-1)
				return
			result.append(mod_ss - mod_a)
			s = s // 100
		else:
			result.append(mod_s - mod_a)
			s = s // 10
		a = a // 10
	if s < a:
		print(-1)
	else:
		result.append(s - a)
		print(int(''.join(map(str, reversed(result)))))
n = int(input())
values = [list(map(int, input().split())) for _ in range(n)]
for v in values:
	solve(*v)


for _ in range(int(input())):
	(a, s) = input().split()
	n = len(a)
	m = len(s)
	i = n - 1
	j = m - 1
	b = ''
	f = True
	while i >= 0 and j >= 0:
		if s[j] >= a[i]:
			b = str(int(s[j]) - int(a[i])) + b
			j -= 1
			i -= 1
		else:
			if j - 1 < 0:
				f = False
				break
			if not 9 < int(s[j - 1:j + 1]) < 19:
				f = False
				break
			b = str(int(s[j - 1:j + 1]) - int(a[i])) + b
			j -= 2
			i -= 1
	if not f or i >= 0:
		print(-1)
	else:
		if j >= 0:
			b = s[0:j + 1] + b
		print(b.lstrip('0'))


def solve():
	(a, s) = input().split()
	(i, j) = (len(a) - 1, len(s) - 1)
	ans = ''
	while i >= 0 and j >= 0:
		small = int(a[i])
		big = 0
		if a[i] <= s[j]:
			big = int(s[j])
		elif j > 0:
			big = int(s[j - 1:j + 1])
			j -= 1
		g = big - small
		if g > 9 or g < 0:
			return -1
		ans = str(g) + ans
		i -= 1
		j -= 1
	ans = s[:j + 1] + ans
	return int(ans) if i < 0 else -1
t = int(input())
while t:
	print(solve())
	t -= 1


def fun(a, s):
	a = str(a)
	s = str(s)
	(i, j) = (len(a) - 1, len(s) - 1)
	ans = ''
	while i >= 0 and j >= 0:
		if int(a[i]) <= int(s[j]):
			ans = str(int(s[j]) - int(a[i])) + ans
			j -= 1
		else:
			if j == 0:
				return -1
			t = int(s[j - 1:j + 1]) - int(a[i])
			if t > 9 or t < 0:
				return -1
			ans = str(t) + ans
			j -= 2
		i -= 1
	ans = s[:j + 1] + ans
	if j < 0 and i >= 0:
		return -1
	return int(ans)
for _ in range(int(input())):
	(a, s) = map(int, input().split())
	print(fun(a, s))


def ans(a, s):
	b = ''
	idx = len(s) - 1
	for val in reversed(a):
		sum_val = s[idx:idx + 1]
		if sum_val < val or idx < 0:
			if idx <= 0:
				return -1
			idx = idx - 1
			sum_val = s[idx:idx + 2]
			if int(sum_val) < int(val):
				return -1
			s = s[:-1]
		if int(sum_val) - int(val) >= 10:
			return -1
		b = str(int(sum_val) - int(val)) + b
		idx = idx - 1
	b = s[:idx + 1] + b
	return b.lstrip('0')
for _ in range(int(input())):
	(a, s) = str(input()).split(' ')
	print(ans(a, s))


for _ in range(int(input())):
	(a, s) = input().split()
	a = a[::-1]
	s = s[::-1]
	i = 0
	j = 0
	f = 1
	ans = ''
	while j < len(s):
		if i == len(a):
			ans += s[j]
			j += 1
			continue
		if len(a) - i > len(s) - j:
			f = 0
			break
		if int(s[j]) - int(a[i]) < 0:
			if j < len(s) - 1:
				j += 1
				if int(s[j]) == 1:
					ans += str(int(s[j]) * 10 + int(s[j - 1]) - int(a[i]))
				else:
					f = 0
					break
			else:
				f = 0
				break
		else:
			ans += str(int(s[j]) - int(a[i]))
		i += 1
		j += 1
	if f == 0:
		print(-1)
	else:
		print(int(ans[::-1]))


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_ls():
	return list(map(int, sys.stdin.readline().strip().split()))

def solve():
	(a, s) = get_ints()
	ls = []
	while s:
		x = a % 10
		y = s % 10
		if x <= y:
			ls.append(y - x)
		else:
			s //= 10
			y += 10 * (s % 10)
			if x < y and y >= 10 and (y < 19):
				ls.append(y - x)
			else:
				print(-1)
				return
		s //= 10
		a //= 10
	if a:
		print(-1)
	else:
		while True:
			if ls[-1] == 0:
				ls.pop()
			else:
				break
		ls.reverse()
		print(''.join([str(i) for i in ls]))

def main():
	for _ in range(int(input())):
		solve()
main()


def wrongadd(a, b):
	a = int(a)
	a = str(a)
	b = str(b)
	n = max(len(a), len(b))
	a = a.zfill(n)
	b = b.zfill(n)
	c = []
	for i in range(n - 1, -1, -1):
		c.append(str(int(a[i]) + int(b[i])))
	c = c[::-1]
	c = ''.join(c)
	return c
t = int(input())
for _ in range(t):
	(a, s) = input().split()
	(al, sl) = (len(a), len(s))
	n = max(len(a), len(s))
	a = a.zfill(n)
	s = s.zfill(n)
	(start, end) = (n - 1, n)
	b = ''
	for i in range(n - 1, -1, -1):
		if i < n - al and start < 0:
			break
		elif start < 0:
			b = -1
		if a[i] <= s[start:end]:
			b += str(int(s[start:end]) - int(a[i]))
			start -= 1
			end -= 1
			if start < 0:
				if i > n - al:
					b = -1
				break
		else:
			start -= 1
			try:
				b += str(int(s[start:end]) - int(a[i]))
				start -= 1
				end = start + 1
			except:
				b = -1
				break
	if b == -1:
		print(b)
		continue
	b = b[::-1]
	try:
		b = int(b)
	except:
		print(-1)
		continue
	if wrongadd(a, b) == s:
		print(b)
	else:
		print(-1)


for _ in range(int(input())):
	(a, s) = input().split()
	i = len(a) - 1
	j = len(s) - 1
	b = []
	pos = True
	while j >= 0:
		if j < i:
			pos = False
			break
		if i < 0:
			b.append(int(s[j]))
			j -= 1
		elif int(s[j]) >= int(a[i]):
			b.append(int(s[j]) - int(a[i]))
			j -= 1
			i -= 1
		elif j == 0:
			pos = False
			break
		else:
			b.append(int(s[j - 1]) * 10 + int(s[j]) - int(a[i]))
			j -= 2
			i -= 1
	for i in b:
		if int(i) < 0 or int(i) > 9:
			pos = False
			break
	if pos:
		b.reverse()
		while int(b[0]) == 0:
			b.pop(0)
		for i in b:
			print(i, end='')
		print()
	else:
		print(-1)


for _ in range(int(input())):
	(a, s) = input().split()
	b = ''
	j = len(s) - 1
	got = True
	for i in range(len(a) - 1, -1, -1):
		if j < 0:
			got = False
			break
		if int(a[i]) <= int(s[j]):
			b += str(int(s[j]) - int(a[i]))
			j -= 1
		else:
			if j < 1:
				got = False
				break
			c = int(s[j - 1] + s[j])
			if int(a[i]) + 9 < c or c < int(a[i]):
				got = False
				break
			b += str(c - int(a[i]))
			j -= 2
	print(int(s[:j + 1] + b[::-1]) if got else -1)


t = int(input())
while t > 0:
	t -= 1
	(a, s) = map(int, input().split())
	a2 = str(a)
	s2 = str(s)
	ccc = a2
	a2 = '0' * (len(s2) - len(ccc)) + ccc
	n = len(a2)
	m = len(s2)
	i = 0
	j = 0
	ans = ''
	fl = True
	while i < n and j < n:
		d1 = int(a2[-1 - i])
		d2 = int(s2[-1 - j])
		if d2 >= d1:
			ans += str(d2 - d1)
			i += 1
			j += 1
		else:
			if j == n - 1:
				break
			tt = str(int(s2[-2 - j]) * 10 + d2 - d1)
			if len(tt) > 1:
				break
			ans += tt
			i += 1
			j += 2
	ans += '0' * (n - len(ans))
	ans = ans[::-1]
	st = []
	for i in range(n - 1, -1, -1):
		st.append(str(int(ans[i]) + int(a2[i])))
	res = ''
	st = st[::-1]
	for i in range(len(st)):
		res += st[i]
	res = str(int(res))
	if res == s2:
		print(int(ans))
	else:
		print(-1)


def find_b(a, s):
	if a == '':
		return s
	if s == '':
		return '-1'
	if int(a[-1]) <= int(s[-1]):
		prefix = find_b(a[:-1], s[:-1])
		if prefix != '-1':
			return prefix + str(int(s[-1]) - int(a[-1]))
	elif len(s) >= 2 and s[-2] == '1':
		prefix = find_b(a[:-1], s[:-2])
		if prefix != '-1':
			return prefix + str(int(s[-2:]) - int(a[-1]))
	return '-1'
n = int(input())
output = []
for _ in range(n):
	output.append(int(find_b(*input().split())))
for ans in output:
	print(ans)


import sys
import pprint
import logging
from logging import getLogger

def input():
	return sys.stdin.readline().rstrip('\r\n')
logging.basicConfig(format='%(message)s', level=logging.WARNING)
logger = getLogger(__name__)
logger.setLevel(logging.INFO)

def debug(msg, *args):
	logger.info(f'{msg}={pprint.pformat(args)}')
from collections import deque

def check(a, b, s):
	S = deque()
	if len(b) < len(a):
		b = [0] * (len(a) - len(b)) + b
	if len(a) < len(b):
		a = [0] * (len(b) - len(a)) + a
	for i in range(len(a) - 1, -1, -1):
		summ = a[i] + b[i]
		S.appendleft(summ)
	S = ''.join(map(str, S))
	s = ''.join(map(str, s))
	if S == s:
		return True
	return False
for i in range(int(input())):
	(a, s) = map(str, input().split())
	a = list(map(int, a))
	s = list(map(int, s))
	lsta = len(a) - 1
	lsts = len(s) - 1
	b = deque()
	ok = True
	while lsta > -1 and lsts > -1:
		summ = s[lsts]
		if a[lsta] == summ:
			if lsta == 0:
				lsts -= 1
				mul = 10
				while lsts > -1:
					summ += mul * s[lsts]
					lsts -= 1
					mul *= 10
			b.appendleft(summ - a[lsta])
		elif a[lsta] > summ:
			t = summ
			if lsts - 1 >= 0:
				summ += 10 * s[lsts - 1]
			else:
				ok = False
				break
			lsts -= 1
			b.appendleft(abs(summ - a[lsta]))
		else:
			b.appendleft(summ - a[lsta])
		lsta -= 1
		lsts -= 1
	if lsts >= 0:
		summ = s[lsts]
		mul = 10
		lsts -= 1
		while lsts > -1:
			summ += mul * s[lsts]
			lsts -= 1
			mul *= 10
		b.appendleft(summ)
	if ok:
		number = []
		for i in b:
			for j in str(i):
				if j == '-':
					ok = False
					break
				number.append(int(j))
		if ok and check(a, number, s):
			number = int(''.join(map(str, b)))
			print(number)
		else:
			print(-1)
	else:
		print(-1)


import sys, os, io
import math
from collections import defaultdict

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def solve():
	(a, s) = li()
	a = str(a)
	s = str(s)
	a = list(a)
	s = list(s)
	ptr = len(s) - 1
	b = []
	for i in range(len(a) - 1, -1, -1):
		if ptr < 0:
			print(-1)
			return
		if int(a[i]) <= int(s[ptr]):
			b.append(str(int(s[ptr]) - int(a[i])))
			ptr -= 1
		else:
			if ptr == 0:
				print(-1)
				return
			x = int(s[ptr - 1]) * 10 + int(s[ptr])
			if 0 <= x - int(a[i]) <= 9:
				b.append(str(x - int(a[i])))
				ptr -= 2
			else:
				print(-1)
				return
	print(int(''.join(s[:ptr + 1] + b[::-1])))
t = 1
t = ii()
for _ in range(t):
	solve()


import math as m
i = input()
inp = []
for a in range(0, int(i)):
	inp.append(input().split())

def logic(a, s):
	l_a = len(a)
	l_s = len(s)
	p_a = 1
	p_s = 1
	b = 0
	while p_a <= l_a and p_s <= l_s:
		a_digit = int(a[-p_a])
		s_digit = int(s[-p_s])
		if a_digit <= s_digit:
			b += (s_digit - a_digit) * 10 ** (p_a - 1)
			p_a += 1
			p_s += 1
		elif p_s < l_s:
			s_next_digit = int(s[-p_s - 1])
			if s_next_digit == 1:
				b += (10 + s_digit - a_digit) * 10 ** (p_a - 1)
				p_a += 1
				p_s += 2
			else:
				return -1
		else:
			return -1
	if p_s > l_s and p_a <= l_a:
		return -1
	elif p_s <= l_s and p_a > l_a:
		b += int(s[:-p_s + 1]) * 10 ** l_a
	return b
for i in inp:
	[a, s] = i
	print(logic(a, s))


def doit(x, y):
	if x > y:
		raise Exception()
	if x == y:
		return 0
	dx = x % 10
	dy = y % 10
	if dy >= dx:
		return doit(x // 10, y // 10) * 10 + dy - dx
	else:
		dy = y % 100
		if dy > dx and dy - dx < 10:
			return doit(x // 10, y // 100) * 10 + dy - dx
	raise Exception()

def solve():
	(x, y) = [int(x) for x in input().split()]
	try:
		res = doit(x, y)
		return res
	except:
		return -1
t = int(input())
for _ in range(t):
	print(solve())


for i in range(int(input())):
	(a, s) = input().split()
	(a, s) = (a[::-1], s[::-1])
	na = len(a)
	ns = len(s)
	ans = ''
	k = 0
	flag = True
	for j in range(na):
		if k >= ns:
			flag = False
			break
		a_int = int(a[j])
		s_int = int(s[k])
		if a_int <= s_int:
			ans += str(s_int - a_int)
			k += 1
		elif k + 1 >= ns:
			flag = False
			break
		else:
			s_int2 = int(s[k + 1] + s[k])
			if s_int2 // 10 != 1:
				flag = False
				break
			else:
				ans += str(s_int2 - a_int)
				k += 2
	if flag:
		print(int(s[k:][::-1] + ans[::-1]))
	else:
		print(-1)


from sys import stdin, stdout
import math
import copy
T = int(input())
for i in range(T):
	(a, s) = [str(x) for x in stdin.readline().split()]
	ans = ''
	while True:
		if len(a) == 0:
			a = '0'
		last_a = int(a[-1:])
		unavailable_one = 0
		unavailable_two = 0
		last_one = s[-1:]
		if len(last_one) != 1:
			unavailable_one = 1
		else:
			target = int(last_one)
			if target >= last_a:
				ans = str(target - last_a) + ans
				a = a[:-1]
				s = s[:-1]
			else:
				unavailable_one = 1
		if unavailable_one == 1:
			last_two = s[-2:]
			if len(last_two) != 2:
				unavailable_two = 1
			else:
				target = int(last_two)
				if target >= last_a and target <= last_a + 9:
					ans = str(target - last_a) + ans
					a = a[:-1]
					s = s[:-2]
				else:
					unavailable_two = 1
		if a == '' and s == '':
			print(ans.lstrip('0'))
			break
		if unavailable_one == 1 and unavailable_two == 1:
			print(-1)
			break


import sys
import math
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
for _ in range(t):
	(a, s) = inlt()
	b = ''
	while s > 0:
		a0 = a % 10
		s0 = s % 10
		if a0 > s0:
			s0 = s % 100
			if s0 > 18 or s0 < 10:
				break
			s = s // 100
		else:
			s0 = s % 10
			s = s // 10
		a = a // 10
		b = str(s0 - a0) + b
	if a > 0:
		print(-1)
	else:
		print(int(b))


from math import e
t = int(input())
for _ in range(t):
	(a, s) = input().split()
	b = []
	exists = True
	while len(s) > 0:
		if len(a) > len(s):
			exists = False
			break
		if len(a) == 0:
			for i in reversed(s):
				b.insert(0, i)
			break
		if int(a[-1]) > int(s[-1]):
			enter = int(s[-2:]) - int(a[-1])
			if 0 <= enter <= 9:
				b.insert(0, str(enter))
				s = s[:-2]
				a = a[:-1]
			else:
				exists = False
				break
		else:
			b.insert(0, str(int(s[-1]) - int(a[-1])))
			s = s[:-1]
			a = a[:-1]
	if exists:
		b = ''.join(b)
		if len(b) == 1:
			print(b)
		else:
			b = b.lstrip('0')
			print(b)
	else:
		print(-1)


t = int(input())
for i in range(t):
	(a, s) = input().split()
	b = ''
	k = len(s) - 1
	for i in reversed(range(len(a))):
		if s[k] == a[i]:
			b = '0' + b
		elif s[k] < a[i]:
			if k == 0 or s[k - 1] != '1':
				print(-1)
				break
			b = str(10 + int(s[k]) - int(a[i])) + b
			k -= 1
		else:
			b = str(int(s[k]) - int(a[i])) + b
		k -= 1
	else:
		if k < -1:
			print(-1)
		elif k > -1:
			b = s[:k + 1] + b
			print(int(b))
		else:
			print(int(b))


import sys
t = int(input())
for _ in range(t):
	line = sys.stdin.readline()
	[a, s] = line[:len(line) - 1].split()
	result = 0
	finished = False
	ai = len(a) - 1
	si = len(s) - 1
	B = []
	while not finished:
		if int(a[ai]) <= int(s[si]):
			B.append(str(int(s[si]) - int(a[ai])))
			ai -= 1
			si -= 1
			if si < 0 and ai >= 0:
				result = -1
				break
			elif ai < 0:
				B.append(str(s[:si + 1]))
				finished = True
				break
		else:
			if s[si - 1] != '1' or si == 0:
				result = -1
				break
			B.append(str(int(s[si - 1] + s[si]) - int(a[ai])))
			ai -= 1
			si -= 2
			if si < 0 and ai >= 0:
				result = -1
				break
			elif ai < 0:
				B.append(str(s[:si + 1]))
				finished = True
				break
	if finished is True:
		B.reverse()
		result = int(''.join(B))
	print(result)


from sys import stdin, stdout
from collections import defaultdict
input = stdin.readline
from random import randint
import math
import sys
for _ in range(int(input())):
	(a, s) = map(str, input().strip().split())
	b = ''
	no = False
	if int(s) < int(a):
		print(-1)
		continue
	while len(a) > 0 and len(s) > 0:
		if a[-1] == s[-1]:
			b = '0' + b
			a = a[:-1]
			s = s[:-1]
		elif int(a[-1]) < int(s[-1]):
			b = str(int(s[-1]) - int(a[-1])) + b
			a = a[:-1]
			s = s[:-1]
		elif len(s) > 1 and s[-2] == '1':
			b = str(int(s[-2] + s[-1]) - int(a[-1])) + b
			a = a[:-1]
			s = s[:-2]
		else:
			no = True
			break
	if len(s) != 0:
		b = s + b
	if len(a) > 0:
		no = True
	if no:
		print(-1)
	else:
		print(int(b))


from collections import defaultdict, Counter, deque
from math import sqrt, log10, log, floor, factorial, gcd
from bisect import bisect_left, bisect_right, insort
from itertools import permutations, combinations
import sys, io, os
input = sys.stdin.readline
inf = float('inf')
mod = 10 ** 9 + 7

def yn(a):
	print('YES' if a else 'NO')
ceil = lambda a, b: (a + b - 1) // b
t = int(input())
for i in range(t):
	(a, s) = input().split()
	a = int(a)
	s = int(s)
	a1 = a
	s1 = s
	result = ''
	itr = 0
	while a > 0 or s > 0:
		itr += 1
		ls = s % 10
		la = a % 10
		if ls < la:
			ls = s % 100
			chk = ls - la
			s = s // 100
		else:
			chk = ls - la
			s = s // 10
		a = a // 10
		result += str(chk)
		if chk < 0 or chk >= 10:
			result = '-1'
			break
	if result == '-1':
		print(result)
	else:
		while s:
			result += str(s % 10)
			s //= 10
		r = result[::-1]
		r = int(r)
		print(r)


import bisect
import collections
import math
import sys
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.buffer.readline())

def MI():
	return map(int, sys.stdin.buffer.readline().split())

def LI():
	return list(map(int, sys.stdin.buffer.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def BI():
	return sys.stdin.buffer.readline().rstrip()

def SI():
	return sys.stdin.buffer.readline().rstrip().decode()

def li():
	return [int(i) for i in input().split()]

def lli(rows):
	return [li() for _ in range(rows)]

def si():
	return input()

def ii():
	return int(input())

def ins():
	return input().split()

def drank(d, processing, da, rank):
	tmp = 10 ** 9
	if len(d[da]) == 1:
		return 1
	for di in d[da]:
		if processing[di - 1] == 0:
			processing[di - 1] = 1
			tmp = min(tmp, drank(d, processing, di, rank))
			processing[di - 1] = 0
	rank[da - 1] = tmp + 1
	return tmp + 1

def binary_search(n, a):
	l = len(a)
	low = 0
	high = l - 1
	while high >= low:
		mid = (high + low) // 2
		if a[mid] == n:
			return mid
		elif a[mid] > n:
			high = mid - 1
		else:
			low = mid + 1
	return -1
is_prime = [True] * (10 ** 6 + 1)

def primeseive(n):
	is_prime[0] = is_prime[1] = False
	i = 2
	while i * i <= n:
		if is_prime[i] == True:
			for j in range(i * i, n + 1, i):
				is_prime[j] = False
		i += 1

def solve():
	(a, s) = si().split(' ')
	i = 0
	j = 0
	la = len(a)
	ls = len(s)
	a = a[::-1]
	s = s[::-1]
	ans = ''
	while i < la:
		if j >= ls:
			return -1
		if a[i] <= s[j]:
			ans += str(int(s[j]) - int(a[i]))
			i += 1
			j += 1
		elif j + 1 < ls and s[j + 1] == '1':
			ans += str(int('1' + s[j]) - int(a[i]))
			i += 1
			j += 2
		else:
			return -1
	if j != ls:
		ans += s[j:]
	return ans.rstrip('0')[::-1]

def main():
	for _ in range(ii()):
		sys.stdout.write(str(solve()) + '\n')
main()


t = int(input())
for t in range(t):
	(a, s) = list(map(int, input().split()))
	(gg, ans) = (0, '')
	while a > 0:
		x = a % 10
		y = s % 10
		add = y - x
		if add < 0:
			add += 10
		ans = str(add) + ans
		if add + x < 10:
			a //= 10
			s //= 10
		else:
			a //= 10
			s //= 10
			if s % 10 != (add + x) // 10:
				gg = 1
				break
			else:
				s //= 10
	print(((str(s) if s > 0 else '') + str(ans)).lstrip('0') if not gg else -1)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def solve(a, s):
	(a, s) = (a[::-1], s[::-1])
	(ai, si) = (0, 0)
	bl = []
	while ai < len(a) and si < len(s):
		if ord(a[ai]) == ord(s[si]):
			bl.append('0')
			ai += 1
			si += 1
		elif ord(a[ai]) > ord(s[si]):
			nsi = si + 1
			if nsi == len(s):
				return -1
			if s[nsi] != '1':
				return -1
			diff = int(s[nsi] + s[si]) - int(a[ai])
			bl.append(str(diff))
			ai += 1
			si += 2
		else:
			diff = ord(s[si]) - ord(a[ai])
			bl.append(str(diff))
			ai += 1
			si += 1
	if ai != len(a):
		return -1
	while si != len(s):
		bl.append(s[si])
		si += 1
	return int(''.join(bl[::-1]))
for _ in range(int(input())):
	(a, s) = input().split()
	val = solve(a, s)
	print(val)


import math
n = int(input())

def result(a, b):
	a = str(a)
	b = str(b)
	if len(a) < len(b):
		a = '0' * (len(b) - len(a)) + a
	else:
		b = '0' * (len(a) - len(b)) + b
	res = ''
	for i in range(len(b) - 1, -1, -1):
		res = str(int(a[i])) + str(int(b[i])) + res
	return res
for i in range(n):
	(a, s) = map(int, input().split())
	res = ''
	temp = str(s)
	at = str(a)
	while a > 0 or s > 0:
		rem = a % 10
		a = a // 10
		srem = s % 10
		s = s // 10
		if srem >= rem:
			res = str(srem - rem) + res
		else:
			t = s % 10
			s = s // 10
			if t * 10 + srem - rem < 10:
				res = str(t * 10 + srem - rem) + res
			else:
				res = '-1' + res
	if a == 0 and s == 0 and ('-' not in res):
		print(int(res))
	else:
		print(-1)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def getnext(index1, index2, s1, s2, dic):
	if index1 == len(s1):
		return s2[index2:]
	if index2 == len(s2):
		return '*'
	if (index1, index2) in dic:
		return dic[index1, index2]
	d1 = int(s1[index1])
	d2 = int(s2[index2])
	if d1 > d2:
		if index2 + 1 < len(s2) and s2[index2 + 1] == '1':
			output = str(d2 + 10 - d1) + getnext(index1 + 1, index2 + 2, s1, s2, dic)
		else:
			output = '*'
	else:
		base = str(d2 - d1)
		output = base + getnext(index1 + 1, index2 + 1, s1, s2, dic)
	dic[index1, index2] = output
	return output

def main(t):
	(num1, num2) = map(int, input().split())
	(s1, s2) = (str(num1)[::-1], str(num2)[::-1])
	dic = {}
	ans = getnext(0, 0, s1, s2, dic)
	if ans[-1] == '*':
		print('-1')
		return
	ans = ans[::-1]
	i = 0
	while i < len(ans) - 1 and ans[i] == '0':
		i += 1
	print(ans[i:])
T = int(input())
t = 1
while t <= T:
	main(t)
	t += 1


t = int(input())
for _ in range(t):
	(a, s) = input().split()
	b = []
	i = len(a) - 1
	j = len(s) - 1
	while j >= 0 and i >= 0:
		x = int(a[i])
		y = int(s[j])
		if x <= y:
			b.append(y - x)
		elif j - 1 < 0:
			print(-1)
			break
		else:
			y = 10 * int(s[j - 1]) + y
			j -= 1
			if 10 <= y <= 18:
				b.append(y - x)
			else:
				print(-1)
				break
		i -= 1
		j -= 1
	else:
		if i >= 0:
			print(-1)
		else:
			while j >= 0:
				b.append(int(s[j]))
				j -= 1
			print(int(''.join([str(a) for a in b[::-1]])))


import sys
import bisect as bi
import os
import itertools as it
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(a, x) = I()
	a = str(a)
	x = str(x)
	(nn, mm) = (len(a), len(x))
	i = len(a) - 1
	j = len(x) - 1
	temp = []
	tf = 1
	for i in range(len(a) - 1, -1, -1):
		if j < 0:
			tf = 0
			break
		now = int(a[i])
		cur = int(x[j])
		if cur > now:
			temp.append(cur - now)
			j -= 1
		elif cur == now:
			temp.append(0)
			j -= 1
		elif j > 0:
			te = cur
			cur = int(x[j - 1]) * 10 + cur
			if x[j - 1] != '1':
				tf = 0
				break
			temp.append(cur - now)
			j -= 2
		else:
			tf = 0
			break
	if j >= 0:
		temp += list(x[:j + 1][::-1])
	if tf:
		print(''.join(list(map(str, temp[::-1]))).lstrip('0'))
	else:
		print(-1)


n = int(input())
results = []
for i in range(n):
	(a, s) = input().split()
	la = len(a)
	ls = len(s)
	if ls < la:
		results.append(-1)
		continue
	b = ''
	while la > 0 and ls > 0:
		if int(s[ls - 1]) >= int(a[la - 1]):
			b = str(int(s[ls - 1]) - int(a[la - 1])) + b
		else:
			if ls < 2:
				b = '-1'
				break
			elif s[ls - 2] != '1':
				b = '-1'
				break
			b = str(10 + int(s[ls - 1]) - int(a[la - 1])) + b
			ls -= 1
		ls -= 1
		la -= 1
	if la != 0:
		b = '-1'
	else:
		b = s[:ls] + b
	results.append(int(b))
for result in results:
	print(result)


n = int(input())
for i in range(n):
	nums = input().split()
	a = int(nums[0])
	s = int(nums[1])
	ans = []
	valid = True
	while not (a == 0 and s == 0):
		if s % 10 >= a % 10:
			ans.append(s % 10 - a % 10)
			s = s // 10
			a = a // 10
		elif s % 100 - a % 10 < 10 and s % 100 - a % 10 >= 0:
			ans.append(s % 100 - a % 10)
			s = s // 100
			a = a // 10
		else:
			valid = False
			break
	if not valid:
		res = -1
	else:
		res = 0
		for num in ans[::-1]:
			res = res * 10 + num
	print(res)


t = int(input())
for _ in range(t):
	(a, s) = map(int, input().split())
	b = ''
	(diga, digs) = (0, 0)
	while a > 0:
		diga = a % 10
		digs = s % 10
		if diga > digs:
			digs = s % 100
			s //= 10
		a //= 10
		s //= 10
		if not (digs - diga <= 9 and digs - diga >= 0):
			b = -9
			break
		b = str(digs - diga) + b
	if int(b) < 0:
		print(-1)
		continue
	b = str(s) + b
	print(int(b))


from math import *
import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return input().split()

class Solution:

	def __init__(self):
		self.ans = 0

	def solve(self, a, s):
		ans = ''
		k = 0
		for i in range(len(a)):
			if not a[i] == '0':
				break
			k += 1
		a = a[k:]
		(i, j) = (len(a) - 1, len(s) - 1)
		while i >= 0:
			x1 = int(a[i])
			temp = s[j]
			x2 = int(temp)
			while x1 > x2:
				j -= 1
				if j < 0:
					break
				temp = s[j] + temp
				x2 = int(temp)
			if j < i:
				return -1
			sub = str(x2 - x1)
			if len(sub) > 1:
				return -1
			ans = sub + ans
			j -= 1
			i -= 1
		while j >= 0:
			ans = s[j] + ans
			j -= 1
		if not len(ans):
			return -1
		return int(ans)
sol = Solution()
t = inp()
ans = []
while t:
	[a, s] = invr()
	ans.append(sol.solve(a, s))
	t -= 1
for i in range(len(ans)):
	print(ans[i], end='\n')


import math

def solve():
	x = input().split()
	a = int(x[0])
	s = int(x[1])
	ans = []
	while s > 0 and a > 0:
		numa = a % 10
		nums = s % 10
		if nums >= numa:
			ans.insert(0, nums - numa)
		else:
			s = s // 10
			nums += s % 10 * 10
			if nums > numa and nums >= 10 and (nums <= 18):
				ans.insert(0, nums - numa)
			else:
				return -1
		s = s // 10
		a = a // 10
	if a != 0:
		return -1
	while s > 0:
		nums = s % 10
		ans.insert(0, nums)
		s = s // 10
	ans = [str(i) for i in ans]
	ans = ''.join(ans)
	ans = int(ans)
	return ans
n = int(input())
for i in range(n):
	print(solve())


for _ in range(int(input())):
	(a, s) = map(int, input().split())
	(b, z) = (0, 1)
	while s > 0:
		(s0, a0) = (s % 10, a % 10)
		if s0 >= a0:
			b += z * (s0 - a0)
			s //= 10
		elif s % 100 - a0 in range(10):
			b += z * (s % 100 - a0)
			s //= 100
		else:
			break
		a //= 10
		z *= 10
	print(-1 if s > 0 or a > 0 else b)


import math

def solve(a, s):
	a = a[::-1]
	s = s[::-1]
	cur_i = 0
	b = []
	for i in range(len(a)):
		ai = int(a[i])
		if cur_i >= len(s):
			return -1
		si = int(s[cur_i])
		if ai <= si:
			b.append(str(si - ai))
		else:
			b.append(str(10 + si - ai))
			cur_i += 1
			if cur_i >= len(s):
				return -1
			if s[cur_i] != '1':
				return -1
		cur_i += 1
	if cur_i != len(s):
		for _ in range(len(s)):
			if cur_i >= len(s):
				break
			b.append(s[cur_i])
			cur_i += 1
	return ''.join(b[::-1]).lstrip('0')
import os
import io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input().decode().strip())
for t in range(T):
	(a, s) = [x for x in input().decode().strip().split(' ')]
	res = solve(a, s)
	print(res, flush=True)


def solve():
	for t in range(1):
		(a, s) = map(int, input().split())
		ans = []
		flag = False
		while s:
			x = a % 10
			y = s % 10
			if x <= y:
				ans.append(y - x)
			else:
				s = s // 10
				y += 10 * (s % 10)
				if x < y and y >= 10 and (y <= 19):
					ans.append(y - x)
				else:
					print(-1)
					return
			a //= 10
			s //= 10
		if a:
			print(-1)
		else:
			while ans[-1] == 0:
				ans.pop(-1)
			for ele in ans[::-1]:
				print(ele, end='')
			print()
for _ in range(int(input())):
	solve()


cases = int(input())
for c in range(cases):
	(a, s) = map(int, input().split())
	b = 0
	digit = 1
	sLen = len(str(s))
	for i in range(sLen):
		av = a % 10
		rv = s % 10
		bv = rv - av
		if bv < 0:
			rv = s % 100
			bv = rv - av
			if bv >= 10 or bv <= 0:
				b = -1
				break
			s //= 10
		b = b + bv * digit
		digit *= 10
		a //= 10
		s //= 10
	print(b)


t = int(input())
while t > 0:
	t -= 1
	(a, b) = map(int, input().split())
	a = str(a)
	b = str(b)
	i = len(a) - 1
	j = len(b) - 1
	ans = ''
	poss = True
	while i >= 0 and j >= 0:
		if a[i] <= b[j]:
			ans = str(ord(b[j]) - ord(a[i])) + ans
			i -= 1
			j -= 1
		else:
			if j <= 0:
				poss = False
				break
			x = int(b[j - 1:j + 1])
			x -= ord(a[i]) - ord('0')
			i -= 1
			j -= 2
			if not 0 < x <= 9:
				poss = False
				break
			ans = str(x) + ans
	poss = poss and i == -1
	for k in range(j, -1, -1):
		ans = b[k] + ans
	if not poss:
		print(-1)
		continue
	try:
		ans = int(ans)
		print(ans)
	except:
		print(-1)


i = int
for s in [*open(0)][1:]:
	(a, s) = s.split()
	a = a.zfill(19)
	b = ''
	while s and -1 < (c := (i(s[(m := (-1))]) - i(a[-1]))) <= 9 or (s[1:] and -1 < (c := (c + i(s[(m := (m - 1))]) * 10)) <= 9):
		a = a[:-1]
		s = s[:m]
		b = str(c) + b
	print(i(a) and -1 or i(b))


t = int(input(''))
i = 0
for i in range(t):
	count = 0
	s = ''
	(s1, s2) = input().split(' ')
	l1 = len(s1)
	l2 = len(s2)
	j = l1 - 1
	k = l2 - 1
	while j >= 0 and k >= 0:
		a = int(s1[j])
		c = int(s2[k])
		if a > c and k > 0:
			b = int(s2[k - 1] + s2[k])
			d = b - a
			if d > 0 and d < 10:
				s = str(d) + s
				k -= 2
				j -= 1
			else:
				count += 1
				break
		elif a < c:
			d = c - a
			s = str(d) + s
			j -= 1
			k -= 1
		elif a == c:
			s = '0' + s
			k -= 1
			j -= 1
		else:
			count += 1
			break
	if k >= 0 and count == 0:
		k += 1
		s = s2[:k] + s
		j = 0
		for j in range(k):
			s1 = '0' + s1
	if count == 0 and len(s1) == len(s):
		print(int(s))
	else:
		print('-1')


t = int(input())
for j in range(0, t):
	(a, s) = map(int, input().split())
	f = 0
	b = ''
	while f == 0:
		if a % 10 < s % 10:
			b = str(s % 10 - a % 10) + b
			a = a // 10
			s = s // 10
		elif a % 10 == s % 10:
			b = str(0) + b
			a = a // 10
			s = s // 10
		elif s // 10 % 10 == 1:
			b = str(s % 100 - a % 10) + b
			s = s // 100
			a = a // 10
		else:
			f = -1
			b = -1
			break
		if s == 0:
			if a != 0:
				b = -1
			f = -1
			break
	print(int(b))


import heapq
import sys
import math
from collections import deque
from bisect import bisect_left, bisect_right
I = sys.stdin.readline
II = lambda : int(I())
IN = lambda x: map(int, x.split())
FN = lambda x: map(float, x.split())
L = lambda x: list(IN(x))
M = 1000000007
P = print
T = True
F = False
for _ in range(II()):
	(a, s) = IN(I())
	b = 0
	t = 1
	while a > 0 or s > 0:
		(a, ad) = divmod(a, 10)
		(s, sd) = divmod(s, 10)
		if sd < ad:
			(s, sd2) = divmod(s, 10)
			if sd2 == 0:
				b = -1
				break
			sd += sd2 * 10
		c = sd - ad
		if c > 9:
			b = -1
			break
		b += c * t
		t *= 10
	print(b)


import sys

def read_line():
	return sys.stdin.readline().strip()
t = int(read_line())
for _ in range(t):
	line = read_line().split()
	a = int(line[0])
	s = int(line[1])
	b = 0
	pow10 = 1
	while s > 0:
		last_a = a % 10
		last_sum = s % 10
		if last_sum < last_a:
			s = s // 10
			last_sum += 10 * (s % 10)
			if not 0 <= last_sum - last_a <= 9:
				b = -1
				break
		b += (last_sum - last_a) * pow10
		pow10 *= 10
		s = s // 10
		a = a // 10
	print(b if a == 0 else -1)


def solve(a, s):
	na = len(a)
	ns = len(s)
	i = na - 1
	j = ns - 1
	b = ''
	while i >= 0 and j >= 0:
		if s[j] < a[i]:
			if j > 0:
				k = int(s[j - 1:j + 1]) - int(a[i])
				b += str(k)
				j -= 2
		else:
			k = int(s[j]) - int(a[i])
			b += str(k)
			j -= 1
		i -= 1
	if j >= 0:
		b += s[:j + 1][::-1]
	if i >= 0:
		b += a[:i + 1][::-1]
	b = b[::-1]
	if '-' in b:
		return -1
	elif int(b) > int(s):
		return -1
	else:
		st = ''
		nb = len(b)
		if na > nb:
			b = '0' * (na - nb) + b
			nb = na
		else:
			a = '0' * (nb - na) + a
			na = nb
		for i in range(na):
			st += str(int(a[i]) + int(b[i]))
		if s == st:
			return int(b)
		else:
			return -1
q = int(input())
while q:
	l = [i for i in input().split(' ')]
	a = l[0]
	s = l[1]
	print(solve(a, s))
	q -= 1


def finda(b, s):
	(i, j) = (len(b) - 1, len(s) - 1)
	ans = ''
	while i >= 0 and j >= 0:
		small = int(b[i])
		big = 0
		if b[i] <= s[j]:
			big = int(s[j])
		elif j > 0:
			big = int(s[j - 1:j + 1])
			j -= 1
		g = big - small
		if g > 9 or g < 0:
			return -1
		ans = str(g) + ans
		i -= 1
		j -= 1
	ans = s[:j + 1] + ans
	return int(ans) if i < 0 else -1
for _ in range(int(input())):
	(b, s) = input().split()
	print(finda(b, s))


for _ in range(int(input())):
	(a, s) = input().split()
	a = list(a)
	s = list(s)
	b = ''
	while a and s:
		c = a.pop()
		d = s.pop()
		if c > d:
			if s:
				f = s.pop()
				if f != '1':
					b = -1
					break
			else:
				b = -1
				break
			b += str(int(f + d) - int(c))
		else:
			b += str(int(d) - int(c))
	if a or b == -1:
		print(-1)
		continue
	elif s:
		for i in s[::-1]:
			b += i
	print(int(b[::-1]))


try:
	for _ in range(int(input())):
		(a, n) = map(int, input().split())
		c = 0
		for i in range(18):
			r = a % 10
			t = n % 10
			if r > t:
				c += 10 ** i * (10 + t - r)
				n //= 10
				if n % 10 != 1:
					c = -1
					break
			else:
				c += 10 ** i * (t - r)
			n //= 10
			a //= 10
		print(c)
except:
	pass


t = int(input())
for _ in range(t):
	(A, S) = map(str, input().split())
	A = list(A)
	S = list(S)
	A = [int(c) for c in A]
	S = [int(c) for c in S]
	A.reverse()
	B = []
	flag = True
	for a in A:
		if len(S) == 0:
			flag = False
			break
		elif S[-1] >= a:
			b = S[-1] - a
			B.append(b)
			S.pop()
		else:
			if len(S) <= 1:
				flag = False
				break
			s = S[-1] + S[-2] * 10
			b = s - a
			if b >= 10 or b < 0:
				flag = False
				break
			B.append(b)
			S.pop()
			S.pop()
	if not flag:
		print(-1)
		continue
	while S:
		b = S.pop()
		B.append(b)
	ans = 0
	for (i, b) in enumerate(B):
		ans += b * pow(10, i)
	print(ans)


import sys
import math
input = sys.stdin.readline

def solve(a, s):
	a = [int(i) for i in a]
	s = [int(i) for i in s]
	i = len(a) - 1
	j = len(s) - 1
	ans = []
	while True:
		if i == -1:
			for k in range(j, -1, -1):
				ans.append(s[k])
			break
		if j == -1:
			return -1
		if a[i] > s[j]:
			if j == 0:
				return -1
			if s[j - 1] != 1:
				return -1
			else:
				ans.append(int(str(s[j - 1]) + str(s[j])) - a[i])
				j -= 2
				i -= 1
		else:
			ans.append(s[j] - a[i])
			j -= 1
			i -= 1
	ans.reverse()
	index = len(ans) - 1
	for i in range(len(ans)):
		if ans[i] != 0:
			index = i
			break
	ans = ans[index:]
	anss = ''
	for i in ans:
		anss += str(i)
	if len(anss) == 0:
		anss += '0'
	return anss
for _ in range(int(input())):
	print(solve(*input().split()))


def solve(a, b):
	(i, j) = (len(a) - 1, len(b) - 1)
	diff = ''
	while i >= 0 and j >= 0:
		(c, d) = (a[i], b[j])
		if int(c) <= int(d):
			diff += str(int(d) - int(c))
		else:
			j -= 1
			if b[j] != '1':
				return '-1'
			else:
				d = '1' + d
				diff += str(int(d) - int(c))
		i -= 1
		j -= 1
		if i > j:
			return '-1'
	if i < j:
		diff += b[:j + 1][::-1]
	return int(diff[::-1])
T = int(input())
for _ in range(T):
	(a, b) = input().split()
	print(solve(a, b))


from collections import Counter, defaultdict
import math
import bisect

def getlist():
	return list(map(int, input().split()))

def maplist():
	return map(int, input().split())

def main():
	n = int(input())
	for num in range(n):
		(a, s) = maplist()
		arr1 = str(a)
		arr2 = str(s)
		b = ''
		loop = False
		while len(arr2) >= len(arr1):
			if int(arr2[-1]) >= int(arr1[-1]):
				b += str(int(arr2[-1]) - int(arr1[-1]))
				arr2 = arr2[:-1]
			elif int(arr2[-2:]) - int(arr1[-1]) < 10 and int(arr2[-2:]) > int(arr1[-1]):
				b += str(int(arr2[-2:]) - int(arr1[-1]))
				arr2 = arr2[:-2]
			else:
				break
			arr1 = arr1[:-1]
			if len(arr1) == 0:
				b += arr2[::-1]
				loop = True
				break
		if loop:
			b = b[::-1]
			i = 0
			while i < len(b):
				if int(b[i]) == 0:
					i += 1
				else:
					break
			print(b[i:])
		else:
			print(-1)
main()


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
for _ in range(inp()):
	(n, m) = invr()
	if m < n:
		print(-1)
	else:
		s = ''
		while m:
			if m % 10 < n % 10:
				k = m % 100
				if k - n % 10 >= 10 or k < 10:
					print(-1)
					break
				else:
					s = str(k - n % 10) + s
					m //= 100
					n //= 10
			else:
				s = str(m % 10 - n % 10) + s
				m //= 10
				n //= 10
		else:
			if n or m:
				print(-1)
			else:
				s = s.lstrip('0')
				print(s)


t = int(input())
for _ in range(t):
	(a, s) = input().split()
	ind = len(s) - 1
	b = ''
	for i in reversed(range(len(a))):
		if ind < 0:
			print(-1)
			break
		if s[ind] >= a[i]:
			b = str(int(s[ind]) - int(a[i])) + b
			ind -= 1
		elif ind > 0 and s[ind - 1] == '1':
			b = str(10 + int(s[ind]) - int(a[i])) + b
			ind -= 2
		else:
			print(-1)
			break
	else:
		if ind != -1:
			b = s[:ind + 1] + b
		print(int(b))


from sys import stdin, setrecursionlimit, stdout
from io import BytesIO
import os
from collections import deque, Counter
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
from bisect import bisect_right, bisect_left

def ii():
	return int(input().decode()) if OJ else int(input())

def fi():
	return float(input().decode()) if OJ else float(input())

def mi():
	return map(int, input().decode().split()) if OJ else map(int, input().split())

def fmi():
	return map(float, input().decode().split()) if OJ else map(float, input().split('\n'))

def li():
	return list(mi())

def si():
	return input().decode().rstrip() if OJ else input().rstrip()

def lsi():
	return list(si())

def oj():
	global OJ
	OJ = True

def check(a, b, s):
	while max(a, b):
		(x, y) = (a % 10, b % 10)
		a //= 10
		b //= 10
		if x + y < 10:
			z = s % 10
			s //= 10
		else:
			z = s % 100
			s //= 100
		if x + y != z:
			return False
	if s:
		return False
	return True

def solve(a, s):
	(z, zz) = (a, s)
	ans = []
	while s:
		x = a % 10
		a //= 10
		if x <= s % 10:
			y = s % 10
			s //= 10
		else:
			y = s % 100
			s //= 100
		if y - x > 9:
			return -1
		ans.append(y - x)
	if a:
		return -1
	p = 0
	for i in ans[::-1]:
		p = p * 10 + i
	return p if check(z, p, zz) else -1

def main():
	(a, s) = mi()
	print(solve(a, s))
OJ = False
oj()
if OJ:
	input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
else:
	input = stdin.readline
vow = {'A', 'E', 'I', 'O', 'U'}
mod = 1000000007
res = ['NO', 'YES']
(test, test_case) = (0, 1)
test_case = ii()
print('>>>>>>>>>>>>> O U T P U T >>>>>>>>>>>>>\n' if not OJ else '', end='')
while test < test_case:
	test += 1
	main()


T = int(input())
for _ in range(T):
	(a, s) = input().split()
	ans = ''
	dif = 0
	start_a = len(a) - 1
	start_s = len(s) - 1
	marker = True
	while start_a >= 0 and start_s >= 0:
		if int(a[start_a]) > int(s[start_s]):
			if start_s == 0:
				marker = False
				break
			elif s[start_s - 1] != '1':
				marker = False
				break
			else:
				ans = str(int(s[start_s]) + 10 - int(a[start_a])) + ans
				start_s -= 2
				start_a -= 1
		else:
			ans = str(int(s[start_s]) - int(a[start_a])) + ans
			start_a -= 1
			start_s -= 1
	if not marker:
		print(-1)
	elif start_a != -1:
		print(-1)
	elif start_s < -1:
		print(-1)
	else:
		if start_s == -1:
			pass
		else:
			for i in range(start_s, -1, -1):
				ans = s[i] + ans
		for i in range(len(ans)):
			if ans[i] != '0':
				print(ans[i:])
				break


t = int(input())
for i in range(t):
	(a, s) = map(int, input().split())
	b = ''
	while a > 0:
		r1 = a % 10
		r2 = s % 10
		r3 = s % 100
		m1 = r1
		m2 = r1 + 9
		a = a // 10
		if r2 >= m1 and r2 <= m2:
			b = str(r2 - r1) + b
			s = s // 10
		elif r3 >= m1 and r3 <= m2:
			b = str(r3 - r1) + b
			s = s // 100
		else:
			print(-1)
			break
	else:
		if s > 0:
			b = str(s) + str(b)
		print(int(b))


for _ in range(int(input())):
	(a, s) = list(map(int, input().split()))
	ans = []
	flag = False
	while s:
		x = a % 10
		y = s % 10
		if x <= y:
			ans.append(y - x)
		else:
			s //= 10
			y += 10 * (s % 10)
			if y > x and 10 <= y <= 19:
				ans.append(y - x)
			else:
				flag = True
				break
		a //= 10
		s //= 10
	if flag or a:
		print(-1)
	else:
		while ans[-1] == 0:
			ans.pop(-1)
		print(*ans[::-1], sep='')


for _ in range(int(input())):
	(a, s) = map(int, input().split())
	b = 0
	c = 1
	while s > 0:
		(a1, s1) = (a % 10, s % 10)
		if s1 >= a1:
			b += c * (s1 - a1)
			s //= 10
		elif s % 100 - a1 in range(10):
			b += c * (s % 100 - a1)
			s //= 100
		else:
			break
		a //= 10
		c *= 10
	print(-1 if s > 0 or a > 0 else b)


for t in range(int(input())):
	(a, s) = map(int, input().split())
	ans = ''
	while s:
		x = a % 10
		y = s % 10
		if x <= y:
			ans += str(y - x)
		else:
			s //= 10
			y += 10 * (s % 10)
			if x < y <= 19 and y >= 10:
				ans += str(y - x)
			else:
				print(-1)
				break
		a //= 10
		s //= 10
	else:
		if a:
			print(-1)
		else:
			ans = ans[::-1]
			for i in range(len(ans)):
				if ans[i] != '0':
					print(ans[i:])
					break


for _ in range(int(input())):
	arr = [int(x) for x in input().split()]
	(a, s) = (arr[0], arr[1])
	ans = ''
	while a > 0:
		temp1 = a % 10
		temp2 = s % 10
		temp3 = s % 100
		r1 = temp1
		r2 = temp1 + 9
		a = a // 10
		if temp2 >= r1 and temp2 <= r2:
			ans = str(temp2 - temp1) + ans
			s = s // 10
		elif temp3 >= r1 and temp3 <= r2:
			ans = str(temp3 - temp1) + ans
			s = s // 100
		else:
			print(-1)
			break
	else:
		if s > 0:
			ans = str(s) + str(ans)
		print(int(ans))


for i in range(int(input())):
	(a, s) = map(int, input().split())
	a = str(a)
	s = str(s)
	b = []
	jud = 0
	now = len(s) - 1
	for i in range(len(a) - 1, -1, -1):
		if now < 0:
			jud = 1
			break
		if int(a[i]) > int(s[now]):
			if now <= 0 or s[now - 1] != '1':
				jud = 1
				break
			b.append(10 - (int(a[i]) - int(s[now])))
			now -= 2
		else:
			b.append(int(s[now]) - int(a[i]))
			now -= 1
	for i in range(now, -1, -1):
		b.append(s[i])
	n = len(b)
	for i in range(n - 1, -1, -1):
		if b[i] == 0:
			b.pop(-1)
		else:
			break
	if jud == 1:
		print(-1)
	elif b == []:
		print(0)
	else:
		ans = ''
		for i in range(len(b) - 1):
			ans += str(b[-(i + 1)])
		ans += str(b[0])
		print(int(ans))


numcases = int(input())
for i in range(numcases):
	nums = input()
	nums = nums.split()
	nums[0] = nums[0].zfill(len(nums[1]))
	nums[0] = nums[0][::-1]
	nums[1] = nums[1][::-1]
	temp = nums[0]
	nums[0] = nums[1]
	nums[1] = temp
	try:
		c = 0
		out = ''
		for (i, x) in enumerate(nums[1]):
			if len(nums[0]) > i + c:
				n = int(x)
				a = int(nums[0][i + c])
				if n == a:
					out += '0'
				elif n > a:
					d = int(nums[0][i + c:i + c + 2][::-1])
					if d - n < 10:
						out += str(d - n)
						c += 1
					else:
						raise Exception
				elif n < a:
					out += str(a - n)
			elif int(nums[1][i:]):
				if len(str(int(nums[1][i:]))) > len(str(int(nums[0][i + c:]))):
					raise Exception
		print(int(out[::-1]))
	except:
		print(-1)


sr = lambda : input()
ir = lambda : int(sr())
lr = lambda : list(map(int, sr().split()))
inf = 10 ** 18
mod = 998244353
test = ir()
for t in range(test):
	(a, s) = lr()
	b = 0
	pre_b = 1
	n = len(str(a))
	flg = True
	for i in range(n):
		tmp_a = a % 10
		a = a // 10
		tmp_s = s % 10
		if tmp_a > tmp_s:
			tmp_s = s % 100
			tmp_b = tmp_s - tmp_a
			if 0 <= tmp_b < 10:
				b += tmp_b * pre_b
				pre_b *= 10
				s = s // 100
			else:
				flg = False
				break
		else:
			tmp_b = tmp_s - tmp_a
			if 0 <= tmp_b < 10:
				b += tmp_b * pre_b
				pre_b *= 10
				s = s // 10
			else:
				flg = False
				break
	if flg:
		if s != 0:
			b += pre_b * s
		print(b)
	else:
		print(-1)


for iq in range(int(input())):
	(a, s) = map(int, input().split())
	if a > s:
		print(-1)
	else:
		s = [int(i) for i in str(s)]
		a = [int(i) for i in str(a)]
		b = []
		while len(a) != 0:
			if len(s) == 0:
				b.append(-1)
				break
			if s[-1] < a[-1]:
				if len(s) < 2:
					b.append(-1)
					break
				b.append(s[-2] * 10 + s[-1] - a[-1])
				s.pop()
			else:
				b.append(s[-1] - a[-1])
			s.pop()
			a.pop()
		f = 0
		for i in b:
			if i >= 10 or i < 0:
				print(-1)
				f = 1
				break
		b = b[::-1]
		if not f:
			i = 0
			if len(s) == 0:
				while i != len(b) and b[i] == 0:
					i += 1
				if i == len(b):
					b.append(0)
			print(*s, *b[i:], sep='')


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(a, s) = input().split()
	b = ''
	c = len(s) - 1
	d = 0
	for i in range(len(a) - 1, -1, -1):
		if c < 0:
			d = -1
			break
		if int(s[c]) == int(a[i]):
			b += '0'
			c -= 1
		elif int(s[c]) > int(a[i]):
			b += str(int(s[c]) - int(a[i]))
			c -= 1
		elif c != 0:
			if len(str(int(s[c - 1] + s[c]) - int(a[i]))) > 1 or s[c - 1] == '0':
				d = -1
				break
			b += str(int(s[c - 1] + s[c]) - int(a[i]))
			c -= 2
		else:
			d = -1
			break
	if d == -1:
		print(d)
		continue
	if c != -1:
		for i in range(c, -1, -1):
			b += s[i]
	print(b[::-1].lstrip('0'))


from __future__ import print_function
from math import *
from collections import deque
import os
import sys
from io import BytesIO, IOBase

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
for _ in range(inp()):
	(a, s) = input().split()
	na = len(a)
	ns = len(s)
	out = []
	a = list(map(int, list(a)))
	s = list(map(int, list(s)))
	a = [0] * (ns - na) + a
	f = 1
	pa = ns - 1
	ps = ns - 1
	while pa >= 0 and ps >= 0:
		if a[pa] <= s[ps]:
			out.append(s[ps] - a[pa])
			pa -= 1
			ps -= 1
		else:
			out.append(10 + s[ps] - a[pa])
			if s[ps - 1] != 1 or ps == 0:
				f = 0
				break
			ps -= 2
			pa -= 1
	while out[-1] == 0:
		out.pop()
	out.reverse()
	if not f or pa > ns - na - 1:
		print(-1)
		continue
	print(''.join((str(i) for i in out)))


def solve(a, b):
	b = [int(x) for x in str(b)]
	a = [int(x) for x in str(a)]
	b.reverse()
	a.reverse()
	ans = ''
	bind = 0
	for i in range(len(a)):
		if bind < len(b) and b[bind] == a[i]:
			ans += '0'
			bind += 1
		elif bind < len(b) and b[bind] > a[i]:
			ans += str(b[bind] - a[i])
			bind += 1
		elif bind < len(b) - 1 and b[bind] < a[i] and (b[bind + 1] == 1):
			ans += str(b[bind + 1] * 10 + b[bind] - a[i])
			bind += 2
		else:
			return -1
	while bind < len(b):
		ans += str(b[bind])
		bind += 1
	return int(ans[::-1])
for i in range(int(input())):
	(a, b) = input().split()
	print(solve(a, b))


def ss(a, s):
	i = len(s) - 1
	j = len(a) - 1
	l = []
	if len(s) < len(a):
		return -1
	if (len(s) == 1) & (len(a) == 1):
		if int(s) >= int(a):
			return int(s) - int(a)
		else:
			return -1
	while (i >= 0) & (j >= 0):
		if int(s[i]) >= int(a[j]):
			l.append(str(int(s[i]) - int(a[j])))
			i = i - 1
			j = j - 1
		elif i == 0:
			if int(s[i]) >= int(a[j]):
				l.append(str(int(s[i]) - int(a[j])))
				i = i - 1
				j = j - 1
			else:
				return -1
		elif (int(s[i - 1:i + 1]) - int(a[j])) // 10 > 0:
			return -1
		elif int(s[i - 1:i + 1]) - int(a[j]) < 0:
			return -1
		else:
			l.append(str(int(s[i - 1:i + 1]) - int(a[j])))
			i = i - 2
			j = j - 1
	if (i == -1) & (j > -1):
		return -1
	elif (i > -1) & (j == -1):
		s1 = s[:i + 1]
		s1 = s1[::-1]
		l1 = list(s1)
		l.extend(l1)
		l = l[::-1]
		return int(''.join(l))
	else:
		l = l[::-1]
		return int(''.join(l))
	return 0
t = int(input())
ls = []
for x in range(t):
	s = str(input())
	ls.append(s)
la = []
for y in ls:
	x = y.split(' ')
	a = x[0]
	s = x[1]
	ans = ss(a, s)
	la.append(ans)
for x in la:
	print(x)


def f(a, b, s):
	s1 = ''
	l1 = len(a)
	l2 = len(b)
	s1 = ''
	if l1 < l2:
		a = (l2 - l1) * '0' + a
	elif l1 > l2:
		b = (l1 - l2) * '0' + b
	for i in range(len(a) - 1, -1, -1):
		x1 = int(a[i])
		y1 = int(b[i])
		s1 = str(x1 + y1) + s1
	return s == s1
t = int(input())
for i in range(0, t):
	(a, s) = map(str, input().split())
	j = len(a) - 1
	k = len(s) - 1
	b = ''
	flag = True
	while j >= 0 and k >= 0:
		x1 = int(s[k])
		x2 = int(a[j])
		if x1 >= x2:
			b = str(x1 - x2) + b
			k -= 1
			j -= 1
		else:
			u = k - 1
			while u > 0 and int(s[u:k + 1]) < x2:
				u -= 1
			if u < 0 or int(s[u:k + 1]) < x2:
				flag = False
				break
			else:
				x3 = int(s[u:k + 1])
				b = str(x3 - x2) + b
				k -= 2
				j -= 1
	if j == -1 and k != -1:
		b = s[:k + 1] + b
	if flag == False:
		print(-1)
	elif f(a, b, s):
		print(int(b))
	else:
		print(-1)


import sys, array, bisect, collections, heapq, itertools, math, functools
sys.setrecursionlimit(100000)

def _r():
	return sys.stdin.buffer.readline()

def rs():
	return _r().decode('ascii').strip()

def rn():
	return int(_r())

def rnt():
	return tuple(map(int, _r().split()))

def rnl():
	return list(rnt())

def rna():
	return array.array('q', rnt())

def pnl(l):
	print(' '.join(map(str, l)))

def solve(a, s):
	a = list(map(int, a.zfill(len(s))[::-1]))
	s = list(map(int, s[::-1]))
	i = j = 0
	b = []
	while j < len(s):
		if a[i] <= s[j]:
			b.append(s[j] - a[i])
			i += 1
			j += 1
		else:
			if j + 1 == len(s) or s[j + 1] != 1:
				return -1
			b.append(10 + s[j] - a[i])
			i += 1
			j += 2
	return ''.join(map(str, reversed(b))).lstrip('0') if sum(a[i:]) == 0 and j == len(s) else -1
for _ in range(rn()):
	print(solve(*rs().split()))


def add(a, b):
	ret = ''
	while len(a) < len(b):
		a = '0' + a
	while len(b) < len(a):
		b = '0' + b
	ret = ''
	for i in range(len(a) - 1, -1, -1):
		ret = str(int(a[i]) + int(b[i])) + ret
	return ret

def solve():
	(a, s) = input().split()
	i = len(a) - 1
	j = len(s) - 1
	ans = ''
	while i >= 0 and j >= 0:
		tmp = ''
		while j >= 0 and (tmp == '' or int(tmp) < int(a[i])):
			tmp = s[j] + tmp
			j -= 1
		if tmp == '' or int(tmp) < int(a[i]):
			ans = '-1'
			break
		else:
			ans = str(int(tmp) - int(a[i])) + ans
		i -= 1
	if i > -1:
		ans = '-1'
	else:
		while j >= 0:
			ans = s[j] + ans
			j -= 1
	if ans != '-1':
		if add(a, ans) != s:
			ans = '-1'
	print(int(ans))
t = 1
t = int(input())
for tc in range(t):
	solve()


t = int(input())
for _ in range(t):
	(a, s) = input().split()
	n = len(s)
	m = len(a)
	j = n - 1
	i = m - 1
	b = ''
	flag = 0
	while j >= 0 and i >= 0:
		x = int(s[j])
		y = int(a[i])
		if x >= y:
			b += str(x - y)
			j -= 1
			i -= 1
		elif j - 1 >= 0 and i >= 0:
			p = s[j - 1]
			q = s[j]
			x = int(p + q)
			if int(x - y) > 9 or int(x - y) < 0:
				flag = 1
				break
			b += str(x - y)
			j -= 2
			i -= 1
		else:
			flag = 1
			break
	if flag or i >= 0:
		print(-1)
	else:
		while j >= 0:
			b += s[j]
			j -= 1
		print(int(b[::-1]))


result = []

def findb(a, s):
	b = []
	(stacks, lengths) = (list(str(s)), len(str(s)))
	(stacka, lengtha) = (list(str(a)), len(str(a)))
	while lengtha > 0 and lengths > 0:
		if int(stacka[lengtha - 1]) > int(stacks[lengths - 1]):
			if lengths < 2:
				return -1
			el = int(''.join(stacks[lengths - 2:lengths])) - int(stacka[lengtha - 1])
			if 0 < el < 10:
				b.append(el)
			else:
				return -1
			lengtha -= 1
			lengths -= 2
		else:
			b.append(int(stacks[lengths - 1]) - int(stacka[lengtha - 1]))
			lengtha -= 1
			lengths -= 1
	if lengtha > 0 and lengths == 0:
		return -1
	b = list(map(str, b))
	return (''.join(stacks[:lengths]) + ''.join(b[::-1])).lstrip('0')
for _ in range(int(input())):
	(a, s) = list(map(int, input().split()))
	result.append(str(findb(a, s)))
print('\n'.join(result))


t = int(input())
for test in range(t):
	(a, s) = [x.strip() for x in input().split(' ')]
	while len(a) < len(s):
		a = '0' + a
	b = ''
	while len(s) > 0 and len(a) > 0:
		if int(s[-1]) >= int(a[-1]):
			b = str(int(s[-1]) - int(a[-1])) + b
			s = s[:-1]
			a = a[:-1]
		elif len(s) == 1 or s[-2] != '1':
			break
		else:
			b = str(int(s[-2:]) - int(a[-1])) + b
			s = s[:-2]
			a = a[:-1]
	if (len(s) == 0 or int(s) == 0) and (len(a) == 0 or int(a) == 0):
		print(b.lstrip('0'))
	else:
		print(-1)


import math, sys
input = sys.stdin.readline
S = lambda : input().rstrip()
I = lambda : int(S())
M = lambda : map(int, S().split())
L = lambda : list(M())
mod1 = 1000000007
mod2 = 998244353
for _ in range(I()):
	(a, s) = input().split()
	i = len(a) - 1
	j = len(s) - 1
	ans = ''
	f = 0
	while i >= 0 and j >= 0:
		if int(a[i]) <= int(s[j]):
			ans += str(int(s[j]) - int(a[i]))
			i -= 1
			j -= 1
		elif j == 0 or s[j - 1] != '1':
			f = 1
			break
		else:
			p = int(s[j - 1])
			q = int(s[j])
			ans += str(10 * p + q - int(a[i]))
			i -= 1
			j -= 2
	if j < 0 and i >= 0 or f == 1:
		print(-1)
		continue
	ans = ans[::-1]
	if j >= 0:
		ans = s[:j + 1] + ans
	print(int(ans))


def get_bad_sum(a, b):
	if '-1' in [a, b]:
		return '-1'
	a = a[::-1]
	b = b[::-1]
	res = []
	i = 0
	while i < max(len(a), len(b)):
		if i < min(len(a), len(b)):
			res.append(str(int(a[i]) + int(b[i])))
		else:
			if i < len(a):
				res.append(str(a[i]))
			if i < len(b):
				res.append(str(b[i]))
		i += 1
	return ''.join(res[::-1]).lstrip('0')

def get_sol(a, s):
	sr = len(s) - 1
	sl = len(s) - 1
	ar = len(a) - 1
	al = len(a) - 1
	res = []
	while True:
		if al < 0:
			return ''.join(res[::-1]).lstrip('0')
		if sl < 0:
			return '-1'
		if int(s[sl:sr + 1]) < int(a[al]):
			sl -= 1
			if sl < 0:
				return -1
		else:
			res.append(str(int(s[sl:sr + 1]) - int(a[al])))
			sl -= 1
			sr = sl
			al -= 1
			ar -= al
			if al < 0 and sl >= 0:
				res = s[0:sl + 1] + ''.join(res[::-1])
				return res.lstrip('0')
for t in range(int(input())):
	(a, s) = map(str, input().split())
	res = get_sol(a, s)
	if s == get_bad_sum(str(a), str(res)):
		print(res)
	else:
		print('-1')


for _ in range(int(input())):
	(a, s) = input().split()
	i = len(a) - 1
	j = len(s) - 1
	if i > j:
		print(-1)
	elif i == j:
		if all((a[d] <= s[d] for d in range(len(s)))):
			print(int(s) - int(a))
		else:
			print(-1)
	else:
		ans = []
		while True:
			if i < 0:
				da = '0'
			else:
				da = a[i]
			ds = s[j]
			if int(da) > int(ds):
				j -= 1
				if j < 0:
					break
				elif s[j] == '1':
					ds = s[j] + ds
				else:
					break
			db = str(int(ds) - int(da))
			ans.append(db)
			i -= 1
			j -= 1
			if j < 0:
				break
		if i < 0:
			print(int(''.join(reversed(ans))))
		else:
			print(-1)


import sys
import math
from bisect import bisect_right as br
from collections import deque
from itertools import combinations as cb

def int_arr():
	return list(map(int, sys.stdin.readline().strip().split()))

def str_arr():
	return list(map(str, sys.stdin.readline().strip().split()))

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	(a, s) = int_arr()
	ans = ''
	while a > 0 or s > 0:
		l = a % 10
		r = s % 10
		a //= 10
		s //= 10
		if r < l:
			x = s % 10
			s //= 10
			if x != 1:
				ans = -1
				break
			r += 10
		ans = str(r - l) + ans
	print(int(ans))


def solution(a, s):
	b = ''
	i = -1
	j = -1
	while i >= -1 * len(s):
		char_s = s[i]
		try:
			char_a = a[j]
		except:
			char_a = '0'
		if char_s < char_a:
			try:
				char_s = s[i - 1] + char_s
				i -= 1
			except:
				return -1
		int_s = int(char_s)
		int_a = int(char_a)
		int_b = int_s - int_a
		if int_b < 0:
			return -1
		b = str(int_b) + b
		i -= 1
		j -= 1
	true_answer = wrong_sum(a, b)
	if true_answer == s:
		return b.lstrip('0')
	else:
		return -1

def wrong_sum(a, b):
	len_a = len(a)
	len_b = len(b)
	if len_a > len_b:
		b = '0' * (len_a - len_b) + b
	elif len_b > len_a:
		a = '0' * (len_b - len_a) + a
	i = -1
	s = ''
	while -1 * i <= len(a):
		s = str(int(a[i]) + int(b[i])) + s
		i -= 1
	return s
t = int(input())
for _ in range(t):
	(a, s) = input().split()
	print(solution(a, s))


def given():
	a = list(map(int, input().split()))
	return a

def main():
	anisha = given()[0]
	while anisha > 0:
		anisha -= 1
		(a, s) = list(input().split())
		b = ''
		n = len(s)
		m = len(a)
		if n > m:
			a = '0' * (n - m) + a
		f = 1
		while s and a:
			if int(s[-1]) >= int(a[-1]):
				b += str(int(s[-1]) - int(a[-1]))
				s = s[:-1]
				a = a[:-1]
			elif int(s[-2:]) >= int(a[-1]):
				cha = int(s[-2:]) - int(a[-1])
				if cha > 9:
					f = 0
					break
				b += str(cha)
				s = s[:-2]
				a = a[:-1]
			else:
				f = 0
				break
		a = a.lstrip('0')
		if len(a) > len(s):
			f = 0
		if f:
			b = int(b[::-1])
			print(b)
		else:
			print(-1)
main()


def solve(a, s):
	ans = ''
	na = len(a)
	ns = len(s)
	i = na - 1
	j = ns - 1
	while i > -1 and j > -1:
		if a[i] > s[j]:
			c = int(s[j]) - int(a[i]) + 10
			if j - 1 < 0 or s[j - 1] != '1':
				return '-1'
			j += -2
		else:
			c = int(s[j]) - int(a[i])
			j += -1
		ans = str(c) + ans
		i += -1
	if i > -1:
		return '-1'
	if j > -1:
		ans = s[0:j + 1] + ans
	while ans[0] == '0':
		ans = ans[1:]
	return ans
test = int(input())
for t in range(0, test):
	(a, s) = input().split()
	print(solve(a, s))


for _ in range(int(input())):
	(a, s) = map(int, input().split())
	ans = ''
	tr = 0
	if a > s:
		print(-1)
	else:
		while s > 0:
			if s == 0:
				tr = -1
				break
			else:
				x = a % 10
				y = s % 10
				if y >= x:
					ans = str(y - x) + ans
					a = a // 10
					s = s // 10
				else:
					y = s % 100
					if y - x >= 10 or y < x:
						tr = -1
						break
					else:
						a = a // 10
						s = s // 100
						ans = str(y - x) + ans
		if tr == 0 and a == 0:
			print(int(ans))
		else:
			print(-1)


for _ in range(int(input())):
	(a, c) = input().split()
	while a and a[0] == '0':
		a = a[1:]
	while c and c[0] == '0':
		c = c[1:]
	(i, j) = (len(c) - 1, len(a) - 1)
	t = 0
	if len(c) < len(a) or c == a:
		print(-1)
		continue
	s = ''
	br = False
	while j > -1:
		if i < j:
			print(-1)
			br = True
			break
		if c[i] < a[j]:
			if i <= 0 or c[i - 1] == '0' or int(c[i - 1:i + 1]) > 18:
				print(-1)
				br = True
				break
			s = str(int(c[i - 1:i + 1]) - int(a[j])) + s
			(i, j) = (i - 2, j - 1)
		else:
			s = str(int(c[i]) - int(a[j])) + s
			(i, j) = (i - 1, j - 1)
	if br:
		continue
	if i > -1:
		s = c[:i + 1] + s
	while len(s) > 1 and s[0] == '0':
		s = s[1:]
	print(s)


t = int(input())
for i in range(0, t):
	(a_str, s_str) = input().split()
	a1 = list(map(int, list(a_str)))
	s1 = list(map(int, list(s_str)))
	a1 = a1[::-1]
	s1 = s1[::-1]
	n = 0
	i = 0
	j = 0
	k = 0
	p = 0
	c1 = len(s1)
	c2 = len(a1)
	while j < len(s1):
		if i == len(a1):
			d = s1[j]
			n += d * 10 ** p
			j += 1
			p += 1
		elif i <= len(a1) - 1:
			d = s1[j] - a1[i]
			if d >= 0:
				n += d * 10 ** i
				i += 1
				j += 1
				p = i
				c1 -= 1
				c2 -= 1
			elif d < 0:
				if j < len(s1) - 1 and s1[j + 1] == 1:
					d = 10 + s1[j] - a1[i]
					n += d * 10 ** i
					i += 1
					j += 2
					p = i
					c1 -= 2
					c2 -= 1
				else:
					k = 1
					i += 1
					p = i
					j += 1
	if c2 > c1:
		k = 1
	if k == 1:
		print(-1)
	else:
		print(n)


import sys, os, io
input = sys.stdin.readline
PI = 3.141592653589793
INF = float('inf')
MOD = 1000000007

def bin32(num):
	return '{0:032b}'.format(num)

def add(x, y):
	return (x + y) % MOD

def sub(x, y):
	return (x - y + MOD) % MOD

def mul(x, y):
	return x * y % MOD

def gcd(x, y):
	if y == 0:
		return x
	return gcd(y, x % y)

def lcm(x, y):
	return x * y // gcd(x, y)

def power(x, y):
	res = 1
	x %= MOD
	while y != 0:
		if y & 1:
			res = mul(res, x)
		y >>= 1
		x = mul(x, x)
	return res

def mod_inv(n):
	return power(n, MOD - 2)

def prob(p, q):
	return mul(p, power(q, MOD - 2))

def ii():
	return int(input())

def li():
	return [int(i) for i in input().split()]

def ls():
	return [i for i in input().split()]

def check(a, x):
	b = a[:]
	b.reverse()
	b = ''.join(b)
	if int(b) >= x:
		return 1
	return 0
for t in range(ii()):
	t += 1
	(a, s) = ls()
	b = []
	a = list(a)
	ind = len(s) - 1
	flag = 1
	for i in range(len(a) - 1, -1, -1):
		x = int(a[i])
		if ind < 0:
			flag = 0
			break
		tmp = [s[ind]]
		ind -= 1
		while ind >= 0 and check(tmp, x) == 0:
			tmp.append(s[ind])
			ind -= 1
		if check(tmp, x):
			tmp.reverse()
			tmp = ''.join(tmp)
			ans = str(int(tmp) - x)
			if len(ans) == 1:
				b.append(ans)
			else:
				flag = 0
				break
		else:
			flag = 0
			break
	if flag:
		while ind >= 0:
			b.append(s[ind])
			ind -= 1
		b.reverse()
		b = ''.join(b)
		print(int(b))
	else:
		print(-1)


ll = lambda : map(int, input().split())
t = lambda : int(input())
ss = lambda : input()
lx = lambda x: map(int, input().split(x))
yy = lambda : print('YES')
nn = lambda : print('NO')
from math import log10, log2, ceil, factorial as fac, gcd, inf, sqrt, log
from bisect import bisect_right as br, bisect_left as bl, insort
from collections import Counter
mod = 10 ** 9 + 7

def Nprime(n):
	if n == 2 or n == 3:
		return 0
	if n == 1:
		return 1
	i = 2
	while i * i <= n:
		if n % i == 0:
			return 1
		i += 1
	return 0

def sum_(a, n):
	d = 4
	s = n * (2 * a + (n - 1) * d) // 2
	return s

def aux(x, y):
	if x == 'a' and y == 'z':
		return 1
	if y == 'a' and x == 'z':
		return 1
	return abs(ord(x) - ord(y))

def aux1(x, y):
	if x == 'a' and y == 'z':
		return 1
	if y == 'z' and x == 'a':
		return 1
	return ord('z') - ord(y) + ord(x) - ord('a')
for _ in range(t()):
	(a, s) = ss().split()
	(n, m) = (len(a), len(s))
	i = n - 1
	j = m - 1
	b = ''
	fl = 0
	while i >= 0 and j >= 0:
		if a[i] > s[j]:
			temp = int(s[j - 1] + s[j]) - int(a[i])
			if temp < 0:
				fl = 1
				break
			b = str(temp) + b
			j -= 2
			i -= 1
		else:
			temp = int(s[j]) - int(a[i])
			b = str(temp) + b
			j -= 1
			i -= 1
	if fl:
		print(-1)
	else:
		k = 0
		while j >= 0:
			b = s[j] + b
			j -= 1
		while i >= 0:
			b = a[i] + b
			i -= 1
		s1 = ''
		a = '0' * (max(len(a), len(b)) - len(a)) + a
		b = '0' * (max(len(a), len(b)) - len(b)) + b
		i = len(a) - 1
		while i >= 0:
			s1 = str(int(a[i]) + int(b[i])) + s1
			i -= 1
		if int(s1) == int(s):
			print(int(b))
		else:
			print(-1)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
LOGN = 20
INF = 10 ** 9 + 5
MOD = 10 ** 9 + 7

def solve():
	(a, s) = map(str, input().split())
	b = []
	ai = len(a) - 1
	si = len(s) - 1
	while ai >= 0 and si >= 0:
		if int(s[si]) >= int(a[ai]):
			b.append(int(s[si]) - int(a[ai]))
			si -= 1
			ai -= 1
		elif si - 1 >= 0 and 0 <= int(s[si - 1:si + 1]) - int(a[ai]) <= 9:
			b.append(int(s[si - 1:si + 1]) - int(a[ai]))
			si -= 2
			ai -= 1
		else:
			print(-1)
			return
	if ai >= 0:
		print(-1)
		return
	while si >= 0:
		b.append(s[si])
		si -= 1
	print(int(''.join([str(c) for c in reversed(b)])))
for _ in range(int(input())):
	solve()


import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
from collections import defaultdict
BUFSIZE = 8192

def bootstrap(f, stack=[]):

	def fun(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return fun

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math
from collections import deque
t = int(input())
for _ in range(t):
	(a, s) = map(str, input().split())
	l1 = len(a)
	l2 = len(s)
	i = l1 - 1
	j = l2 - 1
	ans = []
	poss = 1
	while i >= 0 and j >= 0:
		curr1 = int(a[i])
		curr2 = int(s[j])
		if curr1 > curr2:
			if j >= 1:
				req = int(s[j - 1:j + 1]) - curr1
				if req >= 1 and req <= 9:
					ans.append(str(req))
					j += -2
					i += -1
				else:
					poss = 0
					break
			else:
				poss = 0
				break
		else:
			ans.append(str(curr2 - curr1))
			i += -1
			j += -1
	while j >= 0:
		ans.append(str(s[j]))
		j += -1
	if i < 0 and j < 0:
		pass
	else:
		poss = 0
	if poss:
		l = len(ans)
		while l > 1:
			if ans[-1] == '0':
				ans.pop()
			else:
				break
			l += -1
		print(''.join(ans[::-1]))
	else:
		print(-1)


for _ in range(int(input())):
	(a, s) = map(str, input().strip().split())
	(i, j) = (len(a) - 1, len(s) - 1)
	an = ''
	while j > -1:
		if i >= 0:
			t = int(s[j]) - int(a[i])
		else:
			an = s[:j + 1] + an
			break
		if t >= 0:
			an = str(t) + an
			(i, j) = (i - 1, j - 1)
		elif j == 0:
			an = '-1'
			break
		elif s[j - 1] == '1':
			an = str(t + 10) + an
			(i, j) = (i - 1, j - 2)
		else:
			an = '-1'
			break
		if i > j:
			an = '-1'
			break
	print(int(an))


for _ in range(int(input())):
	(a, b) = input().split()
	if len(b) < len(a):
		print(-1)
		continue
	i = len(a) - 1
	j = len(b) - 1
	possible = True
	ans = ''
	while i >= 0:
		if j >= 0 and b[j] >= a[i]:
			ans += str(int(b[j]) - int(a[i]))
			j -= 1
		elif j > 0 and 0 < int(b[j - 1:j + 1]) - int(a[i]) < 10:
			ans += str(int(b[j - 1:j + 1]) - int(a[i]))
			j -= 2
		else:
			possible = False
			break
		i -= 1
	if not possible:
		print(-1)
		continue
	sr = ans[::-1]
	if j >= 0:
		sr = b[:j + 1] + sr
	sr = str(int(sr))
	print(sr)


t = int(input())
while t:
	t -= 1
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	c = ''
	f = 1
	while a and b:
		x = b % 10 - a % 10
		if x >= 0:
			c += str(x)
			b = b // 10
			a = a // 10
		else:
			x = b % 100 - a % 10
			if 0 < x < 10:
				c += str(x)
				b = b // 100
				a = a // 10
			else:
				f = 0
				break
	if a or f == 0:
		print(-1)
	elif b:
		c += str(b)[::-1]
		print(c[::-1].lstrip('0'))
	else:
		print(c[::-1].lstrip('0'))


import sys
import bisect
import math
from collections import deque
input = lambda : sys.stdin.readline().strip()
mod = 10 ** 9 + 7

def solve():
	(a, s) = input().split()
	if len(a) > len(s):
		return -1
	b = ''
	(i, j) = (len(a) - 1, len(s) - 1)
	while i >= 0 and j >= 0:
		if a[i] <= s[j]:
			b = str(int(s[j]) - int(a[i])) + b
			(i, j) = (i - 1, j - 1)
		else:
			if j - 1 < 0:
				return -1
			if int(s[j - 1] + s[j]) - int(a[i]) > 9 or int(s[j - 1] + s[j]) - int(a[i]) < 0:
				return -1
			b = str(int(s[j - 1] + s[j]) - int(a[i])) + b
			(i, j) = (i - 1, j - 2)
	if i >= 0:
		return -1
	while j >= 0:
		b = s[j] + b
		j -= 1
	return int(b)
t = 1
t = int(input())
for _ in range(t):
	print(solve())


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	(a, s) = stdin.readline().split()
	b = ''
	while len(s) > 0:
		if len(a) == 0:
			b += s[-1]
			s = s[:-1]
		elif int(s[-1]) - int(a[-1]) >= 0:
			b += str(int(s[-1]) - int(a[-1]))
			s = s[:-1]
			a = a[:-1]
		elif len(s) > 1 and 9 >= int(s[-2:]) - int(a[-1]) >= 0:
			b += str(int(s[-2:]) - int(a[-1]))
			s = s[:-2]
			a = a[:-1]
		else:
			b = '1-'
			break
	if len(a) > 0:
		b = '1-'
	print(int(b[::-1]))


import math
from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(a, s) = map(str, input().strip().split())
	n = len(a)
	m = len(s)
	flag = 1
	res = ''
	j = m - 1
	for i in range(n - 1, -1, -1):
		if a[i] > s[j]:
			if j - 1 >= 0 and s[j - 1] != '1' or j - 1 < 0:
				flag = 0
				break
			else:
				res = res + str(int(s[j - 1:j + 1]) - int(a[i]))
				j -= 2
		else:
			res = res + str(int(s[j]) - int(a[i]))
			j -= 1
		if i > 0 and j < 0:
			flag = 0
			break
		if j < 0:
			break
	if flag == 0:
		print(-1)
	else:
		for i in range(j, -1, -1):
			res = res + s[i]
		x = 0
		for i in range(len(res)):
			if res[i] != '0':
				x = i
		print(res[x::-1])


import sys
import math
from collections import deque, Counter
from sys import stdin
int1 = lambda x: int(x) - 1
stinput = lambda : stdin.readline()[:-1]
ii = lambda : int(stinput())
mi = lambda : map(int, stdin.readline().split())
li = lambda : list(mi())
mi1 = lambda : map(int1, stdin.readline().split())
li1 = lambda : list(mi1())
mis = lambda : map(str, stdin.readline().split())
lis = lambda : list(mis())
from collections import defaultdict
import heapq
mod = 10 ** 9 + 7
Mod = 998244353
INF = 10 ** 18
ans = 0
t = ii()

def solve(a, s):
	if len(a) == 0:
		return [s]
	if len(s) == 0:
		return False
	if int(a[-1]) <= int(s[-1]):
		x = solve(a[:-1], s[:-1])
		if x:
			y = int(s[-1]) - int(a[-1])
			x.append(str(y))
			return x
		else:
			return False
	elif len(s) >= 2 and s[-2] == '1':
		x = solve(a[:-1], s[:-2])
		if x:
			y = int(s[-2] + s[-1]) - int(a[-1])
			x.append(str(y))
			return x
		else:
			return False
	return False
for _ in range(t):
	seen = {}
	(a, s) = mis()
	ans = solve(a, s)
	if ans:
		print(int(''.join(ans)))
	else:
		print(-1)


def find(a, s):
	i = len(s) - 1
	j = len(a) - 1
	res = ''
	c = 0
	while i > -1 and j > -1:
		if int(s[i]) >= int(a[j]) and int(s[i]) - int(a[j]) < 10:
			res += str(int(s[i]) - int(a[j]))
			i -= 1
			j -= 1
		elif i > 0 and int(s[i - 1:i + 1]) > int(a[j]) and (int(s[i - 1:i + 1]) - int(a[j]) < 10):
			res += str(int(s[i - 1:i + 1]) - int(a[j]))
			i -= 2
			j -= 1
			c += 1
		else:
			return -1
	if i >= j:
		return int(s[:i + 1] + res[::-1])
	else:
		return -1
r = int(input())
res = []
for i in range(r):
	arr = input().split()
	res.append(find(arr[0], arr[1]))
for i in res:
	print(i)


import sys
import math
import heapq
import bisect
from collections import Counter
from collections import defaultdict
from io import BytesIO, IOBase
from itertools import permutations
import string

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None
		self.BUFSIZE = 8192

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def get_int():
	return int(input())

def get_ints():
	return list(map(int, input().split(' ')))

def get_int_grid(n):
	return [get_ints() for _ in range(n)]

def get_str():
	return input().strip()

def get_strs():
	return get_str().split(' ')

def flat_list(arr):
	return [item for subarr in arr for item in subarr]

def yes_no(b):
	if b:
		return 'YES'
	else:
		return 'NO'
t = get_int()
while t > 0:
	(x, sum) = get_ints()
	flag = False
	if x > sum:
		print(-1)
	elif x == 0:
		print(sum)
	elif x == sum:
		print(0)
	else:
		(ans, p) = (0, 0)
		while sum > 0:
			(i, j) = (x % 10, sum % 10)
			if j >= i:
				ans += 10 ** p * (j - i)
				x //= 10
				sum //= 10
				p += 1
			else:
				j = sum % 100
				if j - i > 9 or j - i < 0:
					flag = True
					break
				else:
					ans += 10 ** p * (j - i)
					x //= 10
					sum //= 100
					p += 1
	if x > 0 or flag:
		print(-1)
	else:
		print(ans)
	t -= 1


t = int(input())
for _ in range(t):
	(a, s) = map(str, input().split())
	m = len(a)
	n = len(s)
	ans = ''
	check = 1
	i = n - 1
	j = m - 1
	while i >= 0 and j >= 0:
		if int(s[i]) - int(a[j]) >= 0:
			ans = ans + str(int(s[i]) - int(a[j]))
			i = i - 1
			j = j - 1
		elif i - 1 >= 0:
			if 0 <= int(s[i - 1:i + 1]) - int(a[j]) <= 9:
				ans = ans + str(int(s[i - 1:i + 1]) - int(a[j]))
				i = i - 2
				j = j - 1
			else:
				check = 0
				break
		else:
			check = 0
			break
	while i >= 0:
		ans = ans + s[i]
		i = i - 1
	if i != -1 or j != -1:
		check = 0
	if check:
		ans = int(ans[::-1])
		print(ans)
	else:
		print(-1)


for _ in range(int(input())):
	(w1, w2) = input().split()
	n = len(w1)
	m = len(w2)
	i = n - 1
	j = m - 1
	ans = ''
	flag = 1
	while i >= 0:
		if j >= 0 and int(w2[j]) >= int(w1[i]):
			ans += str(int(w2[j]) - int(w1[i]))
			i -= 1
			j -= 1
		elif j > 0 and 0 < int(w2[j - 1] + w2[j]) - int(w1[i]) < 10:
			ans += str(int(w2[j - 1] + w2[j]) - int(w1[i]))
			i -= 1
			j -= 2
		else:
			print(-1)
			flag = 0
			break
	if flag:
		if j >= 0:
			print(str(int(w2[0:j + 1] + ans[::-1])))
		else:
			print(str(int(ans[::-1])))


def dumb_subtract(additive, dumb_sum):
	result_string = ''
	additive_stack = list(additive)
	sum_stack = list(dumb_sum)
	while len(sum_stack) >= len(additive_stack) > 0:
		sum_chunk = sum_stack[-2:] if sum_stack[-1] < additive_stack[-1] else sum_stack[-1:]
		additive_chunk = additive_stack.pop()
		for _ in sum_chunk:
			sum_stack.pop()
		result_chunk = int(''.join(sum_chunk)) - int(''.join(additive_chunk))
		if result_chunk > 9 or result_chunk < 0:
			return '-1'
		result_string = str(result_chunk) + result_string
	if len(additive_stack) > 0:
		return '-1'
	return (''.join(sum_stack) + result_string).lstrip('0')

def solve():
	number_of_tests = int(input())
	for test in range(number_of_tests):
		(additive, dumb_sum) = input().split(' ')
		print(dumb_subtract(additive, dumb_sum))
solve()


def f(a, s):
	b = ''
	flag = True
	while a != 0:
		if s == 0:
			flag = False
			break
		if s % 10 >= a % 10:
			b = str(s % 10 - a % 10) + str(b)
			s //= 10
			a //= 10
		elif (s % 100 - s % 10) / 10 != 1:
			flag = False
			break
		else:
			b = str(10 + s % 10 - a % 10) + str(b)
			s //= 100
			a //= 10
	if flag:
		if str(s) == '0':
			s = ''
		k = str(s) + b
		if k[0] == '0':
			while k[0] == '0':
				k = k[1:]
		return k
	else:
		return -1
n = int(input())
for i in range(n):
	(a, s) = map(int, input().split())
	print(f(a, s))


from math import *
from bisect import bisect_left as bl
from bisect import bisect_right as br
from collections import Counter as ctr
from collections import deque as dq
from array import array
from re import search
li = lambda : list(map(int, input().split()))
arr = lambda a: array('i', a)
bi = lambda n: bin(n).replace('0b', '')
yn = lambda f: print('NYOE S'[f::2])
sbstr = lambda a, s: search('.*'.join(a), s)

def solve():
	for _ in range(int(input())):
		(s, a) = input()[::-1].split()
		up = len(s) - len(a)
		sm = []
		i = 0
		j = 0
		f = True
		while i < len(s) and j < len(a):
			if int(s[i]) < int(a[j]):
				if i < len(s) - 1 and s[i + 1] == '1':
					sm += [s[i + 1] + s[i]]
					i += 2
					j += 1
				else:
					f = False
					break
			else:
				sm += [s[i]]
				i += 1
				j += 1
		if i < len(s):
			sm += [s[i:][::-1]]
			a += '0'
		if not f or len(sm) != len(a):
			print(-1)
			continue
		ans = []
		for i in range(len(a)):
			t = int(sm[i]) - int(a[i])
			if t < 0:
				f = False
				break
			else:
				ans.append(str(t))
		if not f:
			print(-1)
		else:
			print(int(''.join(ans[::-1])))
solve()


tests = int(input())
for _ in range(tests):
	(a, s) = [x for x in input().split()]
	b = ''
	j = len(s) - 1
	n = len(a)
	f = 0
	for i in range(n):
		if j == -1:
			f = 1
			break
		elif a[n - i - 1] <= s[j]:
			c = int(s[j]) - int(a[n - 1 - i])
			b = b + chr(c + 48)
			j -= 1
		elif j == 0:
			f = 1
			break
		else:
			c = int(s[j - 1:j + 1]) - int(a[n - 1 - i])
			if c > 9 or c < 0:
				f = 1
				break
			b = b + chr(c + 48)
			j -= 2
	if f == 1:
		print(-1)
	else:
		while j >= 0:
			c = int(s[j])
			b = b + chr(c + 48)
			j -= 1
		print(int(''.join(reversed(b))))


import math
t = int(input())
while t > 0:
	t -= 1
	(a, s) = map(int, input().split())
	b = ''
	ans = True
	while s:
		if a > s or ans == False:
			ans = False
			break
		x = a % 10
		y = s % 10
		z = s % 100
		if y >= x:
			if y - x >= 10:
				ans = False
			b += str(y - x)
			s = s // 10
			a = a // 10
		else:
			if z - x >= 10:
				ans = False
			b += str(z - x)
			s = s // 100
			a = a // 10
	if ans == False or '-' in b:
		print(-1)
	else:
		print(int(b[::-1]))


import math
res = []
t = int(input())
for i in range(t):
	(a, s) = map(int, input().split())
	degree = 1
	b = 0
	while a > 0 and s > 0:
		if a % 10 > s % 10:
			if s % 100 // 10 == 1:
				b = b + (s % 100 - a % 10) * degree
				degree = degree * 10
				s = s // 100
				a = a // 10
			else:
				b = -1
				break
		else:
			b = b + (s % 10 - a % 10) * degree
			degree = degree * 10
			s = s // 10
			a = a // 10
	if s > 0 and a == 0:
		b = b + s * degree
	if s == 0 and a > 0:
		b = -1
	res.append(b)
for r in res:
	print(r)


def solve(a, s):
	b = []
	(a_i, s_i) = (len(a) - 1, len(s) - 1)
	curr_a = 0
	while a_i >= 0 and s_i >= 0:
		curr_a = int(a[a_i])
		a_i -= 1
		curr_s = int(s[s_i])
		s_i -= 1
		if curr_s < curr_a and s_i >= 0:
			curr_s = curr_s + int(s[s_i]) * 10
			s_i -= 1
		if curr_s - curr_a < 0 or curr_s - curr_a > 9:
			return '-1'
		b.append(str(curr_s - curr_a))
	if a_i < 0:
		while s_i >= 0:
			b.append(str(s[s_i]))
			s_i -= 1
	elif s_i < 0:
		return '-1'
	start_b = len(b) - 1
	while start_b > 0 and b[start_b] == '0':
		start_b -= 1
	return ''.join(b[start_b::-1])
t = int(input())
for _ in range(t):
	(a, s) = input().split()
	print(solve(a, s))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(a, b) = input()[:-1].split()
	(i, j) = (x, y) = (len(a), len(b))
	s = ''
	ans = 0
	while j > 0:
		if i > 0:
			i -= 1
			j -= 1
			if b[j] >= a[i]:
				s += str(int(b[j]) - int(a[i]))
			elif j > 0 and b[j - 1] == '1':
				s += str(int(b[j - 1:j + 1]) - int(a[i]))
				j -= 1
			else:
				ans = -1
				break
		if i == 0:
			break
	s = b[:max(j, 0)] + s[::-1]
	if i > 0 or ans == -1:
		print(-1)
	else:
		print(s.lstrip('0'))


from collections import defaultdict, Counter, deque
from math import sqrt, log10, log, floor, factorial, gcd
from bisect import bisect_left, bisect_right, insort
from itertools import permutations, combinations
import sys, io, os
input = sys.stdin.readline
inf = float('inf')
mod = 10 ** 9 + 7

def yn(a):
	print('YES' if a else 'NO')
ceil = lambda a, b: (a + b - 1) // b
t = int(input())
for i in range(t):
	(a, s) = [list(i) for i in input().split()]
	b = []
	flg = 0
	while a:
		if not s:
			flg = 1
			break
		if a[-1] <= s[-1]:
			b.append(int(s.pop()) - int(a.pop()))
		else:
			if len(s) < 2:
				flg = 1
				break
			t = int(s[-2] + s[-1])
			s.pop()
			s.pop()
			val = t - int(a.pop())
			if val >= 10 or val < 0:
				flg = 1
				break
			b.append(val)
	while s:
		b.append(int(s.pop()))
	b.reverse()
	if flg == 1:
		print(-1)
	else:
		b = int(''.join([str(i) for i in b]))
		print(b)


def solve(a, s):
	ans = ''
	can = 1
	while a != 0 and s != 0:
		ca = a % 10
		cs = s % 10
		ccs = s % 100 // 10
		if ca <= cs:
			ans += str(cs - ca)
			a //= 10
			s //= 10
		else:
			num = 10 * ccs + cs
			if num - ca > 9 or num - ca < 0:
				can = 0
				break
			else:
				ans += str(num - ca)
				s //= 100
				a //= 10
	ans = ans[::-1]
	if s == 0 and a != 0:
		can = 0
	if s != 0 and a == 0:
		ans = str(s) + ans
	if can == 1:
		print(int(ans))
	else:
		print(-1)
for i in range(int(input())):
	solve(*map(int, input().split()))


import sys
import os.path
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
	sys.stderr = open('error.txt', 'w')
depth = 200001
mod = 1000000007
lim = mod * mod
sys.setrecursionlimit(depth)
linp = lambda : list(minp())
minp = lambda : map(int, input().split())
from math import inf, ceil, sqrt, log2, gcd
from collections import defaultdict, deque
dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]

def expo(a, b):
	if not b:
		return 1
	v = expo(a, b // 2)
	v = v * v % mod
	if b % 2:
		v = v * a % mod
	return v

def modinv(a, b):
	d = expo(b, mod - 2)
	v = a * d % mod
	return v

def checkPrime(n):
	if n < 4:
		return True
	if n % 2 == 0:
		return False
	for i in range(3, int(sqrt(n)) + 1, 2):
		if n % i == 0:
			return False
	return True

def highestPowerof2(x):
	x |= x >> 1
	x |= x >> 2
	x |= x >> 4
	x |= x >> 8
	x |= x >> 16
	return x ^ x >> 1

def isVowel(char):
	return char.lower() in 'aeiou'
for _ in range(int(input())):
	(a, s) = map(str, input().split())
	b = ''
	n = len(s)
	i = n - 1
	f = True
	for e in reversed(a):
		if i < 0:
			f = False
			break
		if int(e) <= int(s[i]):
			b += str(int(s[i]) - int(e))
			i -= 1
		else:
			if i - 1 >= 0 and int(s[i - 1]) == 1:
				b += str(int(s[i - 1:i + 1]) - int(e))
			else:
				f = False
			i -= 2
	b = b[::-1]
	if f and i >= 0:
		b = s[:i + 1] + b
	if f:
		print(int(b))
	else:
		print(-1)


t = int(input())
for _ in range(t):
	b = ''
	(a, s) = map(str, input().split())
	ind = len(a)
	i = len(s)
	s = '0' + s
	a = '0' + a
	f = 1
	while i > 0 and ind >= 0:
		if int(s[i]) - int(a[ind]) < 0:
			if i <= 1:
				f = 0
				break
			val = int(s[i - 1:i + 1]) - int(a[ind])
			if val > 9:
				f = 0
				break
			else:
				b += str(val)
			i -= 1
		else:
			b += str(int(s[i]) - int(a[ind]))
		ind -= 1
		i -= 1
	for j in range(i, -1, -1):
		b += s[j]
	if f and ind < 1 and (b != ''):
		try:
			print(int(b[::-1]))
		except Exception:
			print(-1)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	(a, s) = input().split()
	a = a[::-1]
	s = s[::-1]
	j = 0
	ans = ''
	flag = True
	for i in a:
		if j == len(s):
			flag = False
			break
		if i <= s[j] and j + 1 <= len(s):
			ans += str(int(s[j]) - int(i))
			j += 1
		elif i > s[j] and j + 2 <= len(s):
			if s[j + 1] == '1':
				ans += str(int(s[j + 1]) * 10 + int(s[j]) - int(i))
				j += 2
			else:
				flag = False
				break
		else:
			flag = False
			break
	if flag and '-' not in ans:
		while j < len(s):
			ans += s[j]
			j += 1
		print(int(ans[::-1]))
	else:
		print(-1)


for _ in range(int(input())):
	(a, b) = map(str, input().split())
	l1 = len(a)
	l2 = len(b)
	flag = True
	k = ''
	while l1 > 0 and l2 > 0:
		if a[-1] <= b[-1]:
			l1 -= 1
			l2 -= 1
			a1 = a[-1]
			b1 = b[-1]
			a = a[:-1]
			b = b[:-1]
			a1 = int(a1)
			b1 = int(b1)
			if not b1 - a1 < 10:
				flag = False
				break
			else:
				k = f'{b1 - a1}' + k
		else:
			l1 -= 1
			l2 -= 2
			if l2 >= 0:
				pass
			if l2 < 0:
				flag = False
				break
			a1 = a[-1]
			b1 = b[-2:]
			a = a[:-1]
			b = b[:-2]
			a1 = int(a1)
			b1 = int(b1)
			if not (b1 - a1 < 10 and b1 - a1 >= 0):
				flag = False
				break
			else:
				k = f'{b1 - a1}' + k
	if not (l1 or not flag):
		print(int(b + k))
	else:
		print(-1)


def solve():
	(a, b) = input().split()
	a = [int(i) for i in a]
	b = [int(i) for i in b]
	i = len(a) - 1
	j = len(b) - 1
	ans = []
	while i >= 0 and j >= 0:
		if j < i:
			return -1
		if a[i] > b[j]:
			if j == 0:
				return -1
			elif b[j - 1] != 1:
				return -1
			ans.insert(0, 10 + b[j] - a[i])
			j -= 2
			i -= 1
		elif a[i] == b[j]:
			ans.insert(0, 0)
			i -= 1
			j -= 1
		else:
			ans.insert(0, b[j] - a[i])
			i -= 1
			j -= 1
	while j >= 0:
		ans.insert(0, b[j])
		j -= 1
	while ans[0] == 0:
		ans.pop(0)
	return ''.join([str(i) for i in ans])
for _ in range(int(input())):
	print(solve())


t = int(input())
ret = []
from collections import deque
for i in range(t):
	(a, b) = input().split()
	if int(b) < int(a):
		ret.append(-1)
		continue
	a = deque(list(a))
	b = deque(list(b))
	ans = ''
	while b:
		if not a:
			a.append('0')
		nowA = a.pop()
		nowB = b.pop()
		if nowA <= nowB:
			ans = str(int(nowB) - int(nowA)) + ans
			continue
		else:
			try:
				nowB2 = b.pop()
			except:
				b.append('0')
				break
			d = int(nowB2 + nowB) - int(nowA)
			if d > 10:
				b.append('0')
				break
			elif d < 0:
				b.append('0')
				break
			else:
				ans = str(d) + ans
	if a or b:
		ret.append(-1)
	else:
		ret.append(int(ans))
print(*ret, sep='\n')


for s in [*open(0)][1:]:
	(a, s) = map(int, s.split())
	b = 0
	k = 1
	while s > 0 <= (d := (s % (m := 10) - a % m)) or -1 < (d := (0 - a % m + s % (m := 100))) <= 9 < s:
		a //= 10
		s //= m
		b += k * d
		k *= 10
	print((b, -1)[a > 0])


import sys

def solve():
	(a, s) = sys.stdin.readline().split()
	j = len(s) - 1
	b = ''
	for i in range(len(a) - 1, -1, -1):
		ai = int(a[i])
		if j < 0:
			return '-1'
		if s[j] >= a[i]:
			b += str(int(s[j]) - ai)
			j -= 1
		elif j == 0 or s[j - 1] != '1':
			return '-1'
		else:
			b += str(int(s[j - 1:j + 1]) - ai)
			j -= 2
	if j >= 0:
		b += s[:j + 1][::-1]
	return str(int(b[::-1]))
t = int(sys.stdin.readline())
for _ in range(t):
	print(solve())


for t in range(int(input())):
	(a, s) = input().split()
	n = len(a)
	m = len(s)
	b = ''
	i = n - 1
	j = m - 1
	while i >= 0 and j >= 0:
		e = a[i]
		d = s[j]
		i -= 1
		j -= 1
		if e > d:
			if j >= 0:
				f = s[j]
				j -= 1
			else:
				b = -1
				break
			if f != '1':
				b = -1
				break
			else:
				b += str(int(f + d) - int(e))
		else:
			b += str(int(d) - int(e))
	if i > -1 or b == -1:
		print(-1)
	else:
		while j >= 0:
			b += s[j]
			j -= 1
		print(int(b[::-1]))


for _ in range(int(input())):
	(a, s) = input().split()
	i = len(s) - 1
	j = len(a) - 1
	b = ''
	wrong = False
	try:
		while j >= 0:
			if i < 0:
				wrong = True
				break
			if int(a[j]) > int(s[i]):
				if i < 1:
					wrong = True
					break
				char = str(int(s[i - 1] + s[i]) - int(a[j]))
				if len(char) > 1:
					wrong = True
					break
				b = char + b
				i -= 2
				j -= 1
			else:
				b = str(int(s[i]) - int(a[j])) + b
				i -= 1
				j -= 1
		if i != -1:
			b = s[:i + 1] + b
	except:
		print(-1)
		continue
	if wrong:
		print(-1)
		continue
	print(int(b))


def insert(source_str, insert_str, pos):
	return source_str[:pos] + insert_str + source_str[pos:]

def check(a, b, s):
	temp = ''
	for i in range(len(a) - 1, -1, -1):
		temp = insert(temp, str(int(a[i]) + int(b[i])), 0)
	return int(temp) == int(s)

def solve():
	(a, s) = input().split()
	b = ''
	i = len(a) - 1
	j = len(s) - 1
	while j >= 0 or i >= 0:
		if i < 0:
			a = insert(a, '0', 0)
			i = 0
		if j < 0:
			s = insert(s, '0', 0)
			j = 0
		t1 = a[i]
		t2 = s[j]
		while int(t2) < int(t1):
			j -= 1
			t2 = insert(t2, s[j], 0)
		if int(t2) - int(t1) > 9:
			print(-1)
			return
		b = insert(b, str(int(t2) - int(t1)), 0)
		i -= 1
		j -= 1
	if check(a, b, s):
		print(int(b))
	else:
		print(-1)
for _ in range(int(input())):
	solve()


t = int(input())
for _ in range(t):
	(a, s) = input().split()
	otv = ''
	i = len(a) - 1
	j = len(s) - 1
	while i >= 0:
		if j > -1 and int(a[i]) > int(s[j]):
			if j > 0:
				otv = str(int(s[j - 1:j + 1]) - int(a[i])) + otv
				if int(s[j - 1:j + 1]) - int(a[i]) > 10 or int(s[j - 1:j + 1]) - int(a[i]) < 0:
					otv = -1
					break
			i -= 1
			j -= 2
		else:
			if j > -1:
				otv = str(int(s[j]) - int(a[i])) + otv
			i -= 1
			j -= 1
	if int(otv) == -1 or int(otv) >= int(s) or i > j:
		print(-1)
	else:
		if j > -2:
			otv = s[:j + 1] + otv
		otv = int(otv)
		print(otv)


for _ in range(int(input())):
	(a, s) = input().split()
	(i, j) = (len(a) - 1, len(s) - 1)
	possible = True
	b = ''
	while i >= 0 and j >= 0:
		if s[j] == a[i]:
			b = '0' + b
			j -= 1
		elif a[i] > s[j]:
			if j == 0 or s[j - 1] != '1':
				possible = False
				break
			b = str(int(s[j - 1:j + 1]) - int(a[i])) + b
			j -= 2
		else:
			b = str(int(s[j]) - int(a[i])) + b
			j -= 1
		i -= 1
	if not possible or i >= 0:
		print(-1)
	else:
		if j >= 0:
			b = s[:j + 1] + b
		print(int(b))


T = int(input())
for i in range(T):
	(a, c) = input().split()
	maxLen = max(len(a), len(c))
	a = a.zfill(maxLen)
	c = c.zfill(maxLen)
	cur = maxLen - 1
	curA = maxLen - 1
	num = ''
	while cur >= 0:
		digit = int(c[cur]) - int(a[curA])
		if digit < 0:
			digit = int(c[cur]) + 10 - int(a[curA])
			if cur == 0 or c[cur - 1] != '1':
				num = ''
				break
			cur -= 1
		num = str(digit) + num
		cur -= 1
		curA -= 1
	while curA >= 0:
		if a[curA] != '0':
			num = ''
			break
		curA -= 1
	if num != '':
		print(int(num))
	else:
		print(-1)


for _ in range(int(input())):
	(a, s) = map(int, input().split())
	b = ''
	check = True
	if a > s:
		print(-1)
	else:
		while s > 0:
			if a > s:
				check = False
				break
			if a % 10 <= s % 10:
				d = s % 10 - a % 10
				a = a // 10
				s = s // 10
			elif a % 10 > s % 10:
				d = s % 100 - a % 10
				if d > 10 or d < 0:
					check = False
					break
				a = a // 10
				s = s // 100
			b = str(d) + b
		if check:
			print(int(b))
		else:
			print(-1)


import io, os
import sys
from sys import stdin
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, namedtuple
from heapq import heappush, heappop
from math import gcd, ceil, floor, factorial, sqrt
from itertools import combinations, permutations
input = sys.stdin.readline

def work():
	ans = 0
	return

def main():
	test = int(input())
	for idt in range(test):
		(a, s) = map(str, input().split())
		(n, m) = (len(a), len(s))
		a = a[::-1]
		s = s[::-1]
		i = j = 0
		flag = True
		b = ''
		while i < n:
			if j >= m:
				flag = False
				break
			x = int(a[i])
			y = int(s[j])
			if x <= y:
				b += str(y - x)
				i += 1
				j += 1
			elif j + 1 < m:
				y = int(s[j + 1]) * 10 + int(s[j])
				if 0 <= y - x <= 9:
					b += str(y - x)
					i += 1
					j += 2
				else:
					flag = False
			else:
				flag = False
			if not flag:
				break
		while j < m:
			b += s[j]
			j += 1
		b = b[::-1]
		length = len(b)
		idx = 0
		while idx < length and b[idx] == '0':
			idx += 1
		b = b[idx:]
		if not flag:
			b = -1
		print(b)
	return
main()


def solve():
	(a, s) = (int(i) for i in input().split(' '))
	k = 0
	num = 0
	i = 0
	while a > 0:
		ai = a % 10
		a = a // 10
		sk = s % 10
		s = s // 10
		if ai <= sk:
			num = num + (sk - ai) * 10 ** i
		elif s % 10 == 1:
			sk1 = s % 10
			s = s // 10
			num = num + (sk1 * 10 + sk - ai) * 10 ** i
		else:
			return -1
		i = i + 1
	if s > 0:
		num = num + s * 10 ** i
	return num
t = int(input())
for _ in range(t):
	print(solve())


from sys import stdin
import math
from collections import deque
from heapq import heapify, heappop, heappush
from bisect import bisect_left, bisect_right
input = stdin.readline

def log(n, m):
	(res, val) = (0, 1)
	while True:
		if n == val:
			return res
		elif n > val:
			return res - 1
		res += 1
		val *= m

def ceil(m, n):
	val = m // n
	if m % n != 0:
		return val + 1
	return val
for _ in range(int(input())):
	(a, s) = input().strip().split()
	(idxa, idxs) = (len(a) - 1, len(s) - 1)
	(b, correct) = ([], True)
	while idxs >= 0 and idxa >= 0 and (idxa <= idxs):
		(vala, vals) = (int(a[idxa]), int(s[idxs]))
		if vala <= vals:
			b.append(vals - vala)
		else:
			if idxs == 0:
				correct = False
				break
			val = int(s[idxs - 1] + s[idxs]) - vala
			if val >= 10 or val <= 0:
				correct = False
				break
			b.append(val)
			idxs -= 1
		idxa -= 1
		idxs -= 1
	if idxa >= 0 or not correct:
		print(-1)
		continue
	for c in reversed(s[0:max(idxs + 1, 0)]):
		b.append(int(c))
	while b[-1] == 0:
		b.pop()
	b = ''.join(map(str, reversed(b)))
	print(b)


import os
import sys
from io import BytesIO, IOBase
import math as M
import itertools as ITR
from collections import defaultdict as D
from collections import Counter as C
from collections import deque as Q
import threading
from functools import cmp_to_key, lru_cache, reduce
from functools import cmp_to_key as CMP
from bisect import bisect, bisect_left as BL
from bisect import bisect_right as BR
import random as R
import string
import cmath, time
from heapq import heapify, heappop as HPOP
from heapq import heappush as HPUSH
import heapq as H
enum = enumerate
start_time = time.time()
MOD = 1000000007
MA = float('inf')
MI = float('-inf')
d8i = (-1, -1, 0, 1, 1, 1, 0, -1)
d8j = (0, 1, 1, 1, 0, -1, -1, -1)
d4i = (-1, 0, 1, 0)
d4j = (0, 1, 0, -1)

def increase_stack():
	sys.setrecursionlimit(2 ** 32 // 2 - 1)
	threading.stack_size(1 << 27)

def binary(n):
	return bin(n)[2:]

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def maxfactor(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
	if q:
		return q[-1]

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(M.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	l.sort()
	return l

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def seive(n):
	a = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p ** 2, n + 1, p):
				prime[i] = False
		p = p + 1
	for p in range(2, n + 1):
		if prime[p]:
			a.append(p)
	prime[0] = prime[1] = False
	return (a, prime)

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(M.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def countchar(s, i):
	c = 0
	ch = s[i]
	for i in range(i, len(s)):
		if s[i] == ch:
			c += 1
		else:
			break
	return c

def str_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def lis(arr):
	n = len(arr)
	lis = [1] * n
	maximum = 0
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] > arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
				maximum = max(maximum, lis[i])
	return maximum

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def agcd(a):
	(a, b) = (a[0], a[1:])
	for i in b:
		a = gcd(a, i)
	return a

def lcm(a, *b):
	val = a
	gc = a
	for i in b:
		gc = gcd(gc, i)
		val *= i
	return val // gc

def ncr(n, r):
	return M.factorial(n) // (M.factorial(n - r) * M.factorial(r))

def npr(n, r):
	return M.factorial(n) // M.factorial(n - r)

def IF(c, t, f):
	return t if c else f

def YES(c):
	print(IF(c, 'YES', 'NO'))

def Yes(c):
	print(IF(c, 'Yes', 'No'))

def yes(c):
	print(IF(c, 'yes', 'no'))

def JA(a, sep=' '):
	print(sep.join(map(str, a)))

def JAA(a, s='\n', t=' '):
	print(s.join((t.join(map(str, b)) for b in a)))

def PS(a, s=' '):
	print(str(a), end=s)

def I():
	return int(inp())

def F():
	return float(inp())

def LI():
	return list(map(int, inp().split()))

def LF():
	return list(map(float, inp().split()))

def MATI(n):
	return [LI() for i in range(n)]

def MATS(n):
	return [list(inp()) for i in range(n)]

def IV():
	return map(int, inp().split())

def FV():
	return map(float, inp().split())

def LS():
	return list(inp())

def S():
	return inp()
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
inp = lambda : sys.stdin.readline().rstrip('\r\n')
TestCases = 1

def solve(test_no):
	res = ''
	(s, t) = S().split()
	i = len(s) - 1
	j = len(t) - 1
	rem = ''
	while i >= 0 and j >= 0:
		if len(res) > len(t):
			print(-1)
			return
		if len(res) == len(t):
			break
		if s[i] > t[j]:
			val = 10 + int(t[j])
			rval = val - int(s[i])
			rem += str(rval)
			res += str(val)[::-1]
			i -= 1
			j -= 2
		elif s[i] == t[j]:
			rem += '0'
			res += s[i]
			i -= 1
			j -= 1
		else:
			val = str(int(t[j]) - int(s[i]))
			rem += val
			res += t[j]
			i -= 1
			j -= 1
	if i >= 0:
		print(-1)
		return
	while j >= 0:
		rem += t[j]
		res += t[j]
		j -= 1
	if res[::-1] != t:
		print(-1)
		return
	print(int(rem[::-1]))

def main():
	flag = 1
	try:
		sys.stdin = open('C:/Users/raavi.manoj/Documents/coding/python/input.txt', 'r')
		sys.stdout = open('C:/Users/raavi.manoj/Documents/coding/python/output.txt', 'w')
	except:
		flag = 0
	t = 1
	if TestCases:
		t = I()
	for test in range(1, t + 1):
		solve(test)
	if flag:
		print('\nTHIS IS A PYTHON OUTPUT FILE')
		print('Time: %.4f seconds' % (time.time() - start_time))
		localtime = time.asctime(time.localtime(time.time()))
		print(localtime)
		sys.stdout.close()
main()


t = int(input())
for _ in range(t):
	(a, s) = input().split()
	b = ''
	a = list(map(int, a))
	s = list(map(int, s))
	iS = len(s) - 1
	key = True
	for i in range(len(a) - 1, -1, -1):
		if s[iS] == a[i]:
			b += '0'
			iS -= 1
		elif s[iS] > a[i]:
			b += str(s[iS] - a[i])
			iS -= 1
		elif iS > 0:
			if s[iS - 1] == 1:
				b += str(10 + s[iS] - a[i])
				iS -= 2
			else:
				key = False
				break
		else:
			key = False
			break
		if i > 0 and iS < 0:
			key = False
			break
	if key == False:
		print('-1')
	else:
		for i in range(iS, -1, -1):
			b += str(s[i])
		print(int(b[::-1]))


for _ in range(int(input())):
	(a, s) = input().split()
	finish = False
	i = len(a) - 1
	j = len(s) - 1
	result = ''
	while not finish:
		(a1, s1) = (int(a[i]), int(s[j]))
		if s1 == a1:
			result += '0'
			i -= 1
			j -= 1
		elif s1 > a1:
			result += str(s1 - a1)
			i -= 1
			j -= 1
		elif s1 < a1:
			if j > 0:
				s1 = int(s[j - 1] + s[j])
				j -= 1
				if s1 > a1:
					if s1 - a1 > 9:
						result = '-1'
						break
					else:
						result += str(s1 - a1)
						i -= 1
						j -= 1
				else:
					result = '-1'
					break
			else:
				result = '-1'
				break
		if result == '-1':
			finish = True
		elif i < 0 and j >= 0:
			a = '0' + a
			i = 0
		elif i >= 0 and j < 0:
			result = '-1'
			finish = True
		elif i < 0 and j < 0:
			finish = True
	print(result if result == '-1' else result.rstrip('0')[::-1])


from sys import stdin
test = int(stdin.readline())
for t in range(test):
	(a, result) = map(str, stdin.readline().split())
	b = ''
	state = True
	while True:
		tmp1 = int(result[-1])
		tmp2 = int(a[-1])
		result = result[:-1]
		if len(a) == 1:
			a = '0'
		else:
			a = a[:-1]
		if tmp1 >= tmp2:
			b = str(tmp1 - tmp2) + b
		else:
			if result == '':
				state = False
				break
			tmp1 = int(result[-1]) * 10 + int(tmp1)
			result = result[:-1]
			if tmp1 > 18:
				state = False
				break
			elif tmp1 - tmp2 < 0:
				state = False
				break
			else:
				b = str(tmp1 - tmp2) + b
		if result == '':
			break
	if state:
		if a != '0':
			print(-1)
		else:
			print(int(b))
	else:
		print(-1)


import sys
fin = sys.stdin

def tanya_substract(a, s):
	s = s[::-1]
	a = a[::-1]
	b = []
	while s:
		c_s = s[0]
		if a == '':
			a = '0'
		c_a = a[0]
		c_b = int(c_s) - int(c_a)
		if c_b < 0:
			if len(s) < 2 or s[1] != '1':
				return -1
			else:
				s = s[1:]
			c_b %= 10
		b.append(str(c_b))
		a = a[1:]
		s = s[1:]
	b = b[::-1]
	if not b:
		return -1
	return ''.join(b).lstrip('0') if a == '' and s == '' else -1
n = int(fin.readline())
for i in range(n):
	l = fin.readline().rstrip('\n')
	(a, s) = l.split()
	b = tanya_substract(a, s)
	print(b)


import sys
import pprint
import logging
from logging import getLogger

def input():
	return sys.stdin.readline().rstrip('\r\n')
logging.basicConfig(format='%(message)s', level=logging.WARNING)
logger = getLogger(__name__)
logger.setLevel(logging.INFO)

def debug(msg, *args):
	logger.info(f'{msg}={pprint.pformat(args)}')

def solve():
	(a, s) = inp()
	b = 0
	mul = 1
	fl = 0
	while s:
		p = s % 10
		q = a % 10
		s //= 10
		a //= 10
		if p < q:
			if not s % 10 == 1:
				fl = 1
				break
			p += 10
			s //= 10
		b += mul * (p - q)
		mul *= 10
	if a:
		fl = 1
	print(-1 if fl else b)
multi = True
t = 1

def inp():
	return map(int, input().split())
if multi:
	t = int(input())
while t:
	t -= 1
	solve()


import sys
T = int(sys.stdin.readline())
for _ in range(T):
	(a, x) = list(map(int, sys.stdin.readline().split()))
	b = []
	while a > 0 or x > 0:
		a_ = a % 10
		x_ = x % 10
		if x_ >= a_:
			b.append(x_ - a_)
			x = x // 10
			a = a // 10
		elif x % 100 >= a_:
			val = x % 100 - a_
			if val > 10:
				b = [-1]
				break
			b.append(val)
			x = x // 100
			a = a // 10
		else:
			b = [-1]
			break
	print(int(''.join(map(str, b[::-1]))))


import sys
input = sys.stdin.readline

def solve(a, s):
	(n, m) = (len(s), len(a))
	i = n - 1
	j = m - 1
	ans = []
	while i >= 0 and j >= 0:
		cur = s[i]
		while int(cur) < int(a[j]):
			if i <= 0:
				return -1
			i -= 1
			cur = s[i] + cur
		x = int(cur) - int(a[j])
		if len(str(x)) > 1:
			return -1
		ans.append(x)
		i -= 1
		j -= 1
	while i >= 0:
		ans.append(int(s[i]))
		i -= 1
	if i == -1 and j == -1:
		return int(''.join(map(str, ans[::-1])))
	return -1
t = int(input())
for _ in range(t):
	(a, s) = input().strip().split()
	print(solve(a, s))


def solve():
	[a, s] = [x for x in input().split()]
	res = ''
	s_ind = len(s) - 1
	for i in range(len(a) - 1, -1, -1):
		if s_ind < 0:
			print(-1)
			return
		if s[s_ind] >= a[i]:
			b = int(s[s_ind]) - int(a[i])
			res = str(b) + res
			s_ind -= 1
		else:
			if s_ind == 0:
				print(-1)
				return
			if s[s_ind - 1] != '1':
				print(-1)
				return
			b = int(s[s_ind - 1:s_ind + 1]) - int(a[i])
			res = str(b) + res
			s_ind -= 2
	if s_ind >= 0:
		res = s[:s_ind + 1] + res
	res = str(int(res))
	print(res)
for i in range(int(input())):
	solve()


for _ in range(int(input())):
	(a, s) = map(int, input().split())
	b = 0
	temp = 1
	while s > 0:
		subA = a % 10
		subS = s % 10
		if subA <= subS:
			b += temp * (subS - subA)
			s //= 10
		elif s % 100 - subA in range(10):
			b += temp * (s % 100 - subA)
			s //= 100
		else:
			break
		temp *= 10
		a //= 10
	if a > 0 or s > 0:
		print(-1)
	else:
		print(b)