You are given a decimal representation of an integer $x$ without leading zeros.

You have to perform the following reduction on it exactly once: take two neighboring digits in $x$ and replace them with their sum without leading zeros (if the sum is $0$, it's represented as a single $0$).

For example, if $x = 10057$, the possible reductions are:

choose the first and the second digits $1$ and $0$, replace them with $1+0=1$; the result is $1057$;

choose the second and the third digits $0$ and $0$, replace them with $0+0=0$; the result is also $1057$;

choose the third and the fourth digits $0$ and $5$, replace them with $0+5=5$; the result is still $1057$;

choose the fourth and the fifth digits $5$ and $7$, replace them with $5+7=12$; the result is $10012$.

What's the largest number that can be obtained?


-----Input-----

The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases.

Each testcase consists of a single integer $x$ ($10 \le x < 10^{200000}$). $x$ doesn't contain leading zeros.

The total length of the decimal representations of $x$ over all testcases doesn't exceed $2 \cdot 10^5$.


-----Output-----

For each testcase, print a single integer — the largest number that can be obtained after the reduction is applied exactly once. The number should not contain leading zeros.


-----Examples-----

Input
2
10057
90
Output
10012
9


-----Note-----

The first testcase of the example is already explained in the statement.

In the second testcase, there is only one possible reduction: the first and the second digits.

Difficulty: EASY
Tags: String algorithms

Greedy algorithms
Skill types: Greedy algorithms

Starter code:

Solutions:
import sys, collections
equal = {'19', '28', '29', '37', '38', '39', '46', '47', '48', '49', '55', '56', '57', '58', '59', '64', '65', '66', '67', '68', '69', '73', '74', '75', '76', '77', '78', '79', '82', '83', '84', '85', '86', '87', '88', '89', '91', '92', '93', '94', '95', '96', '97', '98', '99'}

def solve(s):
	n = len(s)
	for i in range(n - 2, -1, -1):
		if s[i:i + 2] in equal:
			mid = str(int(s[i]) + int(s[i + 1]))
			return s[:i] + mid + s[i + 2:]
	mid = str(int(s[0]) + int(s[1]))
	return mid + s[2:]
input = sys.stdin.readline
tests = int(input()[:-1])
for test in range(tests):
	s = input()[:-1]
	print(solve(s))


import sys
input = sys.stdin.readline
n = int(input())
R = []

def process(S):
	x = list(map(int, list(S)))
	decimal_checked = False
	for i in range(len(x) - 2, -1, -1):
		c = x[i] + x[i + 1]
		if c >= 10:
			x[i + 1] = c - 10
			x[i] = 1
			decimal_checked = True
			break
	if not decimal_checked:
		x[1] += x[0]
		x.pop(0)
	return ''.join([chr(c + ord('0')) for c in x])
for _ in range(n):
	s = input()[:-1]
	R.append(process(s))
for r in R:
	print(r)


def Solve():
	lst = []
	for t in range(int(input())):
		n = input()[::-1]
		lst.append(n)
	for num in lst:
		e = True
		for i in range(len(num) - 1):
			z = int(num[i]) + int(num[i + 1])
			if z > 9:
				e = False
				break
		z = str(z)[::-1]
		if e:
			num = num[::-1]
			print(str(int(num[0]) + int(num[1])) + num[2:])
		else:
			ans = (num[:i] + z + num[i + 2:])[::-1]
			print(ans)
Solve()


import sys

def _input_iter():
	for line in sys.stdin:
		for part in line.strip().split(' '):
			stripped = part.strip()
			if stripped:
				yield stripped
stream = _input_iter()

def read_int():
	return int(next(stream))

def read_str():
	return next(stream)

def run():
	x = list(read_str())
	for i in range(len(x) - 2, -1, -1):
		currd = int(x[i])
		nextd = int(x[i + 1])
		if currd + nextd >= 10:
			x[i] = str(1)
			x[i + 1] = str(currd + nextd - 10)
			print(''.join(x))
			return
	x[1] = str(int(x[0]) + int(x[1]))
	del x[0]
	print(''.join(x))
test_cases = read_int()
for _ in range(test_cases):
	run()


import sys
input = sys.stdin.readline

def print(*args, end='\n', sep=' ') -> None:
	sys.stdout.write(sep.join(map(str, args)) + end)

def solve() -> str:
	x = input().strip()
	two = False
	for i in reversed(range(1, len(x))):
		if int(x[i]) + int(x[i - 1]) >= 10:
			two = True
			ind = i
			break
	if two:
		print(x[:ind - 1], str(int(x[ind - 1]) + int(x[ind])), x[ind + 1:], sep='')
		return
	for i in range(len(x) - 1):
		if int(x[i]) + int(x[i + 1]) >= int(x[i]):
			print(x[:i], str(int(x[i]) + int(x[i + 1])), x[i + 2:], sep='')
			break
	else:
		print(x[:-2], str(int(x[-1]) + int(x[-2])), sep='')

def main() -> None:
	t = int(input())
	for _ in range(t):
		solve()
main()


def solve():
	s = str(input())
	for i in reversed(range(len(s) - 1)):
		if ord(s[i]) + ord(s[i + 1]) - 48 * 2 > 9:
			print(s[:i] + str(ord(s[i]) + ord(s[i + 1]) - 48 * 2) + s[i + 2:])
			return
	print(str(ord(s[0]) + ord(s[1]) - 48 * 2) + s[2:])
nt = int(input())
for t in range(nt):
	solve()


def solve():
	x = input()
	f = False
	for i in ['19', '28', '37', '46', '55', '66', '77', '88', '99', '29', '38', '39', '47', '48', '49', '56', '57', '58', '59', '67', '68', '69', '78', '79', '89']:
		if i in x or i[::-1] in x:
			f = True
			break
	if f:
		a = []
		i = 0
		while True:
			i -= 1
			(a, b) = (x[i - 1], x[i])
			ab = str(int(a) + int(b))
			if int(ab) >= 10:
				if i == -1:
					px = x[:i - 1] + ab
				else:
					px = x[:i - 1] + ab + x[i + 1:]
				print(px)
				break
	else:
		px = str(int(x[0]) + int(x[1]))
		print(px + x[2:])
for i in range(int(input())):
	solve()


n = int(input())
for _ in range(n):
	x = input()
	flag = 0
	ind = -1
	for i in range(len(x) - 1, 0, -1):
		if int(x[i]) + int(x[i - 1]) >= 10:
			flag = 1
			ind = i
			break
	if flag == 0:
		try:
			print(str(int(x[0]) + int(x[1])) + x[2:])
		except:
			print(x)
	else:
		print(x[:ind - 1] + str(int(x[ind]) + int(x[ind - 1])) + x[ind + 1:])


import sys
n = int(sys.stdin.readline())
for _ in range(n):
	mx = 0
	x = sys.stdin.readline().rstrip()
	for i in range(len(x) - 2, -1, -1):
		if int(x[i]) + int(x[i + 1]) >= 10:
			print(x[:i] + str(int(x[i]) + int(x[i + 1])) + x[i + 2:])
			break
	else:
		print(str(int(x[0]) + int(x[1])) + x[2:])


ans = []
for _ in range(int(input())):
	x = input()
	mx = 0
	ok = False
	for i in range(len(x) - 1, 0, -1):
		if int(x[i]) + int(x[i - 1]) > 9:
			ok = True
			ans.append(x[:i - 1] + str(int(x[i]) + int(x[i - 1])) + x[i + 1:])
			break
	else:
		ans.append(str(int(x[0]) + int(x[1])) + x[2:])
for i in ans:
	print(i)


def do(n):
	l = len(n)
	p = False
	ind = 0
	for i in range(l - 1, 0, -1):
		(a, b) = (ord(n[i]) - ord('0'), ord(n[i - 1]) - ord('0'))
		if a + b > 9:
			(p, ind) = (True, i)
			break
	if p:
		i = ind
		(a, b) = (ord(n[ind]) - ord('0'), ord(n[ind - 1]) - ord('0'))
		s1 = n[:i - 1]
		if i + 1 < l:
			s2 = n[i + 1:]
		else:
			s2 = ''
		c = str(a + b)
		s_final = s1 + c + s2
		print(s_final)
	else:
		(a, b) = (ord(n[0]) - ord('0'), ord(n[1]) - ord('0'))
		c = str(a + b)
		if l > 2:
			s2 = n[2:]
		else:
			s2 = ''
		s_final = c + s2
		print(s_final)
t = int(input())
for i in range(t):
	n = str(input())
	do(n)


for s in [*open(0)][1:]:
	a = (*map(int, s[:-1]),)
	i = max(0, ''.join(('01'[(x + y) // 10] for (x, y) in zip(a, a[1:]))).rfind('1'))
	print(s[:i], a[i] + a[i + 1], s[i + 2:], sep='')


import sys
input = sys.stdin.readline

def read_int_list():
	return list(map(int, list(input().strip())))

def solve(a):
	pos = len(a) - 1
	for i in range(len(a) - 1, 0, -1):
		pos = i
		if a[i] + a[i - 1] > 9:
			break
	print(f"{''.join(map(str, a[:pos - 1]))}{a[pos] + a[pos - 1]}{''.join(map(str, a[pos + 1:]))}")
for _ in range(int(input())):
	a = read_int_list()
	solve(a)


def give(s):
	if len(s) == 2:
		return str(int(s[0]) + int(s[1]))
	sg = ''
	for i in range(1, len(s)):
		md = (int(s[-i]) + int(s[-i - 1])) // 10
		if md > 0:
			e = str(int(s[-i]) + int(s[-i - 1]))
			sg = s[:-i - 1] + e
			if 1 - i < 0:
				sg += s[-i + 1:]
			return sg
	return str(int(s[0]) + int(s[1])) + s[2:]
for _ in range(int(input())):
	print(give(input()))


import sys
input = sys.stdin.readline

def solution(inp: str) -> str:
	for i in range(len(inp) - 1, 0, -1):
		current_sum = int(inp[i]) + int(inp[i - 1])
		if current_sum >= 10:
			res = ''.join(inp[:i - 1]) + str(current_sum) + ''.join(inp[i + 1:])
			return res
	current_sum = int(inp[0]) + int(inp[1])
	res = str(current_sum) + ''.join(inp[2:])
	return res
t = int(input())
for case in range(t):
	inp = input().rstrip()
	sol = solution(inp)
	print(sol)


n = int(input())
results = []
for i in range(n):
	num = input()
	out = 0
	for j in range(len(num) - 1, 1, -1):
		temp = int(num[j]) + int(num[j - 1])
		if temp >= 10:
			out = num[0:j - 1] + str(temp) + num[j + 1:]
			break
	if out == 0:
		out = str(int(num[0]) + int(num[1])) + num[2:]
	results.append(out)
for result in results:
	print(result)


def solve(s):
	mn = 0
	if int(s[-1]) + int(s[-2]) >= 10:
		return s[:len(s) - 2] + str(int(s[-1]) + int(s[-2]))
	else:
		n = len(s)
		i = n - 2
		j = n - 3
		while j >= 0 and i > 0:
			val = int(s[i]) + int(s[j])
			if val >= 10:
				idxb = i
				idxf = j
				break
			j -= 1
			i = j + 1
		if j < 0 and i == 0:
			return str(int(s[0]) + int(s[1])) + s[2:]
		else:
			return s[:idxf] + str(val) + s[idxb + 1:]
for i in range(int(input())):
	s = input()
	print(solve(s))


import sys
inp = sys.stdin.readline
for _ in range(int(inp())):
	n = inp().strip()
	index = 0
	for i in range(len(n) - 2, -1, -1):
		if int(n[i]) + int(n[i + 1]) > 9:
			index = i
			break
	insert = int(n[i]) + int(n[i + 1])
	n = n[:i] + str(insert) + n[i + 2:]
	print(n)


import math

def swapp(n, j):
	a = n[0:j]
	ba = int(n[j])
	bb = int(n[j + 1])
	b = str(ba + bb)
	c = n[j + 2:]
	return a + b + c
t = int(input())
for i in range(t):
	n = input()
	flag = False
	for j in range(len(n) - 2, -1, -1):
		if int(n[j]) + int(n[j + 1]) >= 10:
			print(swapp(n, j))
			flag = True
			break
	if not flag:
		print(swapp(n, 0))


def solve(s):
	max = 0
	imax = 0
	for i in range(len(s) - 1, 0, -1):
		if int(s[i]) + int(s[i - 1]) >= 10:
			return s[0:i - 1] + str(int(s[i]) + int(s[i - 1])) + s[i + 1:]
	return str(int(s[0]) + int(s[1])) + s[2:]
n = int(input())
for i in range(n):
	s = input().strip()
	print(solve(s))


t = int(input())
for _ in range(t):
	s = input()
	dd = -1
	ans = str(int(s[0]) + int(s[1])) + s[2:]
	for i in range(len(s) - 2, -1, -1):
		cur = int(s[i]) + int(s[i + 1])
		if cur > 9:
			dd = i
			break
	if dd > -1:
		ans = s[:dd] + str(int(s[dd]) + int(s[dd + 1])) + s[dd + 2:]
	print(ans)


n = int(input())
for i in range(n):
	s = input()
	prev = int(s[-1])
	for j in range(len(s) - 2, -1, -1):
		cur = int(s[j])
		if cur + prev >= 10:
			pref = s[:j]
			suff = s[j + 2:]
			res = pref + str(cur + prev) + suff
			print(res)
			break
		prev = cur
	else:
		sum = str(int(s[0]) + int(s[1]))
		res = sum + s[2:]
		print(res)


t = int(input())
for k in range(t):
	a = input()
	n = len(a)

	def prb(a, n):
		for i in range(n - 1):
			b = int(a[n - 1 - i]) + int(a[n - 2 - i])
			if b > 9:
				return a[:n - 2 - i] + str(b) + a[n - i:]
		return str(int(a[0]) + int(a[1])) + a[2:]
	print(prb(a, n))


import sys
input = lambda : sys.stdin.readline().rstrip()
from collections import deque, defaultdict
for _ in range(int(input())):
	s = input()
	ans = ''
	for i in range(len(s) - 1, 0, -1):
		sm = int(s[i]) + int(s[i - 1])
		if sm >= 10:
			ans = s[:i - 1] + str(sm) + s[i + 1:]
			break
	if len(ans):
		print(ans)
		continue
	sm = int(s[0]) + int(s[1])
	ans = str(sm) + s[2:]
	print(ans)


for _ in range(int(input())):
	s = input()
	s = s[::-1]
	for i in range(1, len(s)):
		k = int(s[i - 1]) + int(s[i])
		if k >= 10:
			s = s[:i - 1] + str(k)[::-1] + s[i + 1:]
			break
	else:
		s = s[:-2] + str(int(s[-1]) + int(s[-2]))
	s = s[::-1]
	print(s)


for _ in range(int(input())):
	s = input()
	i = len(s) - 1
	res = ''
	while i > 0:
		if int(s[i]) + int(s[i - 1]) > 9:
			res = s[:i - 1] + str(int(s[i]) + int(s[i - 1])) + s[i + 1:]
			break
		i -= 1
	else:
		res = str(int(s[0]) + int(s[1])) + s[2:]
	print(res)


import functools
import sys
import typing
from typing import Callable, Dict, List, Set, Tuple
sys.setrecursionlimit(10 ** 6)
sinput: Callable[..., str] = sys.stdin.readline
debug = functools.partial(print, file=sys.stderr)
MOD: int = 998244353
INF: float = float('Inf')
IINF: int = sys.maxsize // 2

def main() -> None:
	s = sinput().strip()
	l = len(s)
	same_pos = -1
	for i in range(l - 1):
		af = int(s[i]) + int(s[i + 1])
		if af >= 10:
			same_pos = i
	if same_pos != -1:
		change_pos = same_pos
	else:
		change_pos = 0
	print(s[:change_pos], int(s[change_pos]) + int(s[change_pos + 1]), s[change_pos + 2:], sep='')
t = int(sinput())
for _ in range(t):
	main()


for _ in range(int(input())):
	x = input()
	j = -1
	for i in range(len(x) - 2, -1, -1):
		if int(x[i]) + int(x[i + 1]) >= 10:
			j = i
			break
	print(x[:j] + str(int(x[j]) + int(x[j + 1])) + x[j + 2:] if j > 0 else str(int(x[0]) + int(x[1])) + x[2:])


t = int(input())
res = []
for _ in range(t):
	nums = list(input())
	flag = False
	for i in range(len(nums) - 1, 0, -1):
		if int(nums[i]) + int(nums[i - 1]) > 9:
			nums[i] = str(int(nums[i]) + int(nums[i - 1]))
			nums.pop(i - 1)
			ans = ''.join(nums)
			flag = True
			break
	if flag:
		res.append(ans)
	else:
		nums[0] = str(int(nums[0]) + int(nums[1]))
		nums.pop(1)
		res.append(''.join(nums))
for ans in res:
	print(ans)


def main():
	t = int(input())
	while t > 0:
		t -= 1
		n = list(input())
		done = False
		for i in range(len(n) - 2, -1, -1):
			first = int(n[i])
			second = int(n[i + 1])
			if first + second >= 10:
				ans = str(first + second)
				n[i] = ans[0]
				n[i + 1] = ans[1]
				done = True
				break
		if not done:
			n[1] = str(int(n[0]) + int(n[1]))
			n[0] = ''
		print(''.join(n))
main()


T = int(input())
for tc in range(T):
	s = input()
	L = list(s)
	n = len(s)
	f = False
	for i in range(n - 1, 0, -1):
		if int(L[i]) + int(L[i - 1]) > 9:
			(L[i - 1], L[i]) = list(str(int(L[i]) + int(L[i - 1])))
			f = True
			break
	if f == True:
		print(''.join(L))
	else:
		L[1] = str(int(L[0]) + int(L[1]))
		print(''.join(L)[1:])


t = int(input())

def solve():
	x = input()
	r = ''
	n = len(x)
	for i in range(len(x) - 1, 0, -1):
		if int(x[i]) + int(x[i - 1]) >= 10:
			r = x[:i - 1] + str(int(x[i]) + int(x[i - 1])) + x[i + 1:]
			return r
	r = str(int(x[0]) + int(x[1])) + x[2:]
	return r
while t:
	t -= 1
	print(solve())


import math
from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	s = input().strip()
	n = len(s)
	maxi = -1
	idx = -1
	for i in range(n - 1, 0, -1):
		if int(s[i]) + int(s[i - 1]) > 9:
			idx = i
			break
	if idx == -1:
		res = str(int(s[0]) + int(s[1])) + s[2:]
	else:
		idx -= 1
		i = 0
		res = ''
		while i < n:
			if i != idx:
				res += s[i]
				i += 1
			else:
				res += str(int(s[i]) + int(s[i + 1]))
				i += 2
	print(res)


def solve(x):
	x = list(x)
	i = len(x) - 1
	flg = 0
	while i > 1:
		num = int(x[i]) + int(x[i - 1])
		if num >= 10:
			x[i - 1] = str(num)
			print(''.join(x[:i]) + ''.join(x[i + 1:]))
			flg = 1
			break
		i -= 1
	if flg == 0:
		num = int(x[0]) + int(x[1])
		print(str(num) + ''.join(x[2:]))
n = int(input())
while n:
	x = input()
	solve(x)
	n -= 1


for _ in range(int(input())):
	s = input()
	ans = s
	n = len(s)
	a = int(s[0]) + int(s[1])
	for i in range(n - 2, -1, -1):
		a = int(s[i]) + int(s[i + 1])
		if a >= 10:
			ans = s[:i] + str(a) + s[i + 2:]
			break
	if ans == s:
		ans = str(a) + s[2:]
	print(ans)


t = int(input())
while t > 0:
	s = input()
	l = len(s)
	sum = 0
	flag = 0
	for i in range(l - 1):
		sum = int(s[i]) + int(s[i + 1])
		if sum >= 10:
			flag = 1
			break
	if l == 2:
		print(int(s[0]) + int(s[1]))
	elif len(str(int(s[l - 1]) + int(s[l - 2]))) == 2:
		print(s[:l - 2] + str(int(s[l - 1]) + int(s[l - 2])))
	elif flag == 0:
		print(str(int(s[0]) + int(s[1])) + s[2:])
	else:
		for i in range(l - 2, 0, -1):
			p = int(s[i]) + int(s[i - 1])
			if len(str(p)) == 2:
				print(s[:i - 1] + str(p) + s[i + 1:l])
				break
			else:
				continue
	t = t - 1


for s in [*open(0)][1:]:
	a = (*map(int, s[:-1]),)
	i = j = 0
	for (x, y) in zip(a, a[1:]):
		i = (i, j)[x + y > 9]
		j += 1
	print(s[:i], a[i] + a[i + 1], s[i + 2:], sep='')


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 main():
	t = int(input())
	for _ in range(t):
		s = input()
		n = len(s)
		ok = False
		for i in range(n - 1, 0, -1):
			add = int(s[i]) + int(s[i - 1])
			if add > 9:
				print(s[:i - 1] + str(add) + s[i + 1:])
				ok = True
				break
		if not ok:
			print(str(int(s[0]) + int(s[1])) + s[2:])
main()


for _ in range(int(input())):
	s = input()
	for i in range(len(s) - 1, 0, -1):
		x = int(s[i])
		y = int(s[i - 1])
		if x + y > 9:
			s = s[:i - 1] + str(x + y) + s[i + 1:]
			break
	else:
		s = str(int(s[0]) + int(s[1])) + s[2:]
	print(s)


import sys
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	s = input()
	for i in range(len(s) - 1, 0, -1):
		x = int(s[i])
		y = int(s[i - 1])
		if x + y > 9:
			s = s[:i - 1] + str(x + y) + s[i + 1:]
			break
	else:
		s = str(int(s[0]) + int(s[1])) + s[2:]
	print(s)


for (i, a) in [[len(i) - 1, i] for i in [input() for _ in range(int(input()))]]:
	while int(a[i]) + int(a[i - 1]) < 10 and i > 1:
		i -= 1
	print(a[:i - 1] + str(int(a[i]) + int(a[i - 1])) + a[i + 1:])


from random import getrandbits

def solve_while(s: str):
	it = len(s) - 1
	while it > 0:
		a = int(s[it]) + int(s[it - 1])
		if a >= 10:
			print(s[:it - 1] + str(a) + s[it + 1:])
			return
		it -= 1
	print(str(int(s[0]) + int(s[1])) + s[2:])

def solve_for(s: str):
	for it in range(len(s) - 1, 0, -1):
		a = int(s[it]) + int(s[it - 1])
		if a >= 10:
			print(s[:it - 1] + str(a) + s[it + 1:])
			return
	print(str(int(s[0]) + int(s[1])) + s[2:])
for cases in range(int(input())):
	solve_while(input()) if getrandbits(1) == 0 else solve_for(input())


def solve(s):
	n = len(s)
	for i in range(n - 2, -1, -1):
		if int(s[i]) + int(s[i + 1]) >= 10:
			s[i] = str(int(s[i]) + int(s[i + 1]))
			del s[i + 1]
			res = ''
			for i in s:
				res += i
			return res
	s[0] = str(int(s[0]) + int(s[1]))
	del s[1]
	res = ''
	for i in s:
		res += i
	return res
for test in range(int(input())):
	s = list(input())
	print(solve(s))


def main():
	s = input()
	if len(s) == 1:
		print(s)
		return
	(ind, ind1) = (-1, -1)
	for i in range(len(s) - 1, 0, -1):
		if int(s[i]) + int(s[i - 1]) >= 10:
			ind1 = i
			break
		if i - 1 == 0:
			break
	if ind1 == -1:
		print(str(int(s[0]) + int(s[1])) + str(s[2:len(s)]))
		return
	b = int(s[ind1]) + int(s[ind1 - 1])
	s1 = ''
	for j in range(0, ind1 - 1):
		s1 += s[j]
	s1 += str(b)
	for j in range(ind1 + 1, len(s)):
		s1 += s[j]
	print(s1)
t = int(input())
while t > 0:
	main()
	t -= 1


for t in range(int(input())):
	s = input()
	n = len(s)
	x = 0
	for i in range(n - 2, -1, -1):
		if int(s[i]) + int(s[i + 1]) >= 10:
			x = i
			break
	print(s[:x] + str(int(s[x]) + int(s[x + 1])) + s[x + 2:])


for l in range(int(input())):
	a = input()
	k = True
	for i in reversed(range(1, len(a))):
		if int(a[i]) + int(a[i - 1]) >= 10:
			b = str(int(a[i]) + int(a[i - 1]))
			if i != len(a) - 1:
				a = a[0:i - 1] + b[0] + b[1] + a[i + 1:]
			else:
				a = a[0:i - 1] + b[0] + b[1]
			k = False
			print(a)
			break
	if k:
		b = str(int(a[0]) + int(a[1]))
		a = b + a[2:]
		print(a)


t = int(input())
while t:
	s = input()
	n = len(s)
	ans = 0
	flag = False
	for each in range(n - 1, 0, -1):
		res = int(s[each]) + int(s[each - 1])
		if res > 9:
			ans = s[:each - 1] + str(res) + s[each + 1:]
			flag = True
			break
	if flag == True:
		print(ans)
	else:
		ans = str(int(s[0]) + int(s[1]))
		ans = ans + s[2:]
		print(ans)
	t -= 1


def solve(a):
	for i in range(len(a) - 2, -1, -1):
		num = int(a[i]) + int(a[i + 1])
		if num >= 10:
			a[i] = str(num)
			a.pop(i + 1)
			return ''.join(a)
	a[0] = str(int(a[1]) + int(a[0]))
	a.pop(1)
	return ''.join(a)
for _ in range(int(input())):
	s = list(input())
	print(solve(s))


t = int(input())
for test in range(t):
	n = input()
	flag = True
	for i in range(len(n) - 1, 0, -1):
		if int(n[i]) + int(n[i - 1]) >= 10:
			print(n[:i - 1] + str(int(n[i - 1]) + int(n[i])) + n[i + 1:])
			flag = False
			break
	if flag:
		x = str(int(n[0]) + int(n[1]))
		print(x + n[2:])


for _ in range(int(input())):
	x = [ord(c) - ord('0') for c in input()]
	n = len(x)
	for i in range(n - 2, -1, -1):
		if x[i] + x[i + 1] >= 10:
			x[i + 1] += x[i] - 10
			x[i] = 1
			break
	else:
		x[1] += x[0]
		x.pop(0)
	print(''.join([chr(c + ord('0')) for c in x]))


t = int(input())
for test in range(t):
	x = input()
	for i in range(len(x) - 2, -1, -1):
		if int(x[i]) + int(x[i + 1]) > 9:
			print(f'{x[:i]}{int(x[i]) + int(x[i + 1])}{x[i + 2:]}')
			break
	else:
		print(f'{int(x[0]) + int(x[1])}{x[2:]}')


t = int(input())
for _ in range(t):
	string = input()
	i = len(string) - 1
	while int(string[i]) + int(string[i - 1]) < 10 and i > 1:
		i -= 1
	print(string[:i - 1] + str(int(string[i]) + int(string[i - 1])) + string[i + 1:])


for iii in range(int(input())):
	s = input()
	q = ''
	flag = False
	for i in range(len(s) - 1, 0, -1):
		x = int(s[i]) + int(s[i - 1])
		if x >= 10:
			q = s[:i - 1] + str(x) + s[i + 1:]
			print(q)
			flag = True
			break
	if flag:
		continue
	for i in range(len(s) - 1):
		x = int(s[i]) + int(s[i + 1])
		if x < 10:
			q = s[:i] + str(x) + s[i + 2:]
			print(q)
			break


import sys

def solve():
	n = sys.stdin.readline().rstrip('\n')
	n = list(n)
	n = [int(_) for _ in n]
	flag = 0
	for i in range(len(n) - 2, -1, -1):
		if n[i] + n[i + 1] >= 10:
			m = n[i] + n[i + 1] - 10
			n[i + 1] = m
			n[i] = 1
			flag = 1
			break
	if flag == 0:
		m = n[0] + n[1]
		n.pop(0)
		n[0] = m
	n = [str(_) for _ in n]
	n = ''.join(n)
	print(n)
T = int(sys.stdin.readline().rstrip('\n'))
for _ in range(T):
	solve()


for q in range(int(input())):
	lst = list(input())
	for i in range(len(lst) - 2, -1, -1):
		if int(lst[i]) + int(lst[i + 1]) >= 10:
			lst[i + 1] = str(int(lst[i + 1]) + int(lst[i]) - 10)
			lst[i] = '1'
			break
	else:
		lst[1] = str(int(lst[1]) + int(lst[0]))
		lst.pop(0)
	print(''.join(lst))


for i in range(int(input())):
	x = input()
	a = -1
	for k in range(len(x) - 1, 0, -1):
		if int(x[k]) + int(x[k - 1]) >= 10:
			a = k
			break
	if a == -1:
		print(str(int(x[0]) + int(x[1])) + x[2:])
	else:
		y = str(int(x[k]) + int(x[k - 1]))
		print(x[:k - 1] + y + x[k + 1:])


for x in range(int(input())):
	n = [j for j in input()]
	c = 1
	for i in range(len(n) - 2, -1, -1):
		if int(n[i]) + int(n[i + 1]) >= 10:
			n[i] = str(int(n[i + 1]) + int(n[i]))
			n.pop(i + 1)
			c = 0
			break
	if c:
		n[0] = str(int(n[1]) + int(n[0]))
		n.pop(1)
	n = ''.join(n)
	n.replace(' ', '')
	print(n)


from cmath import *
from decimal import *

def solves():
	Str = input()
	i = len(Str) - 1
	while i > 0:
		s = int(Str[i]) + int(Str[i - 1])
		if s > 9:
			print(Str[:i - 1] + str(s) + Str[i + 1:])
			return
		i -= 1
	print(str(int(Str[0]) + int(Str[1])) + Str[2:])
t = 1
t = int(input())
for _ in range(0, t):
	solves()


for _ in range(int(input())):
	s = input()
	n = len(s)
	z = 0
	ind0 = -1
	for i in range(n - 2, -1, -1):
		x = int(s[i]) + int(s[i + 1])
		if x > 9:
			s = s[:i] + str(x) + s[i + 2:]
			z = -1
			break
	if z == -1:
		print(s)
	elif ind0 == 1:
		print(s[0] + s[2:])
	else:
		print(str(int(s[0]) + int(s[1])) + s[2:])


for _ in range(int(input())):
	a = input()
	fl = False
	for i in range(len(a) - 1, 0, -1):
		if int(a[i]) + int(a[i - 1]) > 9:
			print(a[:i - 1] + str(int(a[i]) + int(a[i - 1])) + a[i + 1:])
			fl = True
			break
	if fl:
		continue
	for i in range(len(a) - 1):
		print(a[:i] + str(int(a[i]) + int(a[i + 1])) + a[i + 2:])
		break


t = int(input())
for _ in range(t):
	s = input()
	fail = False
	for i in range(len(s) - 1, 1, -1):
		k = int(s[i - 1]) + int(s[i])
		if k >= 10:
			print(s[:i - 1], end='')
			print(1, end='')
			print(k % 10, end='')
			print(s[i + 1:])
			fail = True
			break
	if not fail:
		print(int(s[0]) + int(s[1]), end='')
		print(s[2:])


def slow(a):
	s = []
	for i in range(0, len(a) - 1):
		s.append(int(a[:i] + str(int(a[i + 1]) + int(a[i])) + a[i + 2:]))
	return str(max(s))

def fast(s):
	n = len(s)
	flag = False
	for i in range(n - 1):
		if int(s[i]) + int(s[i + 1]) >= 10:
			flag = True
			break
	if not flag:
		return str(int(s[0]) + int(s[1])) + str(s[2:])
	else:
		for i in range(n - 1, 0, -1):
			if int(s[i]) + int(s[i - 1]) >= 10:
				return s[:i - 1] + str(int(s[i]) + int(s[i - 1])) + s[i + 1:]
for _ in range(int(input())):
	print(fast(input()))


def singleinput():
	R = int(input())
	return R

def strinput():
	R = str(input())
	return R

def intarray():
	As = list(map(int, input().split()))
	return As

def matrixinput(arr):
	As = list(map(int, input().split()))
	arr.append(As)
for i in range(singleinput()):
	n = str(input())
	s = ''
	for j in range(len(n) - 2, -1, -1):
		if int(n[j]) + int(n[j + 1]) >= 10:
			s = n[0:j] + str(int(n[j]) + int(n[j + 1])) + n[j + 2:]
			break
	if len(s) > 0:
		print(s)
	else:
		print(str(int(n[0]) + int(n[1])) + n[2:])


t = int(input())
for i in range(t):
	s = input()
	n = len(s)
	j = n - 1
	flag = True
	while j > 0:
		if int(s[j]) + int(s[j - 1]) >= 10:
			flag = False
			break
		j -= 1
	if flag:
		k = int(s[0]) + int(s[1])
		print(str(k) + s[2:], end='\n')
	else:
		s = s[:j - 1] + str(int(s[j]) + int(s[j - 1])) + str(s[j + 1:])
		print(s, end='\n')


T = int(input())

def process():
	x = input()
	tot = len(x)
	for i in range(tot - 1, 0, -1):
		g1 = x[i]
		g2 = x[i - 1]
		suming = int(g1) + int(g2)
		if suming >= 10:
			ch = str(suming)
			x = list(x)
			x[i - 1] = ch[0]
			x[i] = ch[1]
			ans = ''.join(x)
			return ans
	chang = str(int(x[0]) + int(x[1]))
	x = x[1:]
	x = list(x)
	x[0] = chang
	ans = ''.join(x)
	return ans
for i in range(T):
	print(process())


t = int(input())
for _ in range(t):
	x = input()
	length = len(x)
	idx = 0
	done = False
	for i in range(length - 1, 0, -1):
		if int(x[i - 1]) + int(x[i]) >= 10:
			idx = i
			done = True
			break
	if not done:
		x = str(int(x[0]) + int(x[1])) + x[2:]
	else:
		x = x[:idx - 1] + str(int(x[idx - 1]) + int(x[idx])) + x[idx + 1:]
	print(x)


t = int(input())
for _ in range(t):
	(x, num_digit_preserved) = (input(), False)
	for i in range(len(x) - 1, 0, -1):
		s = int(x[i]) + int(x[i - 1])
		if s > 9:
			print(x[:i - 1] + str(s) + x[i + 1:])
			num_digit_preserved = True
			break
	if not num_digit_preserved:
		print(str(int(x[0]) + int(x[1])) + x[2:])


for _ in range(int(input())):
	num = input()
	for i in range(len(num) - 1, 0, -1):
		if int(num[i]) + int(num[i - 1]) >= 10:
			res = num[:i - 1] + str(int(num[i]) + int(num[i - 1])) + num[i + 1:]
			print(res)
			break
	else:
		res = str(int(num[0]) + int(num[1])) + num[2:]
		print(res)


for _ in range(int(input())):
	x = input()
	i = len(x) - 1
	if len(x) != 2:
		while i > 1 and int(x[i]) + int(x[i - 1]) < 10:
			i -= 1
		x += '0'
		print((x[:i - 1] + str(int(x[i]) + int(x[i - 1])) + x[i + 1:])[:-1])
	elif len(x) == 2:
		print(str(int(x[-1]) + int(x[-2])))


t = int(input())
for _ in range(t):
	s = input()
	ddig = False
	changeInd = None
	changeValue = None
	for i in range(len(s) - 1):
		if int(s[i]) + int(s[i + 1]) >= 10:
			ddig = True
			changeInd = i
			changeValue = int(s[i]) + int(s[i + 1])
			break
	if not ddig:
		flag = False
		for i in range(len(s) - 1):
			if s[i] != '0' or s[i + 1] != '0':
				changeInd = i
				changeValue = int(s[i]) + int(s[i + 1])
				flag = True
				break
		if not flag:
			changeInd = len(s) - 2
			changeValue = int(s[-1]) + int(s[-2])
	else:
		for i in range(len(s) - 1, 0, -1):
			if int(s[i]) + int(s[i - 1]) >= 10:
				changeInd = i - 1
				changeValue = int(s[i]) + int(s[i - 1])
				break
	print(s[:changeInd] + str(changeValue) + s[changeInd + 2:])


def solve():
	n = input()
	arr = [i for i in n]
	for i in range(len(arr) - 2, -1, -1):
		temp_sum = int(arr[i]) + int(arr[i + 1])
		if temp_sum >= 10:
			arr[i] = str(temp_sum // 10)
			arr[i + 1] = str(temp_sum % 10)
			print(''.join(arr))
			return
	arr[1] = str(int(arr[0]) + int(arr[1]))
	arr = arr[1:]
	print(''.join(arr))
	return
for _ in range(int(input())):
	solve()


t = int(input())
while t != 0:
	x = input()
	s = list(x)
	flag = 0
	for i in range(len(s) - 2, -1, -1):
		if int(s[i]) + int(s[i + 1]) >= 10:
			flag += 1
			net = int(s[i]) + int(s[i + 1])
			s[i] = str(net // 10)
			s[i + 1] = str(net % 10)
			break
	if flag == 0:
		net = int(s[0]) + int(s[1])
		s[1] = str(net)
		s = s[1:]
	ans = ''.join(s)
	print(ans)
	t -= 1


t = int(input())
for i in range(t):
	s = input()
	k = len(s)
	an = ''
	for i in range(k - 1, 1, -1):
		if int(s[i]) + int(s[i - 1]) > 9:
			an += s[:i - 1] + str(int(s[i - 1]) + int(s[i])) + s[i + 1:]
			break
	else:
		an += str(int(s[0]) + int(s[1])) + s[2:]
	print(an)


for _ in range(int(input())):
	s = input()
	pos = 0
	for i in range(len(s) - 2, -1, -1):
		if int(s[i]) + int(s[i + 1]) >= 10:
			pos = i
			break
	print(s[:pos] + str(int(s[pos]) + int(s[pos + 1])) + s[pos + 2:])


for _ in range(int(input())):
	s = input()
	cond = True
	for i in range(len(s) - 2, -1, -1):
		if int(s[i]) + int(s[i + 1]) > 9:
			s = s[0:i] + str(int(s[i]) + int(s[i + 1])) + s[i + 2:]
			cond = False
			break
	if cond:
		s = str(int(s[0]) + int(s[1])) + s[2:]
	print(s)


def fun(n):
	j = 0
	for i in range(len(n) - 1):
		if int(n[i]) + int(n[i + 1]) >= 10:
			j = i
	return n[:j] + str(int(n[j]) + int(n[j + 1])) + n[j + 2:]
for i in range(int(input())):
	print(fun(input()))


def solve(x):
	i = len(x) - 1
	while int(x[i]) + int(x[i - 1]) < 10 and i > 1:
		i = i - 1
	print(x[:i - 1] + str(int(x[i]) + int(x[i - 1])) + x[i + 1:])
debugmode = 0
if debugmode:
	with open('input.txt', 'r') as f:
		t = int(f.readline())
		for i in range(t):
			x = f.readline()
			x = x[:-1]
			solve(x)
else:
	t = int(input())
	for i in range(t):
		x = input()
		solve(x)


t = int(input())
for i in range(t):
	x = input()
	ind = len(x) - 1
	while int(x[ind]) + int(x[ind - 1]) < 10 and ind > 0:
		ind -= 1
	if ind != 0:
		ind -= 1
	s = x[0:ind] + str(int(x[ind]) + int(x[ind + 1])) + x[ind + 2:len(x)]
	print(s)


t = int(input())
for i in range(t):
	cnt = 0
	a = input()
	ln = len(a)
	for i in range(ln - 1, 0, -1):
		if int(a[i]) + int(a[i - 1]) > 9:
			s = a[:i - 1] + str(int(a[i]) + int(a[i - 1])) + a[i + 1:ln]
			break
		cnt += 1
	if cnt == ln - 1:
		s = str(int(a[0]) + int(a[1])) + a[2:ln]
	print(s)


sz = len

def solve():
	x = input()
	for i in range(sz(x) - 1):
		j = sz(x) - i - 1
		y = int(x[j]) + int(x[j - 1])
		if y >= 10:
			print(x[:j - 1] + str(y) + x[j + 1:])
			return
	y = int(x[0]) + int(x[1])
	print(str(y) + x[2:])
	return
t = int(input())
while t > 0:
	t -= 1
	solve()


t = int(input())
for i in range(t):
	x = input()
	ans = -1
	for j in reversed(range(len(x) - 1)):
		main = int(x[j]) + int(x[j + 1])
		if main >= 10:
			pre = x[0:j]
			post = x[j + 2:]
			ans = pre + str(main) + post
			break
	if ans == -1:
		ans = str(int(x[0]) + int(x[1])) + x[2:]
	print(ans)


t = int(input())
for i in range(t):
	a = 0
	max = 0
	string_s = input()
	string = [int(x) for x in string_s]
	if len(string_s) == 1:
		print(string_s)
		continue
	for j in range(len(string) - 2, -1, -1):
		if string[j] + string[j + 1] >= 10:
			string[j + 1] += string[j] - 10
			string[j] = 1
			a = 1
			break
	if a == 1:
		st = [str(x) for x in string]
		y = ''.join(st)
		print(y)
		continue
	print(str(int(string_s[0]) + int(string_s[1])) + string_s[2:])


for _ in range(int(input())):
	s = input()
	s = s[::-1]
	s = list(s)
	flag = 0
	for i in range(0, len(s) - 2):
		temp = int(s[i]) + int(s[i + 1])
		if temp > 9:
			temp = str(temp)
			s[i] = temp[1]
			s[i + 1] = temp[0]
			s = s[::-1]
			s = ''.join(s)
			flag = 1
			break
	if flag == 1:
		print(s)
	else:
		s = s[::-1]
		temp = int(s[0]) + int(s[1])
		s = s[2:len(s)]
		s = ''.join(s)
		print(str(temp) + s)