During a daily walk Alina noticed a long number written on the ground. Now Alina wants to find some positive number of same length without leading zeroes, such that the sum of these two numbers is a palindrome.

Recall that a number is called a palindrome, if it reads the same right to left and left to right. For example, numbers $121, 66, 98989$ are palindromes, and $103, 239, 1241$ are not palindromes.

Alina understands that a valid number always exist. Help her find one!


-----Input-----

The first line of input data contains an integer $t$ ($1 \leq t \leq 100$) — the number of test cases. Next, descriptions of $t$ test cases follow.

The first line of each test case contains a single integer $n$ ($2 \leq n \leq 100000$) — the length of the number that is written on the ground.

The second line of contains the positive $n$-digit integer without leading zeroes — the number itself.

It is guaranteed that the sum of the values $n$ over all test cases does not exceed $100000$.


-----Output-----

For each of $t$ test cases print an answer — a positive $n$-digit integer without leading zeros, such that the sum of the input integer and this number is a palindrome.

We can show that at least one number satisfying the constraints exists. If there are multiple solutions, you can output any of them.


-----Examples-----

Input
3
2
99
4
1023
3
385
Output
32
8646
604


-----Note-----

In the first test case $99 + 32 = 131$ is a palindrome. Note that another answer is $12$, because $99 + 12 = 111$ is also a palindrome.

In the second test case $1023 + 8646 = 9669$.

In the third test case $385 + 604 = 989$.

Source: codeforces | Difficulty: EASY
Tags: Mathematics

Implementation

Constructive algorithms


Solutions:
def solve():
	n = int(input())
	s = input()
	res = [''] * n
	ascii_9 = ord('9')
	ascii_1 = ord('1')
	ascii_0 = ord('0')
	if s[0] == '9':
		is_borrowed = False
		for i in range(n - 1, -1, -1):
			num = 0
			ascii_i = ord(s[i])
			if not is_borrowed:
				if ascii_1 >= ascii_i:
					num = ascii_1 - ascii_i
				else:
					is_borrowed = True
					num = 11 - (ascii_i - ascii_0)
			elif ascii_0 == ascii_i:
				num = ascii_0 - ascii_i
				is_borrowed = False
			else:
				num = 10 - (ascii_i - ascii_0)
			res[i] = str(num)
		print(''.join(res))
	else:
		for i in range(n - 1, -1, -1):
			res[i] = str(ascii_9 - ord(s[i]))
		print(''.join(res))
for _ in range(int(input())):
	solve()


def main():
	n = int(input())
	s = input()
	ans = []
	if s[0] == '9':
		p = 0
		for i in s[::-1]:
			i = int(i) + p
			if i == 1:
				ans.append('0')
				p = 0
			elif i == 0:
				ans.append('1')
				p = 0
			else:
				ans.append(str(11 - i))
				p = 1
		ans.reverse()
	else:
		for i in s:
			ans.append(str(9 - int(i)))
	print(''.join(ans))
for _ in range(int(input())):
	main()


a = int(input())
(x, y) = (0, 0)
ans = ''
l = []
for i in range(a):
	n = int(input())
	s = input()
	if s[0] != '9':
		for j in range(n):
			x = ord(s[j]) - 48
			y = 9 - x
			ans += chr(y + 48)
		l.append(ans)
		ans = ''
	else:
		c = 0
		for j in range(n - 1, -1, -1):
			x = ord(s[j]) - 48
			x += c
			if x > 1:
				y = 11 - x
				c = 1
				ans += chr(y + 48)
			else:
				c = 0
				y = 1 - x
				ans += chr(y + 48)
		l.append(ans[::-1])
	ans = ''
for i in l:
	print(i)


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

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

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

def solve():
	n = ii()
	num = si()
	ans = ''
	if num[0] == '9':
		carry = 0
		for i in range(n - 1, -1, -1):
			curr = int(num[i]) + carry
			if curr < 2:
				ans += str(1 - curr)
				carry = 0
			else:
				ans += str(11 - curr)
				carry = 1
		ans = ans[::-1]
	else:
		for i in num:
			ans += str(9 - int(i))
	print(ans)
	return

def main():
	tt = ii()
	for i in range(tt):
		solve()
main()


import sys
import collections
from math import ceil, gcd, sqrt, log
import bisect
INF = float('inf')
mod = 1000000007

def solve():
	n = int(input())
	s = input()
	A = ['' for i in range(n)]
	if s[0] != '9':
		for i in range(n):
			k = 9 - int(s[i])
			A[i] = str(k)
	else:
		c = 0
		j = n - 1
		while j >= 0 and int(s[j]) < 2:
			if s[j] == '0':
				A[j] = '1'
			else:
				A[j] = '0'
			j -= 1
		for i in range(j, -1, -1):
			if int(s[i]) + c > 1:
				k = 11 - (int(s[i]) + c)
				c = 1
				ok = k
				A[i] = str(ok)
			elif int(s[i]) + c == 1:
				A[i] = '0'
				c = 0
			else:
				A[i] = '1'
				c = 0
	print(''.join(A))
t = int(input())
while t != 0:
	solve()
	t -= 1


t = int(input())
while t > 0:
	n = int(input())
	s = input()
	result = ''
	if s[0] == '9':
		c = 0
		for i in range(n - 1, -1, -1):
			x = ord(s[i]) - ord('0')
			x += c
			if x > 1:
				y = 11 - x
				c = 1
				result += chr(y + ord('0'))
			else:
				c = 0
				y = 1 - x
				result += chr(y + ord('0'))
		result = result[::-1]
	else:
		for c in s:
			result += str(9 - (ord(c) - ord('0')))
	print(result)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	s = input()
	if s[0] == '9':
		c = 0
		ans = ''
		for i in range(n - 1, -1, -1):
			d = int(s[i]) + c
			if d <= 1:
				c = 0
				ans += str(1 - d)
			else:
				c = 1
				ans += str(11 - d)
		print(ans[::-1])
	else:
		a = ''
		for i in range(n):
			a += str(9 - int(s[i]))
		print(a)


for i in range(int(input())):
	n = int(input())
	s = input()
	s1 = ''
	k = 0
	if s[0] == '9':
		for i in range(n - 1, -1, -1):
			if s[i] == '0' and k == 1:
				s1 += '0'
				k = 0
			elif s[i] == '0':
				s1 += '1'
			elif s[i] == '1' and k == 0:
				s1 += '0'
			else:
				ans = str(11 - (int(s[i]) + k))
				s1 += ans
				k = 1
	else:
		for i in range(n - 1, -1, -1):
			ans = str(9 - int(s[i]))
			s1 += ans
	print(s1[-1::-1])


t = int(input())
while t:
	t -= 1
	n = int(input())
	first_number = input()
	zero = ord('0')
	if n == 1:
		print(first_number)
	if first_number[0] == '9':
		extra = 0
		ans = []
		for i in range(n - 1, -1, -1):
			sub = ord(first_number[i]) - zero + extra
			if sub <= 1:
				gap = 1 - sub
				extra = 0
			else:
				gap = 11 - sub
				extra = 1
			ans.append(str(gap))
		ans.reverse()
		print(''.join(ans))
	else:
		for i in range(n):
			print(9 - (ord(first_number[i]) - zero), end='')
		print()


for _ in range(int(input())):
	n = int(input())
	string = input()
	i = -1
	answer = []
	if string[0] == '9':
		curr = [1 for i in range(n + 1)]
		while i >= -n:
			if int(string[i]) > curr[i]:
				curr[i - 1] = 0
				curr[i] += 10
			answer.append(str(curr[i] - int(string[i])))
			i -= 1
	else:
		while i >= -n:
			answer.append(str(9 - int(string[i])))
			i -= 1
	print(''.join(answer[::-1]))


def leading_nine(num, n):
	num = num[::-1]
	carry = 0
	res = n * [0]
	for i in range(n):
		curr = int(num[i]) + carry
		if curr == 1:
			res[i] = '0'
			carry = 0
		elif curr == 0:
			res[i] = '1'
			carry = 0
		else:
			res[i] = str(11 - curr)
			carry = 1
	res = ''.join(res)
	return res[::-1]
t = int(input())
while t:
	n = int(input())
	s = input()
	if s[0] == '9':
		print(leading_nine(s, n))
		t -= 1
		continue
	for digit in s:
		print(9 - int(digit), end='')
	print()
	t -= 1


for t in range(int(input())):
	n = int(input())
	s = str(input())
	s = list(s)
	if s[0] == '9':
		target = ['1'] * (n + 1)
		result = []
		j = n - 1
		while j >= 0:
			if int(target[j + 1]) >= int(s[j]):
				result.append(str(int(target[j + 1]) - int(s[j])))
			else:
				target[j] = '0'
				result.append(str(int(target[j + 1]) + 10 - int(s[j])))
			j -= 1
		result.reverse()
		print(''.join(result))
	else:
		target = ['9'] * n
		result = []
		for i in range(n):
			result.append(str(int(target[i]) - int(s[i])))
		print(''.join(result))


for _ in [0] * int(input()):
	n = int(input())
	a = [*map(int, [*input()])]
	if a[0] != 9:
		for i in range(n):
			print(str(9 - a[i]), end='')
		print()
		continue
	s = ''
	re = 0
	for i in range(n - 1, -1, -1):
		s += str((1 - a[i] - re) % 10)
		re = a[i] + re > 1
	print(s[::-1])


loopcount = int(input())
for loop in range(loopcount):
	n = int(input())
	output = [0 for i in range(n)]
	a = input()
	a = list(a)
	if a[0] == '9':
		carry = 0
		i = n - 1
		while i >= 0:
			output[i] += (11 - int(a[i]) - carry) % 10
			if int(a[i]) + carry > 1:
				carry = 1
			else:
				carry = 0
			i -= 1
	else:
		for i in range(n):
			output[i] += 9 - int(a[i])
	print(''.join([str(i) for i in output]))


for _ in range(int(input())):
	n = int(input())
	string = input()
	i = -1
	answer = []
	if string[0] == '9':
		curr = [1 for i in range(n + 1)]
		while i >= -n:
			if int(string[i]) > curr[i]:
				curr[i - 1] = 0
				curr[i] += 10
			answer.append(str(curr[i] - int(string[i])))
			i -= 1
	else:
		while i >= -n:
			answer.append(str(9 - int(string[i])))
			i -= 1
		while len(answer) and answer[-1] == '0':
			answer.pop(-1)
	print(''.join(answer[::-1]) if len(answer) else '2')


import os, sys
isLocal = os.environ.get('USER', '') == 'xueenpeng'
if isLocal:
	sys.stdin = open('./file/input.txt', 'r')
	pass
t = int(input())
for _ in range(t):
	n = int(input())
	num = input()
	ans = ''
	for ch in num:
		ans += str(9 - int(ch))
	if num[0] != '9':
		print(ans)
		continue
	result = []
	for ch in ans[::-1]:
		result.append(int(ch))
	if n >= 1:
		result[0] += 2
	if n >= 2:
		result[-1] += 1
	if n >= 3:
		result[1] += 1
	cur = 0
	while cur < len(result):
		if result[cur] > 9:
			result[cur] -= 10
			result[cur + 1] += 1
		cur += 1
	ans = ''
	for num in result[::-1]:
		ans += str(num)
	print(ans)


T = int(input())
for t in range(0, T):
	n = int(input())
	k = input()
	lst = []
	if int(k[0]) <= 8:
		for a in range(0, n):
			lst.append(9 - int(k[a]))
	else:
		for a in range(0, n - 1):
			lst.append(10 - int(k[a]))
		lst.append(11 - int(k[n - 1]))
		i = n - 1
		while i > 0:
			if lst[i] > 9:
				lst[i] = lst[i] - 10
				lst[i - 1] = lst[i - 1] + 1
				i = i - 1
			else:
				i = i - 1
	for i in lst:
		print(i, end='')
	print()


def getInverse(c, k):
	x = ord(c) - 48
	return k - x
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	k = 9
	if s[0] == '9':
		k = 10
	pile = [0] * n
	rem = 0
	i = n - 1
	while i >= 0:
		x = getInverse(s[i], k)
		pile[i] = rem + x
		if rem:
			rem = 0
		if pile[i] >= 10:
			pile[i] -= 10
			rem = 1
		i -= 1
	if s[0] == '9':
		pile[n - 1] += 1
	if pile[n - 1] == 10:
		pile[n - 1] = 0
		i = n - 2
		while i >= 0:
			pile[i] += 1
			if pile[i] == 10:
				pile[i] = 0
			else:
				break
			i -= 1
	for z in pile:
		print(z, end='')
	print('\n')


t = int(input())
for i in range(t):
	l = int(input())
	n = input()
	pal1 = '99'
	pal2 = '111'
	for j in range(l - 2):
		pal1 = pal1 + '9'
		pal2 = pal2 + '1'
	li = []
	carry = 0
	for k in range(l):
		if n[0] != '9':
			ri_di1 = int(pal1[l - 1 - k])
			ri_di2 = int(n[l - 1 - k])
			sub = ri_di1 - ri_di2
			li.append(str(sub))
		else:
			ri_di1 = int(pal2[l - 1 - k])
			ri_di2 = int(n[l - 1 - k])
			if ri_di1 < ri_di2 + carry:
				sub = 10 + ri_di1 - ri_di2 - carry
				carry = 1
			else:
				sub = ri_di1 - ri_di2 - carry
				carry = 0
			li.append(str(sub))
	string = ''
	for m in range(len(li)):
		string = string + li[len(li) - 1 - m]
	print(string)


for _ in range(int(input())):
	n = int(input())
	x = input()
	y = n * '9'
	s = ''
	for i in range(n):
		s += str(9 - int(x[i]))
	y = s
	if '9' in x:
		new = '1' * (n - 1) + '2'
		carry = '0'
		s = list(s)
		f = 1
		if x[0] != '9':
			f = 0
		if f:
			for i in range(n - 1, -1, -1):
				temp = str(int(s[i]) + int(new[i]) + int(carry))
				if len(temp) == 2:
					carry = temp[0]
					s[i] = temp[1]
				else:
					carry = '0'
					s[i] = temp[0]
			if int(carry):
				s[0] = str(int(s[0]) + int(carry))
			for i in s:
				print(i, end='')
			print()
		else:
			print(y)
	else:
		print(s)


for _ in range(int(input())):
	n = int(input())
	my = input()
	lst = list(map(int, my))
	flag = 0
	pre = lst[0]
	if pre == 9:
		string = '1' * (len(lst) + 1)
		ans = int(string) - int(my)
		print(ans)
	else:
		for i in range(len(lst) - 1):
			print(9 - lst[i], end='')
		print(9 - lst[-1])


for _ in range(int(input())):
	n = int(input())
	s = input()
	k = ''
	if s[0] != '9':
		for i in s:
			k += str(9 - int(i))
		print(k)
	else:
		k = '1' * n + '1'
		print(int(k) - int(s))


def check(a, n):
	A = list(map(int, list(a)))
	B = []
	if A[0] != 9:
		for k in A:
			B.append(str(9 - k))
		return ''.join(B)
	else:
		B = ['1'] * (n + 1)
		return int(''.join(B)) - int(a)
for t in range(int(input())):
	n = int(input())
	A = input()
	print(check(A, n))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	s = input()
	if s[0] != '9':
		for i in s:
			print(9 - int(i), end='')
		print()
	else:
		to = '1' * (n + 1)
		print(int(to) - int(s))


def is_all_9(s: str) -> bool:
	for c in s:
		if c != '9':
			return False
	return True

def nine_with_len(n: int) -> str:
	return '9' * n
t = int(input())
while t:
	t -= 1
	n = int(input())
	s = input()
	if s[0] == '9':
		print(int('1' * (n + 1)) - int(s))
	else:
		s2 = nine_with_len(n)
		r = []
		for c in s:
			r.append(str(9 - (ord(c) - ord('0'))))
		print(''.join(r))


T = int(input())
for _ in range(T):
	n = int(input())
	a = input()
	if a[0] != '9':
		a = list(a)
		for i in range(len(a)):
			a[i] = chr(ord('9') - ord(a[i]) + ord('0'))
		print(''.join(a))
	else:
		s = '1' * (n + 1)
		print(int(s) - int(a))


t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	b = int(a)
	res = [0] * n
	if a[0] == '9':
		qwe = ''
		for i in range(n + 1):
			qwe += '1'
		foo = int(qwe)
		print(foo - b)
	else:
		p1 = 0
		p2 = n - 1
		while p1 <= p2:
			res[p1] = 9 - int(a[p1])
			res[p2] = 9 - int(a[p2])
			p1 += 1
			p2 -= 1
		for i in range(n):
			print(res[i], sep='', end='')
		print('')


t = int(input())
for i in range(0, t):
	n = int(input())
	s = str(input())
	res = ''
	if s[0] < '9':
		for j in range(0, n):
			res += str(ord('9') - ord(s[j]))
	else:
		w = ''
		for j in range(0, n + 1):
			w += '1'
		res = int(w) - int(s)
	print(res)


c = int(input())
for i in range(c):
	cc = int(input())
	s = input()
	n = -1
	ans = 0
	res = 0
	ans = '1'
	for h in range(cc - 2):
		ans += '1'
	ans += '2'
	for j in range(cc):
		if s[j] != '9':
			res = str(9 - int(s[j]))
			n = j
			break
	if n == -1:
		ans = '1'
		for h in range(cc - 2):
			ans += '1'
		ans += '2'
		print(ans)
	else:
		for j in range(n + 1, len(s), 1):
			res += str(9 - int(s[j]))
		if len(res) != len(ans):
			print(int(ans) + int(res))
		else:
			print(res)


import sys, math

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():
	for _ in range(int(input())):
		n = int(input())
		s = input()
		if s.count('9') == n:
			for i in range(n - 1):
				print('1', end='')
			print('2')
		elif s[0] == '9':
			temp = '1' * (n + 1)
			res = int(temp) - int(s)
			print(res)
		else:
			for i in range(n):
				print(9 - int(s[i]), end='')
			print()
main()


def subtract(num1, num2):
	total = ''
	counter = len(num1) - 1
	while counter > 0:
		x = int(num1[counter])
		y = int(num2[counter - 1])
		if x >= y:
			total = str(x - y) + total
		else:
			total = str(10 + x - y) + total
			num1[counter - 1] = str(int(num1[counter - 1]) - 1)
		counter -= 1
	return total
t = int(input())
for i in range(t):
	n = int(input())
	s = list(input())
	total = ''
	for j in range(len(s) - 1, -1, -1):
		rem = str(9 - int(s[j]))
		total = rem + total
	if total[0] == '0':
		num = list('1' * (len(s) + 1))
		total = subtract(num, s)
	print(total)


for _ in range(int(input().strip())):
	n = int(input().strip())
	s = input().strip()
	if s[0] != '9':
		for i in s:
			print(str(ord('9') - ord(i)), end='')
		print()
	else:
		t = ''
		for i in range(n + 1):
			t += '1'
		print(int(t) - int(s))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	nn = input()
	ans = ''
	if nn[0] == '9':
		ans = '1' * (n + 1)
		ans = int(ans) - int(nn)
	else:
		for e in nn:
			ans += str(9 - int(e))
	print(ans)


import sys
input = lambda : sys.stdin.readline().strip()
for i in range(int(input())):
	a = int(input())
	b = input()
	c = ''
	if b[0] == '9':
		d = int('1' * (a + 1))
		print(d - int(b))
	else:
		for i in b:
			c += str(9 - int(i))
		print(c)


t = int(input())
for j in range(t):
	n = int(input())
	s = input()
	if s[0] == '9':
		st = ''
		for i in range(n + 1):
			st += '1'
		print(int(st) - int(s))
	else:
		print(pow(10, n) - 1 - int(s))


for t in range(int(input())):
	n = int(input())
	nm = input()
	if int(nm[0]) < 9:
		res = ''
		for i in range(n):
			res += str(9 - int(nm[i]))
		print(res)
	else:
		res1 = ''
		for i in range(n):
			res1 += '1'
		res2 = ''
		for i in range(n):
			res2 += str(9 - int(nm[i]))
		res = int(res1) + int(res2) + 1
		print(res)


for _ in range(int(input())):
	n = int(input())
	x = input()
	if x[0] == '9':
		y = (10 ** (n + 1) - 1) // 9
		print(y - int(x))
	else:
		y = 10 ** n - 1
		print(y - int(x))


t = int(input())
for _ in range(t):
	n = int(input())
	num = input()
	if num[0] == '9':
		print((10 ** (n + 1) - 1) // 9 - int(num))
	else:
		print(10 ** n - 1 - int(num))


for _ in range(int(input())):
	n = int(input())
	N = input()
	if N[0] == '9':
		print((10 ** (n + 1) - 1) // 9 - int(N))
	else:
		print(10 ** n - 1 - int(N))


t = int(input())
while t > 0:
	n = int(input())
	s = input()
	if s[0] != '9':
		print(10 ** n - 1 - int(s))
	else:
		print(int((n + 1) * '1') - int(s))
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	number = input()
	s = ''
	for j in range(len(number) - 1, -1, -1):
		if int(number[0]) < 9:
			s = str(9 - int(number[j])) + s
		elif j == n - 1:
			if int(number[j]) <= 1:
				s = str(1 - int(number[j])) + s
			else:
				s = str(11 - int(number[j])) + s
		else:
			mem = int(int(s[0]) + int(number[j + 1]) >= 10)
			if 11 - mem - int(number[j]) >= 10:
				s = str(1 - int(number[j]) - mem) + s
			else:
				s = str(11 - int(number[j]) - mem) + s
	print(s)


T = int(input())
for _ in range(T):
	n = int(input())
	s = input()
	if s[0] == '9':
		ans = (10 ** (n + 1) - 1) // 9 - int(s)
		print(ans)
	else:
		ans = 10 ** n - 1 - int(s)
		print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	s = int(a)
	ans = 0
	if a[0] != '9':
		ans = 10 ** n - 1 - s
	else:
		ans = (10 ** (n + 1) - 1) // 9 - s
	print(ans)


pal = int(input())
for _ in range(pal):
	num = int(input())
	num2 = input()
	if num2[0] == '9':
		print((10 ** (num + 1) - 1) // 9 - int(num2))
	else:
		print(10 ** num - 1 - int(num2))


n = int(input())
for i in range(n):
	l = int(input())
	m = input()
	if m[0] == '9':
		m = int(m)
		print((pow(10, l + 1) - 1) // 9 - m)
	else:
		m = int(m)
		print(pow(10, l) - 1 - m)


t = int(input())
for i in range(t):
	size = int(input())
	num = input()
	temp = int(num)
	if num[0] == '9':
		res = (pow(10, size + 1) - 1) // 9 - temp
		print(res)
	else:
		res = pow(10, size) - temp - 1
		print(res)


T = int(input())
while T > 0:
	T -= 1
	len = int(input())
	string = input()
	n = int(string)
	if string[0] == '9':
		print((10 ** (len + 1) - 1) // 9 - n)
	else:
		print(10 ** len - 1 - n)


t = int(input())
for _ in range(t):
	n = int(input())
	a = str(input())
	s = 10 ** n - 1 if a[0] != '9' else (10 ** (n + 1) - 1) // 9
	print(s - int(a))


for i in range(int(input())):
	n = int(input())
	s = input()
	if s[0] == '9':
		print(int('1' * (n + 1)) - int(s))
	else:
		print(''.join([str(9 - int(j)) for j in s]))


a = int(input())
for i in range(a):
	b = int(input())
	c = input()
	if c[0] == '9':
		print(int((b + 1) * '1') - int(c))
	else:
		print(int(b * '9') - int(c))


for z in range(int(input())):
	n = int(input())
	s_str = input()
	s = int(s_str)
	if s_str[0] == '9':
		print(int('1' * (n + 1)) - s)
	else:
		print(int('9' * n) - s)


def solve(n, s):
	if s[0] != '9':
		for i in range(n):
			print(9 - int(s[i]), end='')
		print()
	else:
		ss = '1' * (n + 1)
		print(int(ss) - int(s))
t = int(input())
while t > 0:
	n = int(input())
	s = input()
	solve(n, s)
	t -= 1


tests = int(input())
for _ in range(tests):
	n = int(input())
	p = input()
	if p[0] != '9':
		print(int('9' * n) - int(p))
	else:
		print(int('1' * (n + 1)) - int(p))


from math import log
for _ in range(int(input())):
	n = int(input())
	a = list(input())
	if a[0] != '9':
		for i in range(len(a)):
			a[i] = str(9 - int(a[i]))
		a = int(''.join(a))
	else:
		pal = '1' * (len(a) + 1)
		a = int(pal) - int(''.join(a))
	print(a)


t = int(input())
while t > 0:
	t -= 1
	y = int(input())
	str1 = str(input())
	cnt = len(str1)
	ans = ''
	if str1[0] == '9':
		cnt += 1
		while cnt > 0:
			ans += '1'
			cnt -= 1
	else:
		while cnt > 0:
			ans += '9'
			cnt -= 1
	x = int(str1)
	ans = int(ans)
	print(ans - x)