A numeric string, $s$, is beautiful if it can be split into a sequence of two or more positive integers, $a[1],a[2],...,a[n]$, satisfying the following conditions:

$a[i]-a[i-1]=1$ for any $1<i\leq n$ (i.e., each element in the sequence is $1$ more than the previous element).
No $a[i]$ contains a leading zero. For example, we can split $s=10203$ into the sequence $\{1,02,03\}$, but it is not beautiful because $02$ and $03$ have leading zeroes.
The contents of the sequence cannot be rearranged. For example, we can split $s=312$ into the sequence $\{3,1,2\}$, but it is not beautiful because it breaks our first constraint (i.e., $1-3\neq1$).

The diagram below depicts some beautiful strings:

Perform $q$ queries where each query consists of some integer string $s$. For each query, print whether or not the string is beautiful on a new line. If it is beautiful, print YES x, where $x$ is the first number of the increasing sequence.  If there are multiple such values of $x$, choose the smallest.  Otherwise, print NO.  

Function Description  

Complete the separateNumbers function in the editor below.  

separateNumbers has the following parameter:  

s: an integer value represented as a string   

Prints 

- string:  Print a string as described above. Return nothing.  

Input Format

The first line contains an integer $q$, the number of strings to evaluate. 

Each of the next $q$ lines contains an integer string $s$ to query.

Constraints

$1\leq q\leq10$
$1\leq|s|\leq32$
$s[i]\in[0-9]$

Sample Input 0
7
1234
91011
99100
101103
010203
13
1

Sample Output 0
YES 1
YES 9
YES 99
NO
NO
NO
NO

Explanation 0

The first three numbers are beautiful (see the diagram above). The remaining numbers are not beautiful:

For $s=101103$, all possible splits violate the first and/or second conditions.
For $s=010203$, it starts with a zero so all possible splits violate the second condition.
For $s=13$, the only possible split is $\{1,3\}$, which violates the first condition.
For $s=1$, there are no possible splits because $s$ only has one digit.

Sample Input 1
4
99910001001
7891011
9899100
999100010001

Sample Output 1
YES 999
YES 7
YES 98
NO

Source: hackerrank | Difficulty: EASY
Tags: String algorithms


Solutions:
for _ in range(int(input())):
	s = input().strip()
	n = len(s)
	x = ''
	for i in s[:-1]:
		x += i
		y = int(x)
		z = ''
		while len(z) < n:
			z += str(y)
			y += 1
		if n == len(z) and z == s:
			print('YES', x)
			break
	else:
		print('NO')


tn = int(input())
for tt in range(tn):
	s = input().split()[0]
	res = -1
	for l in range(1, len(s)):
		x = int(s[:l])
		if len(str(x)) != l:
			continue
		ss = str(x)
		xx = x
		while len(ss) < len(s):
			xx += 1
			ss += str(xx)
		if ss == s:
			res = x
			break
	if res != -1:
		print('YES %d' % res)
	else:
		print('NO')


import sys
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	x = -1
	for i in range(len(s) - 1):
		y = int(s[:i + 1])
		t = ''
		while len(t) < len(s):
			t += str(y)
			y += 1
		if t == s:
			x = int(s[:i + 1])
	if x == -1:
		print('NO')
	else:
		print('YES', x)


import sys

def check(s, init):
	cnt = len(s)
	beg = 0
	if len(init) == 0 or init[0] == 0:
		return False
	init = int(init)
	while beg < cnt:
		sinit = str(init)
		if s[beg:beg + len(sinit)] == sinit:
			beg += len(sinit)
			init += 1
		else:
			return False
	return True
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	flag = True
	for i in range(len(s)):
		if check(s, s[:i]):
			print('YES', s[:i])
			flag = False
			break
	if flag:
		print('NO')


def sequence(s):
	x = int(s)
	ans = []
	tmp = s
	for i in range(x + 1, x + 40):
		tmp += str(i)
		ans.append(tmp)
	return ans
for _ in range(int(input())):
	s = input()
	l = len(s)
	tmp = ''
	found = False
	for c in s:
		tmp += c
		if s in sequence(tmp):
			print('YES', tmp)
			found = True
			break
	if not found:
		print('NO')


import sys

def trial(string, index):
	total = 0
	length = len(string)
	if index == 0:
		first = int(string[0])
	else:
		first = int(string[:index])
	curr = first
	total += len(str(curr))
	while total < length:
		nextn = curr + 1
		nextlen = len(str(curr + 1))
		if nextlen + total > length:
			return False
		else:
			nextstrnum = int(string[total:total + nextlen])
			if nextstrnum != nextn:
				return False
			total += nextlen
			curr = nextn
	return True
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	flag = False
	index = -1
	for i in range(len(s)):
		if flag == False:
			flag = trial(s, i)
			if flag == True:
				index = i
	if flag == False or len(s) == 1:
		print('NO')
	elif index == 0:
		print('YES', s[0])
	elif index > 0:
		print('YES', s[:index])
	else:
		print('NO')


import sys
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	n = len(s)
	ans = -1
	for i in range(1, n, 1):
		a = int(s[:i])
		ans = a
		a += 1
		ok = 1
		cur = 0
		for j in range(i, n, 1):
			if cur == 0 and s[j] == '0':
				ok = 0
				break
			cur = cur * 10 + int(s[j])
			if cur > a:
				ok = 0
				break
			elif cur == a:
				a += 1
				cur = 0
		if cur != 0:
			ok = 0
		if ok == 0:
			ans = -1
		else:
			break
	if ans == -1:
		print('NO')
	else:
		print('YES', ans)


n = int(input())
for i in range(n):
	s = input()
	fl = 0
	for i in range(len(s) - 1):
		h = s[0:i + 1]
		n = int(h)
		s1 = s
		d = n
		while len(s1) != 0:
			if s1.find(str(d)) != -1:
				index = s1.find(str(d))
				s1 = s1[0:index] + s1[index + len(str(d)):]
				d += 1
			else:
				break
		if len(s1) == 0:
			print('YES', n)
			fl = 1
			break
	if fl == 0:
		print('NO')


q = int(input())
for i in range(0, q):
	s = input()
	n = len(s)
	yes = 0
	if s[0] == '0' or n == 1:
		print('NO')
	else:
		for j in range(1, n // 2 + 1):
			pre = s[0:j]
			pos = 1
			nex = str(int(pre) + 1)
			j2 = j
			while True:
				if len(nex) > n - j2 or nex[0] == '0':
					pos = 0
					break
				if s[j2:j2 + len(nex)] == nex:
					if j2 + len(nex) == n:
						break
					j2 += len(nex)
					nex = str(int(nex) + 1)
				else:
					pos = 0
					break
			if pos == 1:
				print('YES ' + pre)
				yes = 1
				break
		if yes == 0:
			print('NO')


import sys
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	done = False
	for startSize in range(1, len(s) // 2 + 1):
		ptr = 0
		num = int(s[ptr:ptr + startSize])
		beginNum = num
		ptr += startSize
		while ptr < len(s):
			num += 1
			newSize = len(str(num))
			newNum = int(s[ptr:ptr + newSize])
			if newNum != num:
				break
			ptr += newSize
		if ptr == len(s):
			print('YES', beginNum)
			done = True
			break
	if not done:
		print('NO')


import sys
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	found = False
	for firstLength in range(1, len(s)):
		firstNumber = int(s[0:firstLength])
		beautiful = str(firstNumber)
		currentNumber = firstNumber
		while len(beautiful) < len(s) and beautiful == s[0:len(beautiful)]:
			currentNumber += 1
			beautiful = beautiful + str(currentNumber)
		if beautiful == s:
			print('YES', firstNumber)
			found = True
			break
	if not found:
		print('NO')


def check_string(s, l):
	x_str = s[0:l]
	x_num = int(x_str)
	if len(str(x_num)) != len(x_str):
		return (False, 0)
	s = s[l:]
	cur_num = x_num
	while True:
		next_num = cur_num + 1
		next_str = s[0:len(str(next_num))]
		if len(str(next_num)) == len(next_str) and int(next_str) == next_num:
			cur_num = next_num
			s = s[len(str(next_num)):]
			if s == '':
				return (True, x_num)
		else:
			return (False, 0)
q = int(input())
for i in range(q):
	s = input()
	ans_found = False
	x = 0
	for l in range(1, len(s)):
		res = check_string(s, l)
		if res[0] == True:
			ans_found = True
			x = res[1]
			break
	if ans_found:
		print('YES ' + str(x))
	else:
		print('NO')


import sys
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	if len(s) < 2:
		print('NO')
		continue
	success = False
	success_len = 0
	for try_len in range(1, len(s)):
		first_int = int(s[:try_len])
		build_str = str(first_int)
		while len(build_str) < len(s):
			first_int += 1
			build_str += str(first_int)
		if build_str == s:
			success = True
			success_len = try_len
			break
	if success:
		print('YES', s[:success_len])
	else:
		print('NO')


import sys

def make(k, n):
	ans = ''
	while len(ans) < n:
		ans += str(k)
		k += 1
	return ans

def get_b(s):
	for i in range(len(s) // 2):
		k = s[:i + 1]
		if s == make(int(k), len(s)):
			return k
	return -1
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	k = get_b(s)
	if k != -1:
		print('YES {}'.format(k))
	else:
		print('NO')


tc = int(input())
for _ in range(tc):
	var = input()
	n = 1
	found = False
	ans = 0
	while n < len(var):
		tvar = var[:n]
		dig = int(tvar)
		first = dig
		while 1:
			dig += 1
			tvar += str(dig)
			if len(tvar) >= len(var):
				break
		if tvar == var:
			found = True
			ans = first
		n += 1
	if found:
		print('YES', ans)
	else:
		print('NO')


import sys

def valid(start, x):
	while x != '':
		cur = str(start + 1)
		if not x.startswith(cur):
			return False
		start += 1
		x = x[len(cur):]
	return True

def main():
	q = int(input().strip())
	for a0 in range(q):
		s = input().strip()
		n = len(s)
		ans = -1
		for l in range(1, n):
			prefix = int(s[:l])
			if valid(prefix, s[l:]):
				ans = prefix
				break
		if ans == -1:
			print('NO')
		else:
			print('YES', ans)
main()


import sys
q = int(input())
best = None
for _ in range(q):
	s = input().strip()
	found = False
	for i in range(len(s) // 2):
		a = s[:i + 1]
		f = n = int(s[:i + 1])
		while len(a) < len(s):
			n += 1
			a += str(n)
		if a == s:
			found = True
			print('YES', f)
			break
	if not found:
		print('NO')


import math
import sys

def ndigit(x):
	return int(math.log10(x)) + 1 if x > 0 else 1

def query(s):
	for i in range(1, int(len(s) / 2) + 1):
		if s[0] == '0':
			continue
		n = int(s[:i])
		pos = i
		ok = True
		while pos < len(s) and ok:
			if s[pos] == '0':
				ok = False
			l = ndigit(n)
			nn = int(s[pos:pos + l])
			if n + 1 != nn:
				l += 1
				nn = int(s[pos:pos + l])
				if n + 1 != nn:
					ok = False
			pos += l
			n += 1
		if ok:
			print('YES {0}'.format(s[:i]))
			return
	print('NO')
q = int(input())
for _ in range(q):
	s = input()
	query(s)


import sys

def is_b(s, l=1):
	ln = []
	e = 0
	while e < len(s):
		ln.append(s[e:e + l])
		e += l
		if all([x == '9' for x in ln[-1]]):
			l += 1
	if len(ln) < 2:
		return -1
	if any([x[0] == '0' for x in ln]):
		return -1
	li = list(map(int, ln))
	if all([li[i] == li[i + 1] - 1 for i in range(len(li) - 1)]):
		return li[0]
	return -1
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	res = 0
	for l in range(1, int(len(s) / 2) + 2):
		if is_b(s, l) > 0:
			res = is_b(s, l)
			break
		else:
			pass
	if res > 0:
		print('YES', res)
	else:
		print('NO')


import sys

def isgood(s, prev):
	if len(s) == 0:
		return (True, 0)
	if s[0] == '0':
		return (False, 0)
	if prev == -1:
		for i in range(1, len(s)):
			x = int(s[0:i])
			if isgood(s[i:], x)[0]:
				return (True, x)
	else:
		for i in range(1, len(s) + 1):
			x = int(s[0:i])
			if prev + 1 != x:
				continue
			if isgood(s[i:], x)[0]:
				return (True, 0)
	return (False, 0)
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	x = isgood(s, -1)
	if x[0]:
		print('YES ' + str(x[1]))
	else:
		print('NO')


q = int(input())
for i in range(q):
	rs = input()
	pos = 0
	if rs[0] != '0':
		for p in range(1, len(rs) - 1):
			s = rs[:]
			if not s:
				break
			t = p
			e = int(s[0:t])
			erg = e
			s = s[t:]
			while len(s):
				ne = str(e + 1)
				if s.find(ne) != 0:
					break
				else:
					s = s[len(ne):]
					e += 1
			else:
				pos = erg
				break
	if pos:
		print('YES {}'.format(pos))
	else:
		print('NO')


import sys

def proceed(s, idx1, n):
	n2 = n + 1
	s2 = str(n2)
	len2 = len(s2)
	if idx1 + len2 <= len(s):
		if s2 == s[idx1:idx1 + len2]:
			return (idx1, len2, n2)
	return (idx1, 0, n2)
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	if len(s) < 2:
		print('NO')
		continue
	test = False
	for i in range(1, int(len(s) / 2) + 1):
		s1 = s[0:i]
		n1 = int(s1)
		(idx1, len2, n2) = proceed(s, i, n1)
		while len2 > 0 and idx1 + len2 < len(s):
			(idx1, len2, n2) = proceed(s, idx1 + len2, n2)
		if len2 > 0:
			print('YES', n1)
			test = True
			break
	if not test:
		print('NO')


import sys
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	size = 1
	check = True
	if len(s) == 1:
		check = False
	while size < len(s) // 2 + 1:
		tsize = size
		check = True
		q = 0
		(r, s1, s2) = (s[:tsize], s[:tsize], '')
		if s1 == '0':
			check = False
			break
		if len(str(int(s1) + 1)) == len(s1) + 1:
			tsize += 1
		for i in range(size, len(s)):
			s2 += s[i]
			q += 1
			if q == tsize:
				if int(s1) == int(s2) - 1:
					s1 = s2
					s2 = ''
					q = 0
					if len(str(int(s1) + 1)) == len(s1) + 1:
						tsize += 1
				else:
					check = False
					break
			elif q < tsize and i == len(s) - 1:
				check = False
				break
		size += 1
		if check == True:
			print('YES', r)
			break
	if check == False:
		print('NO')


import sys

def test(s, n):
	a = int(s[:n])
	i = n
	while i < len(s):
		b = str(a + 1)
		if not s[i:].startswith(b):
			return False
		i += len(b)
		a += 1
	return True

def solve(s):
	for c in range(1, len(s) // 2 + 1):
		if test(s, c):
			print('YES', int(s[:c]))
			return
	print('NO')
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	solve(s)


import sys
from math import log10
q = int(input().strip())
for a0 in range(q):
	flag = 0
	s = input().strip()
	if s[0] == '0':
		print('NO')
		continue
	for i in range(1, len(s)):
		flag = 1
		nums = [int(s[:i])]
		digit_length = j = i
		while j < len(s):
			if log10(nums[-1] + 1) % 1 == 0:
				digit_length += 1
			x = int(s[j:j + digit_length])
			if s[j] == '0' or x - nums[-1] != 1:
				flag = 0
				break
			nums.append(x)
			j += digit_length
		if flag == 1:
			print('YES', nums[0])
			break
	if flag == 0:
		print('NO')


import sys
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	printed = False
	for firstSplit in range(1, len(s)):
		valid = True
		start = int(s[:firstSplit])
		if start > 0:
			newS = s[firstSplit:]
			currVal = start + 1
			while valid and len(newS) > 0:
				nextSplit = str(currVal)
				if len(newS) >= len(nextSplit) and newS[:len(nextSplit)] == nextSplit:
					newS = newS[len(nextSplit):]
					currVal += 1
				else:
					valid = False
			if valid:
				printed = True
				print('YES', start)
				break
	if not printed:
		print('NO')


import sys
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	printed = False
	for i in range(1, len(s) // 2 + 1):
		counter = int(s[:i]) + 1
		sub = s[:i]
		while len(sub) < len(s):
			sub += str(counter)
			counter += 1
		if s == sub:
			print('YES ' + s[:i])
			printed = True
			break
	if not printed:
		print('NO')


import sys
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	if s[0] == '0':
		print('NO')
	else:
		beautiful = False
		for firstlength in range(1, len(s)):
			ts = s
			thisbeautiful = True
			length = firstlength
			while len(ts) != 0:
				if length > len(ts):
					thisbeautiful = False
					break
				num = int(ts[0:length])
				ts = ts[length:]
				if len(ts) == 0:
					break
				if ts[0] == '0':
					thisbeautiful = False
					break
				nextnum = str(num + 1)
				length = len(nextnum)
				if length > len(ts):
					thisbeautiful = False
					break
				if nextnum != ts[0:length]:
					thisbeautiful = False
					break
			if thisbeautiful:
				beautiful = True
				print('YES ' + s[0:firstlength])
				break
		if not beautiful:
			print('NO')


import sys

def check_beauty(s, first):
	prev = str(first)
	i = len(first)
	while i != len(s):
		next_num = str(int(prev) + 1)
		j = i + len(next_num)
		if s[i:j] != next_num:
			return False
		i = j
		prev = next_num
	return True

def check_all(s):
	for i in range(1, len(s)):
		first = s[:i]
		if check_beauty(s, first):
			return 'YES ' + first
	return 'NO'
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	print(check_all(s))


import sys

def SplitStr(s, Arr=[]):
	if len(Arr) > 1 and Arr[-1] - Arr[-2] != 1:
		return (False, None)
	if s == '':
		if len(Arr) < 2:
			return (False, None)
		else:
			return (True, Arr[0])
	elif s[0] == '0':
		return (False, None)
	n = len(s)
	for i1 in range(1, n + 1):
		(Valid, First) = SplitStr(s[i1:], Arr + [int(s[:i1])])
		if Valid:
			return (True, First)
	return (False, None)
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	(Valid, First) = SplitStr(s)
	if Valid:
		print('YES %i' % First)
	else:
		print('NO')


import sys

def try_split_with_k(k, s):
	if k > len(s) or int(s[0]) == 0:
		return -1
	a = int(s[:k])
	s = s[k:]
	prev_num = a
	while len(s) > 0:
		if k > len(s) or int(s[0]) == 0:
			return -1
		next_num = int(s[:k])
		if next_num != prev_num + 1:
			next_num = int(s[:k + 1])
			if next_num != prev_num + 1:
				a = -1
				break
			else:
				s = s[k + 1:]
				k += 1
				prev_num = next_num
		else:
			s = s[k:]
			prev_num = next_num
	return a
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	a = -1
	for k in range(1, len(s) // 2 + 1):
		a = try_split_with_k(k, s)
		if a > 0:
			print('YES', a)
			break
	if a == -1:
		print('NO')


import sys

def numLen(s):
	if s[0] == '0':
		return -1
	else:
		num = int(s)
		nextLen = len(str(num + 1))
		num += 1
	return (num, nextLen)
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	strlen = len(s)
	if s[0] == '0':
		print('NO')
	elif strlen == 1:
		print('NO')
	else:
		flag = 0
		for i in range(int(strlen / 2)):
			start = 0
			digit = i + 1
			stop = start + digit
			flag = 0
			firstVal = s[start:stop]
			while stop < len(s):
				snum = str(s[start:stop])
				(nextNum, nextLen) = numLen(snum)
				start = stop
				stop = start + nextLen
				snextNum = s[start:stop]
				if nextNum != int(snextNum):
					flag = 1
					break
			if flag == 0:
				print('YES', firstVal)
				break
		if flag:
			print('NO')


import sys

def main():
	q = int(input())
	for iii in range(0, q):
		s = str(input())
		ok = True
		for i in range(1, len(s)):
			r = int(s[:i])
			t = r + 1
			x = str(r)
			while len(x) < len(s):
				x += str(t)
				t += 1
			if x == s:
				print('YES ' + str(r))
				ok = False
				break
		if ok:
			print('NO')
main()


import sys

def isbeaut(s1, s2):
	if s1[0] == '0' or s2[0] == '0':
		return False
	return int(s2) == int(s1) + 1

def beaut(s):
	l0 = 0
	while l0 < len(s) // 2 + 1:
		cur = 0
		l0 += 1
		l1 = l0
		while True:
			s1 = s[cur:cur + l1]
			l2 = len(str(int(s1) + 1))
			end = cur + l1 + l2
			if end > len(s):
				break
			s2 = s[cur + l1:end]
			if isbeaut(s1, s2):
				if end == len(s):
					return s[:l0]
				cur += l1
				l1 = l2
			else:
				break
	return False
q = int(input().strip())
for a0 in range(q):
	sin = input().strip()
	r = beaut(sin)
	if r is False:
		print('NO')
	else:
		print('YES', r)


def solution(s):
	for l in range(1, len(s) // 2 + 1):
		no = False
		if int(s[0]) == 0:
			continue
		start = l
		size = l
		n = int(s[:l])
		while start < len(s):
			if int(s[start]) == 0:
				no = True
				break
			if n % pow(10, len(str(n))) == pow(10, len(str(n))) - 1:
				if int(s[start:start + size + 1]) - n == 1:
					n = int(s[start:start + size + 1])
					start = start + size + 1
					size += 1
				else:
					no = True
					break
			elif int(s[start:start + size]) - n == 1:
				n = int(s[start:start + size])
				start = start + size
			else:
				no = True
				break
		if not no:
			return 'YES ' + s[:l]
	return 'NO'
q = int(input())
for i in range(q):
	s = input().strip()
	ans = solution(s)
	print(ans)


import sys

def header(t, q):
	if q == '':
		return True
	t += 1
	h = str(t)
	if len(h) > len(q):
		return False
	if h != q[:len(h)]:
		return False
	return header(t, q[len(h):])

def test(s):
	if s[0] == '0':
		print('NO')
		return
	for first in range(1, len(s) - 1):
		if header(int(s[:first]), s[first:]):
			print('YES', s[:first])
			return
	print('NO')
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	test(s)


import sys
q = int(input().strip())
for a0 in range(q):
	s = [int(x) for x in input().strip()]
	if s[0] == 0:
		print('NO')
		continue
	num = s[0]
	genislik = 1
	l = []
	found = False
	while genislik < len(s) // 2 + 1:
		l = []
		q = 0
		for i in range(genislik):
			l.append(s[i])
		num = int(''.join(map(str, l)))
		q += len(l)
		not_found = False
		while q < len(s):
			qy = 0
			num += 1
			nm_arr = [int(x) for x in str(num)]
			if s[q] == 0:
				not_found = True
				break
			for z in range(q, q + len(nm_arr)):
				if z == len(s):
					not_found = True
					break
				if nm_arr[qy] != s[z]:
					not_found = True
					break
				qy += 1
			if not_found is True:
				break
			else:
				q += len(nm_arr)
		genislik += 1
		if q == len(s):
			print('YES {}'.format(int(''.join(map(str, l)))))
			found = True
			break
	if found is False:
		print('NO')


import sys
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	temp = list(s)
	var = True
	count = 0
	num = None
	var = True
	notfound = False
	set1 = [9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999, 9999999999, 99999999999, 999999999999, 9999999999999, 99999999999999, 999999999999999, 9999999999999999]
	while var:
		intemp = []
		strtemp = []
		i = 0
		extra = 0
		while i < len(temp):
			k = 1
			str1 = temp[i]
			if str1 != '0':
				while k <= count + extra:
					if i + k < len(temp):
						str1 += temp[i + k]
					k += 1
			strtemp.append(str1)
			intemp.append(int(str1))
			i += count + 1 + extra
			if int(str1) in set1:
				extra += 1
		if len(intemp) == 1:
			print('NO')
			break
		for i in range(len(intemp) - 1):
			if intemp[i + 1] - intemp[i] != 1:
				notfound = True
				break
		if notfound == False:
			print('YES', intemp[0])
			var = False
		count += 1
		notfound = False


import sys

def get(s):
	if s[0] == '0':
		return None
	for i in range(1, len(s) - 1):
		test = int(s[:i])
		cur = test
		tmp = s[:i]
		while len(tmp) < len(s):
			cur += 1
			tmp += str(cur)
		if tmp == s:
			return test
	return None
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	ans = get(s)
	if ans:
		print('YES', ans)
	else:
		print('NO')


import sys
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	flag = False
	for i in range(1, int(len(s) / 2) + 1):
		x = y = int(s[:i])
		j = i
		while j < len(s):
			if s[j] == 0:
				flag = False
				break
			y += 1
			if s[j:].startswith(str(y)):
				j += len(str(y))
				flag = True
			else:
				flag = False
				break
		if flag == True:
			print('YES ' + str(x))
			break
	if flag == False:
		print('NO')


import sys

def is_beautiful(s):
	for digits in range(1, len(s) // 2 + 1):
		start = s[:digits]
		if start[0] == '0':
			break
		candidate = start
		start = int(start)
		for i in range(1, len(s) // digits + 1):
			expected = str(start + i)
			candidate += expected
			if not s.startswith(candidate):
				break
			if len(candidate) >= len(s):
				break
		if candidate == s:
			return 'YES {}'.format(start)
	return 'NO'
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	print(is_beautiful(s))


import sys
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	l = len(s)
	if l == 1:
		print('NO')
		continue
	if s[0] == '0':
		print('NO')
		continue
	B = True
	for x in range(1, l):
		B = True
		a = int(s[0:x])
		ss = s[x:]
		while ss != '':
			b = str(a + 1)
			ll = len(b)
			if ss[0:ll] == b:
				ss = ss[ll:]
				a += 1
			else:
				B = False
				break
		if B:
			print('YES', s[0:x])
			break
	if B == False:
		print('NO')


import sys
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	flag = 0
	for i in range(1, int(len(s) / 2) + 1):
		root = int(s[0:i])
		len_string = 0
		final = ''
		while len_string < len(s):
			final = final + str(root)
			len_string = len_string + len(str(root))
			root += 1
		if len_string == len(s) and final == s:
			print('YES', s[0:i])
			flag = 1
			break
	if flag == 0:
		print('NO')


q = int(input())
for qwert in range(q):
	s = input().strip()
	faulty = True
	first = ''
	for i in range(1, int(len(s) / 2) + 1):
		num = int(s[:i])
		if str(num) != s[:i]:
			pass
		else:
			faulty = False
			first = str(num)
			while i < len(s):
				new = num + 1
				if s[i:i + len(str(new))] != str(new):
					faulty = True
				num = new
				i = i + len(str(new))
			if not faulty:
				break
			else:
				first = ''
	if faulty:
		print('NO')
	else:
		print('YES', first, sep=' ')


import sys
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	l = len(s)
	d = 2
	res = 0
	if l >= d:
		while res == 0 and d <= l:
			width = l // d
			r = l % d
			i = 0
			prev = int(s[i * width:(i + 1) * width])
			i += 1
			found = True
			start = 0
			end = width
			while i < d:
				if i >= d - r:
					width = l // d + 1
				start = end
				end = start + width
				num = int(s[start:end])
				if s[start] == '0' or num - prev != 1:
					found = False
					break
				i += 1
				prev = num
			if found:
				res = l // d
			d += 1
	if res > 0:
		print('%s %s' % ('YES', s[:res]))
	else:
		print('NO')


import sys

def is_beautiful(s, num):
	if len(s) == 0:
		return True
	next_num = 0
	if s[0] == 0:
		return False
	for i in range(0, len(s)):
		d = s[i]
		next_num *= 10
		next_num += d
		if next_num > num + 1:
			return False
		elif next_num == num + 1:
			return is_beautiful(s[i + 1:], next_num)
	return False
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	s = [int(x) for x in s]
	num = 0
	ans = -1
	for i in range(0, len(s) - 1):
		if s[0] == 0:
			break
		num *= 10
		num += s[i]
		if is_beautiful(s[i + 1:], num):
			ans = num
			break
	if ans == -1:
		print('NO')
	else:
		print('YES ' + str(ans))


(t, f) = ('YES', 'NO')

def check(s, n):
	if len(s) == 0:
		return True
	sn = str(n)
	ln = len(sn)
	if s[:ln] != sn:
		return False
	else:
		return check(s[ln:], n + 1)
q = int(input().strip())
for a0 in range(q):
	trigger = 0
	s = input().strip()
	for i in range(1, len(s)):
		n = int(s[:i])
		if check(s, n):
			print(t, n)
			trigger = 1
			break
	if not trigger:
		print(f)


import sys

def is_am(s, k):
	length = k
	cur = s[:k]
	if cur[0] == '0':
		return False
	while length <= len(s):
		curInt = int(cur)
		cur = str(curInt + 1)
		if cur[0] == '0':
			return False
		if length + len(cur) > len(s):
			return False
		if s[length:length + len(cur)] != cur:
			return False
		length += len(cur)
		if length == len(s):
			return True
	return False
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	gener = (k for k in range(1, 1 + len(s) // 2) if is_am(s, k))
	gener2 = (k for k in range(1, 1 + len(s) // 2) if is_am(s, k))
	print('YES ' + s[:next(gener2)] if any((True for x in gener)) else 'NO')


import sys

def solve(s, h):
	if s[0] == '0':
		return False
	l = len(h)
	ls = len(s)
	if ls == l:
		if int(s) == int(h) + 1:
			return True
	if int(s[0:l]) == int(h) + 1:
		return solve(s[l:], s[0:l])
	if int(s[0:l + 1]) == int(h) + 1:
		if ls == l + 1:
			return True
		else:
			return solve(s[l + 1:], s[0:l + 1])
	return False

def f(s):
	ls = len(s)
	for i in range(1, ls):
		if solve(s[i:], s[0:i]):
			return (True, s[0:i])
	return (False, -1)
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	(Bool, val) = f(s)
	if Bool:
		print('YES', val)
	else:
		print('NO')


import sys
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	numdigit = 1
	while len(s) // numdigit >= 2:
		num = s[0:numdigit]
		num1 = int(num)
		while len(num) < len(s):
			num1 += 1
			num += str(num1)
		if num == s:
			print('YES', s[0:numdigit])
			break
		numdigit += 1
	if len(s) // numdigit < 2:
		print('NO')


import sys
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	n = len(s)
	is_beaut = False
	for i in range(1, n // 2 + 1):
		count = int(s[:i])
		s_test = []
		while len(s_test) < n:
			s_test += str(count)
			count += 1
		if s == ''.join(s_test):
			print('YES {}'.format(s[:i]))
			is_beaut = True
			break
	if not is_beaut:
		print('NO')


def split(n, start):
	while n:
		s = str(start)
		if n.startswith(s):
			n = n[len(s):]
			start += 1
		else:
			return False
	return True
t = int(input())
for i in range(t):
	n = input().strip()
	for take in range(1, len(n) - 1):
		if split(n, int(n[:take])):
			print('YES {}'.format(n[:take]))
			break
	else:
		print('NO')


import sys

def nextNum(s):
	return str(int(s) + 1)

def startsWithHelper(s, start):
	if s == start:
		return True
	elif s.startswith(start):
		nextStart = nextNum(start)
		skip = len(start)
		return startsWithHelper(s[skip:], nextStart)
	return False
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	for i in range(1, len(s) // 2 + 1):
		start = s[:i]
		if start == '0':
			print('NO')
			break
		if startsWithHelper(s[i:], nextNum(start)):
			print('YES', start)
			break
	else:
		print('NO')


import sys
answer = []
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	n = len(s)
	flag = False
	for i in range(1, n // 2 + 1):
		start = s[:i]
		s_val = int(start)
		nex = s_val + 1
		sub = str(s_val) + str(nex)
		while s.startswith(sub) and len(sub) <= len(s):
			if len(sub) == len(s):
				flag = True
				answer.append('YES {}'.format(start))
			nex = nex + 1
			sub = sub + str(nex)
	if not flag:
		answer.append('NO')
for ans in answer:
	print(ans)


import sys
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	flag = 0
	rem = ''
	for c in range(int(len(s) / 2)):
		first = str(s)[:c + 1]
		if int(first) + 1 == int(str(s)[c + 1:c + c + 2]):
			flag = 1
			rem = first
			continue
		if len(s) > c + 1 + c + 1:
			if int(first) + 1 == int(str(s)[c + 1:c + c + 3]):
				rem = first
				flag = 1
				continue
	if flag == 1:
		first = int(rem)
		word = ''
		flag2 = 0
		for i in range(int(len(s) / len(rem))):
			word += str(first + i)
			if word == s:
				flag2 = 1
		if flag2 == 1:
			print('YES' + ' ' + rem)
		else:
			print('NO')
	else:
		print('NO')


def check(elm, S):
	if str(elm)[0] == '0':
		return False
	_len = len(str(elm))
	return elm + 1 == int(S[:_len]) or elm + 1 == int(S[:_len + 1])
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	elm = int(s[0])
	i = 1
	ans = []
	w_len = 0
	found = False
	if s[0] != '0':
		while i < len(s) and (not found):
			if check(elm, s[i:]):
				ans.append(str(elm))
				elm += 1
				i += len(str(elm))
			else:
				i += 1
				elm = int(s[:i])
			if i >= len(s):
				ans.append(str(elm))
				found = ''.join(ans) == s
				if not found and len(ans):
					i = len(ans[0]) + 1
					elm = int(s[:i])
					ans = []
	if found and len(ans) > 1:
		print('YES ' + ans[0])
	else:
		print('NO')


import sys

def is_followed_numbers(numbers):
	ok = True
	cpt_numbers = 1
	if len(numbers) == 1:
		return False
	while ok and cpt_numbers < len(numbers):
		if int(numbers[cpt_numbers]) - int(numbers[cpt_numbers - 1]) != 1:
			ok = False
		if ok and (str(int(numbers[cpt_numbers])) != numbers[cpt_numbers] or str(int(numbers[cpt_numbers - 1])) != numbers[cpt_numbers - 1]):
			ok = False
		cpt_numbers += 1
	return ok

def generate_numbers(number, end_base):
	numbers = []
	begin = 0
	end = end_base
	numbers.append(number[begin:end])
	while end < len(number):
		begin = end
		end += 1
		while end < len(number) and int(number[begin:end]) < int(numbers[len(numbers) - 1]):
			end += 1
		numbers.append(number[begin:end])
	return numbers
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	ok = False
	cpt_range = 1
	numbers = None
	while cpt_range < len(s) and (not ok):
		numbers = generate_numbers(s, cpt_range)
		ok = is_followed_numbers(numbers)
		cpt_range += 1
	if ok:
		print('YES', numbers[0])
	else:
		print('NO')


import sys

def check(i, s):
	while len(s) > 0:
		cur = str(i)
		if not s.startswith(cur) or s[0] == '0':
			return False
		s = s[len(cur):]
		i += 1
	return True
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	f = False
	for i in range(len(s) - 1):
		start = int(s[0:i + 1])
		if check(start, s):
			print('YES', start)
			f = True
			break
	if not f:
		print('NO')


def getBeautifulNumber(s):
	for i in range(1, len(s) // 2 + 1):
		prefix = int(s[:i])
		if isBeautifulNumber(prefix, s[i:]):
			return prefix

def isBeautifulNumber(prevNum, rest):
	if len(rest) == 0:
		return True
	if len(rest) >= 1 and rest[0] == '0':
		return False
	num = -1
	index = -1
	numberFound = False
	for i in range(1, len(rest) + 1):
		num = int(rest[:i])
		if num == prevNum + 1:
			numberFound = True
			index = i
			break
	if numberFound:
		return isBeautifulNumber(num, rest[index:])
	else:
		return False
q = int(input())
for i in range(q):
	num = input()
	result = getBeautifulNumber(num)
	if result:
		print('YES ' + str(result))
	else:
		print('NO')


import sys
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	found = False
	fh = None
	sn = len(s)
	for si in range(1, sn - 1):
		head = s[:si]
		v = int(head)
		tpl = 0
		test_piece = []
		while tpl < sn:
			tp = str(v)
			tpl += len(tp)
			test_piece.append(tp)
			v += 1
		if ''.join(test_piece) == s:
			found = True
			fh = head
			break
	if found:
		print('YES', fh)
	else:
		print('NO')


import sys

def is_nice(s, init_index):
	current = int(s[:init_index])
	remaining = s[init_index:]
	while remaining:
		current = current + 1
		to_be_stripped = str(current)
		if remaining.startswith(to_be_stripped):
			remaining = remaining[len(to_be_stripped):]
			if len(remaining) == 0:
				return True
		else:
			return False
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	if len(s) < 2:
		print('NO')
	else:
		partition = 1
		nice = False
		while partition < int(len(s) / 2) + 1:
			if is_nice(s, partition):
				print('YES', s[:partition])
				nice = True
				break
			else:
				partition = partition + 1
		if not nice:
			print('NO')


import sys

def checker(stringing, i):
	v = stringing[0:i]
	new_v = str(int(v) + 1)
	new_string = stringing[i:]
	if new_string == new_v:
		return True
	elif new_string[:len(new_v)] == new_v:
		return checker(new_string, len(new_v))
	else:
		return False
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	length = len(s) // 2
	truth = False
	lens = 0
	for i in range(1, length + 1):
		v = checker(s, i)
		if v == True:
			truth = True
			lens = s[0:i]
	if truth == True:
		print('YES', lens)
	else:
		print('NO')


import sys
from functools import reduce

def check(s):
	for i in range(1, int(len(s) / 2) + 1):
		test = ''
		num = int(s[0:i])
		while len(test) < len(s):
			test += str(num)
			num += 1
		if test == s:
			print('YES ' + s[0:i])
			return
	print('NO')
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	check(s)


import sys
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	l = len(s)
	if l == 1 or s[0] == '0':
		print('NO')
		continue
	j = 1
	f = 0
	inc = 0
	while j < l / 2 + 1:
		i = 0
		while (int(s[i + j:i + j + j]) - int(s[i:i + j]) == 1 or int(s[i + j:i + j + j + 1]) - int(s[i:i + j]) == 1) and s[i + j] != '0':
			if int(s[i + j:i + j + j]) - int(s[i:i + j]) == 1 and s[i + j] != '0':
				if i + j + j == l:
					print('YES', int(s[0:j - inc]))
					f = 1
					break
				i += j
				if i + j > l:
					break
			else:
				if i + j + j + 1 == l:
					print('YES', int(s[0:j - inc]))
					f = 1
					break
				i += j
				j += 1
				inc += 1
		if f == 1:
			break
		j += 1
	if f == 0:
		print('NO')


import sys

def numDigits(n):
	if n == 0:
		return 0
	else:
		return 1 + numDigits(n // 10)

def nextNum(s, i, num):
	size = numDigits(num)
	if num == 10 ** numDigits(num) - 1:
		size += 1
	return s[i:i + size]
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	beautiful = False
	size = 1
	while not beautiful and size < len(s):
		firstNum = int(s[0:0 + size])
		currentNum = firstNum
		i = numDigits(currentNum)
		while i < len(s) and currentNum + 1 == int(nextNum(s, i, currentNum)) and (nextNum(s, i, currentNum)[0] != '0'):
			currentNum = int(nextNum(s, i, currentNum))
			i += numDigits(currentNum)
		if i == len(s):
			beautiful = True
		else:
			size += 1
	if beautiful:
		print('YES ' + str(firstNum))
	else:
		print('NO')


def valid(s):
	n = len(s)
	if n <= 1:
		return 'NO'
	for i in range(1, n):
		a = int(s[:i])
		t = str(a)
		if t != s[:i]:
			return 'NO'
		j = 1
		while len(t) < n:
			t = t + str(a + j)
			if t == s:
				return 'YES ' + str(a)
			j += 1
	return 'NO'
for _ in range(int(input())):
	print(valid(input()))


def tryIt(s, startWidth):
	width = startWidth
	cur = -1
	pos = 0
	while pos + width < len(s):
		cur = int(s[pos:pos + width])
		pos += width
		if [c == '9' for c in str(cur)].count(True) == len(str(cur)):
			width += 1
		if int(s[pos:pos + width]) != cur + 1:
			return False
	return True
for _ in range(int(input())):
	s = input()
	if s[0] == '0' or len(s) == 1:
		print('NO')
		continue
	width = 1
	while not tryIt(s, width) and width < len(s):
		width += 1
	if width >= len(s) - 1:
		print('NO')
		continue
	else:
		print('YES {}'.format(s[:width]))


import sys
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	if len(s) < 2:
		print('NO')
		continue
	sinir = len(s)
	depo = s
	count = 1
	BigCount = 1
	GuzelList = [s[:count]]
	s = s[count:]
	Output = 'NO'
	while BigCount <= sinir:
		if s == '':
			if len(GuzelList) > 1:
				Output = 'YES'
				break
			BigCount += 1
			count = BigCount
			s = depo
			GuzelList = [s[:count]]
			s = s[count:]
			continue
		if GuzelList[-1] == '9' * len(GuzelList[-1]):
			count += 1
		GuzelList.append(s[:count])
		s = s[count:]
		if GuzelList[-1][0] == '0':
			BigCount += 1
			count = BigCount
			s = depo
			GuzelList = [s[:count]]
			s = s[count:]
			continue
		elif int(GuzelList[-2]) + 1 != int(GuzelList[-1]):
			BigCount += 1
			count = BigCount
			s = depo
			GuzelList = [s[:count]]
			s = s[count:]
			continue
	if Output == 'YES':
		print(Output, GuzelList[0])
	else:
		print(Output)


import sys, math

def debug(*args):
	x = 0

def beautifulFirstNumber(s):
	for i in range(1, math.floor(len(s) / 2) + 1):
		compare = int(s[0:i])
		debug('start at', str(compare))
		debug('remaining part is', s[i:])
		j = i
		ncompare = compare
		failed = False
		while j < len(s):
			wantedNextNum = ncompare + 1
			c = len(str(wantedNextNum))
			debug('next has to be', str(wantedNextNum))
			actualNextNum = s[j:j + c]
			debug('it is', actualNextNum)
			actualNextNum = int(actualNextNum)
			if actualNextNum != wantedNextNum:
				debug('stop: actualNextNum differs')
				failed = True
				break
			ncompare = actualNextNum
			j += c
		if failed is False:
			return compare
	return None
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	debug('handle ', s)
	if len(s) <= 1:
		print('NO')
		continue
	if s[0] == '0':
		print('NO')
		continue
	firstNumber = beautifulFirstNumber(s)
	print('NO' if firstNumber is None else 'YES %d' % firstNumber)


import sys
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	isBtf = False
	nb = ''
	for i in range(1, len(s)):
		init = int(s[:i])
		sub = init
		j = i
		isCorrect = True
		while j < len(s):
			next = sub + 1
			if s[j:j + len(str(next))] != str(next):
				isCorrect = False
				break
			sub = next
			j = j + len(str(next))
		if isCorrect:
			isBtf = True
			nb = init
			break
	if isBtf:
		print('YES ' + str(nb))
	else:
		print('NO')


def isBeautiful(sk):
	for i in range(1, len(sk)):
		res = checkNext(sk[:i], sk[i:])
		if res is not None and res > 0:
			print('YES', sk[:res])
			return
	print('NO')

def checkNext(curr, sk):
	nextC = str(int(curr) + 1)
	try:
		if sk.index(nextC) == 0:
			if sk[len(nextC):] == '':
				return len(curr)
			elif checkNext(nextC, sk[len(nextC):]) is not None:
				return len(curr)
			else:
				return None
		else:
			return None
	except ValueError:
		return None

def main():
	q = int(input())
	for i in range(q):
		temp = input()
		isBeautiful(temp)
main()


import sys

def split(s, cnt):
	return (s[:cnt], s[cnt:])

def solve(s):
	if len(s) == 1:
		return ('NO', '')
	for i in range(1, len(s)):
		spl = split(s, i)
		x = int(spl[0])
		y = x
		ss = spl[1]
		if len(ss) == 0:
			break
		ok = True
		while len(ss) > 0:
			x = x + 1
			xs = str(x)
			if len(xs) > len(ss):
				ok = False
				break
			spl = split(ss, len(xs))
			if xs != spl[0]:
				ok = False
				break
			ss = spl[1]
		if ok:
			return ('YES', str(y))
	return ('NO', '')
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	ans = solve(s)
	print(ans[0] + ' ' + ans[1])


import sys
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	beautiful = False
	for i in range(len(s) // 2):
		first = int(s[:i + 1])
		next = first + 1
		j = i + 1
		while j < len(s):
			second = int(s[j:j + len(str(next))])
			if second == next and len(str(next)) == len(s[j:j + len(str(next))]):
				j = j + len(str(next))
				next = second + 1
				beautiful = True
			else:
				beautiful = False
				break
		if beautiful:
			print('YES', first)
			break
	if not beautiful:
		print('NO')


import sys
q = int(input().strip())
for _ in range(q):
	s = input().strip()
	l = len(s)
	flag = 0
	for i in range(l // 2):
		numc = int(s[:i + 1])
		lc = len(s[:i + 1])
		j = i + 1
		flag = 1
		while j < l:
			if j + lc <= l and int(s[j:j + lc]) - 1 == numc and (not (j + lc + 1 <= l and s[j + lc] == '0')):
				j += lc
				numc += 1
			elif j + lc + 1 <= l and int(s[j:j + lc + 1]) - 1 == numc and (not (j + lc + 2 <= l and s[j + lc + 1] == '0')):
				lc += 1
				j += lc
				numc += 1
			else:
				flag = 0
				break
		if flag == 1:
			print('YES', s[:i + 1])
			break
	if flag == 0:
		print('NO')


import sys
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	if s.startswith('0'):
		print('NO')
		continue
	ans = None
	starting = ''
	for ch in s:
		starting += ch
		if starting == s:
			break
		i = int(starting)
		tmp = starting
		while len(tmp) < len(s):
			i = i + 1
			tmp += str(i)
		if tmp == s:
			ans = starting
			break
	if ans:
		print('YES ' + ans)
	else:
		print('NO')


import sys

def beautNum(s, increment):
	firstNum = None
	notIncremented = True
	i1 = 0
	i2 = increment
	while i2 < len(s):
		currNum = int(s[i1:i2])
		nextNum = int(s[i2:i2 + increment])
		if currNum == nextNum - 1:
			if firstNum is None:
				firstNum = currNum
			i1 = i2
			i2 += increment
		elif notIncremented:
			increment += 1
			nextNum = int(s[i2:i2 + increment])
			if currNum == nextNum - 1:
				if firstNum is None:
					firstNum = currNum
				i1 = i2
				i2 += increment
			notIncremented = False
		else:
			return 'NO'
	return firstNum

def determineBeauty(s):
	if s[0] == '0':
		return 'NO'
	increment = 1
	while increment < len(s) / 2 + 1:
		result = beautNum(s, increment)
		if result == 'NO':
			increment += 1
		else:
			return 'YES ' + str(result)
	return 'NO'
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	if len(s) == 1:
		print('NO')
	elif len(s) == 2:
		if int(s[0]) == int(s[1]) - 1:
			print('YES ' + s[0])
		else:
			print('NO')
	else:
		result = determineBeauty(s)
		print(result)


import sys

def is_beautiful(s, prefix):
	cur = prefix
	rest = s[len(prefix):]
	if s == prefix or prefix.startswith('0'):
		return False
	while len(rest) > 0:
		nextCur = str(int(cur) + 1)
		if rest.startswith(nextCur):
			rest = rest[len(nextCur):]
			cur = nextCur
		else:
			return False
	return True
q = int(input().strip())
for _ in range(q):
	s = input().strip()
	beautiful = False
	if len(s) <= 1:
		print('NO')
		continue
	for i in range(1, len(s) + 1):
		prefix = s[:i]
		if is_beautiful(s, prefix):
			beautiful = True
			break
	if beautiful:
		print('YES ' + prefix)
	else:
		print('NO')


import sys

def first(s):
	if s[0] == '0':
		return (second(s[1:], 0), 0)
	for i in range(1, len(s)):
		result = second(s[i:], int(s[:i]))
		if result:
			return (True, int(s[:i]))
	return (False, None)

def second(s, n):
	if len(s) == 0:
		return True
	li = str(n + 1)
	if s.startswith(li):
		return second(s[len(li):], n + 1)
	else:
		return False
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	(r, v) = first(s)
	if r:
		print('YES', v)
	else:
		print('NO')


import sys
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	temp = len(s)
	m = 0
	for i in range(1, len(s) // 2 + 1):
		x = s[:i]
		a = s[i:]
		y = str(int(x) + 1)
		while len(a) > 0:
			if len(a) >= len(y) and y == a[:len(y)]:
				a = a[len(y):]
				y = str(int(y) + 1)
			else:
				break
		if len(a) == 0:
			m += 1
			print('YES', x)
			break
	if m == 0:
		print('NO')


import sys
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	if len(s) == 1 or s[0] == '0':
		print('NO')
	else:
		kan = []
		for i in range(len(s) // 2):
			kan.append(s[0:i + 1])
		for z in kan:
			k = len(z)
			f = True
			if int(s[k:2 * k]) - int(z) == 1:
				f = True
				v = 0
				g = 1
				for j in range(k, len(s) - k + 1, k):
					if int(s[j:j + k]) - int(s[j - k:j]) == 1:
						f = True
					elif int(s[j:j + k + 1]) - int(s[j - k:j]) == 1 and s[j] != '0':
						f = True
						if j + k + 1 < len(s):
							v = j + k
						break
					else:
						f = False
						break
				if v:
					for j in range(v + 1, len(s) - k, k + 1):
						g = 2
						if int(s[j:j + k + 1]) - int(s[j - k - 1:j]) != 1:
							f = False
							break
			elif 2 * k < len(s) and int(s[k:2 * k] + s[2 * k]) - int(z) == 1:
				g = 2
				for j in range(2 * k + 1, len(s) - k, k + 1):
					if int(s[j:j + k + 1]) - int(s[j - k - 1:j]) != 1:
						f = False
						break
			else:
				f = False
			if f:
				if q > 8:
					if g == 1:
						if int(s[len(s) - k:len(s)]) - int(s[len(s) - 2 * k:len(s) - k]) == 1:
							print('YES', z)
							break
					elif g == 2:
						if len(s) - 2 * k - 2 >= 0 and int(s[len(s) - k - 1:len(s)]) - int(s[len(s) - 2 * k - 2:len(s) - k - 1]) == 1:
							print('YES', z)
							break
						elif int(s[len(s) - k - 1:len(s)]) - int(s[len(s) - 2 * k - 1:len(s) - k - 1]) == 1:
							print('YES', z)
							break
				else:
					print('YES', z)
					break
			f = False
		if not f:
			print('NO')


import sys
import math
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	l_max = len(s)
	l = 1
	flag = 0
	while l < l_max:
		if l > 1 and int(s[0] == 0):
			break
		start = int(s[0:l])
		count = 1
		prev = start
		temp = 0
		i = l
		while i < l_max:
			temp = 10 * temp + int(s[i])
			if temp == 0:
				start = -1
				break
			if temp - prev == 1:
				count += 1
				prev = temp
				temp = 0
			elif temp - prev > 1:
				start = -1
				break
			i += 1
		if start >= 0 and temp == 0 and (i == l_max):
			print('YES', start)
			flag = 1
			break
		l += 1
	if flag == 0:
		print('NO')


import sys

def all_nines(s):
	for char in s:
		if int(char) != 9:
			return False
	return True
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	worked = False
	for n in range(1, len(s)):
		pos = 0
		extra = 0
		last_char = s[pos:pos + n]
		if all_nines(last_char):
			extra += 1
		pos += n
		while len(s) >= pos + n + extra:
			char = s[pos:pos + n + extra]
			if int(last_char) + 1 == int(char):
				if int(char[0]) == 0:
					break
				pos += n + extra
				last_char = char
				if all_nines(char):
					extra += 1
			else:
				break
		if pos == len(s):
			print('YES', s[0:n])
			worked = True
	if not worked:
		print('NO')


for _ in range(int(input())):
	s = input()
	fl = False
	res = 0
	if s[0] == '0':
		print('NO')
		continue
	for i in range(1, len(s) // 2 + 1):
		num = int(s[:i])
		if num == 0:
			continue
		pos = i
		while True:
			if pos + len(str(num + 1)) <= len(s) and str(num + 1) == s[pos:pos + len(str(num + 1))] and (s[pos] != '0'):
				pos += len(str(num + 1))
				if pos == len(s):
					fl = True
					break
				num += 1
			else:
				break
		if fl:
			res = int(s[:i])
			break
	if fl:
		print('YES', res)
	else:
		print('NO')


import sys, copy

def parse(sm, last, item, trace):
	if len(item) > 0:
		for i in range(1, len(item) + 1):
			if int(item[0:i]) - last == 1:
				_trace = copy.copy(trace)
				_last = int(item[0:i])
				_sm = sm + _last
				_item = item[i:len(temp)]
				_trace.append(str(_last))
				return parse(_sm, _last, _item, _trace)
			else:
				pass
	else:
		return int(trace[0])
q = int(input().strip())
for a0 in range(q):
	item = input().strip()
	res = []
	for i in range(1, len(item)):
		temp = copy.copy(item)
		trace = []
		last = int(item[0:i])
		trace.append(str(last))
		sm = last
		temp = temp[i:len(temp)]
		tempres = parse(last, sm, temp, trace)
		if tempres != None:
			res.append(tempres)
	if len(res) == 1:
		print('YES', res[0])
	else:
		print('NO')


import sys

def get_next(s, curr):
	nr = 0
	pz = 0
	if s[0] == '0':
		return (-1, 0)
	for ch in s:
		nr = nr * 10 + int(ch)
		pz += 1
		if nr > curr:
			return (nr, pz)
	return None

def solve(s, l):
	numbers = []
	currNumber = int(''.join(s[0:l]))
	index = l
	ok = True
	while index < len(s):
		nr = get_next(s[index:], currNumber)
		if nr == None:
			ok = False
			break
		if nr[0] - 1 == currNumber:
			numbers.append(currNumber)
			currNumber = nr[0]
			index += nr[1]
		else:
			currNumber = currNumber * 10 + int(s[index])
			index += 1
			if index == len(s):
				ok = False
	if len(numbers) == 0:
		ok = False
	if ok:
		print('YES', numbers[0])
		return 19
	else:
		return -1
q = int(input().strip())
for a0 in range(q):
	s = list(input().strip())
	if len(s) < 2 or s[0] == '0':
		print('NO')
	else:
		ok = True
		for l in range(1, len(s) // 2 + 1):
			if solve(s[:], l) == 19:
				ok = False
				break
		if ok:
			print('NO')


import sys

def get_curr(s, start, stop):
	curr_n = int(s[start:stop])
	curr_dig = len(str(curr_n))
	return (curr_n, curr_dig)

def get_next(s, start, curr_dig, pros_dig):
	act_n = int(s[start + curr_dig:start + curr_dig + pros_dig])
	act_dig = len(str(act_n))
	return (act_n, act_dig)
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	is_beut = 'NO'
	start = 0
	init_dig = 1
	stop = start + init_dig
	nums = 0
	while is_beut == 'NO' and init_dig <= len(s) // 2:
		com_arr = []
		while stop <= len(s) + 1:
			(curr_n, curr_dig) = get_curr(s, start, stop)
			pros_n = curr_n + 1
			pros_dig = len(str(pros_n))
			try:
				(act_n, act_dig) = get_next(s, start, curr_dig, pros_dig)
			except ValueError:
				break
			if act_n == pros_n:
				com_arr.append(curr_n)
				nums += 1
			else:
				break
			start += curr_dig
			stop = start + act_dig
			if stop == len(s):
				com_arr.append(act_n)
				nums += 1
			dig = act_dig
			compare = ''.join(list(map(str, com_arr)))
		if len(com_arr) > 1 and com_arr == list(range(com_arr[0], com_arr[0] + nums)) and (compare == s):
			is_beut = 'YES ' + str(com_arr[0])
		start = 0
		init_dig += 1
		stop = start + init_dig
		nums = 0
	print(is_beut)


def Beautiful(string):
	init_fixed = 1
	Beautiful = False
	while init_fixed < len(string):
		init = init_fixed
		i = 1
		firstnum = int(string[:init])
		firstnum_length = len(str(firstnum))
		while init < len(string):
			length = str(int(i + firstnum))
			curr_length = len(length)
			curr_num = int(string[init:init + curr_length])
			init = init + curr_length
			if curr_num == firstnum + i:
				i += 1
			else:
				break
			if init == len(string):
				Beautiful = True
				break
		init_fixed += 1
		if Beautiful == True:
			print('YES', firstnum)
			break
	if Beautiful == False:
		print('NO')
array = []
q = int(input())
for i in range(0, q):
	x = input()
	array.append(x)
	hello = Beautiful(array[i])


import sys

def isBeautiful(string, size=1, isFlexible=True):
	if len(string) == 1 and isFlexible:
		return (False, '')
	first = int(string[:size])
	second = str(first + 1)
	nextNumIndex = size + len(second)
	if second == string[size:nextNumIndex]:
		if nextNumIndex < len(string):
			(a, b) = (isBeautiful(string[size:], len(second), False)[0], first)
			if a:
				return (a, b)
		else:
			return (True, first)
	if isFlexible and size < len(string):
		return isBeautiful(string, size + 1, True)
	return (False, first)
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	(isB, start) = isBeautiful(s)
	if isB:
		print('YES', start)
	else:
		print('NO')


import sys
q = int(input().strip())
for i in range(q):
	s = input().strip()
	beautiful = False
	start = ''
	for l in range(1, 1 + len(s) // 2):
		beautiful = True
		start = s[0:l]
		if start != str(int(start)):
			beautiful = False
			continue
		offset = l
		n = start
		while offset < len(s):
			n = str(int(n) + 1)
			if n != s[offset:offset + len(n)]:
				beautiful = False
				break
			offset = offset + len(n)
		if beautiful:
			break
	print('YES ' + str(start) if beautiful else 'NO')


import sys

def check_seq(string, expecting):
	if string.startswith(expecting):
		new_string = string[len(expecting):]
		if new_string == '':
			return True
		else:
			new_expecting = str(int(expecting) + 1)
			return check_seq(new_string, new_expecting)
	else:
		return False
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	for i in range(1, len(s)):
		number = int(s[0:i])
		expecting = str(number + 1)
		if check_seq(s[i:], expecting) == True:
			print('YES {}'.format(number))
			break
		else:
			continue
	else:
		print('NO')


import sys

def ver(i, s, l):
	c = int(s[:i])
	j = i
	k = 1
	while j < l:
		if j + k > l:
			break
		d = s[j:j + k]
		if d[0] == '0':
			break
		d = int(d)
		t = d - c
		if t > 1:
			break
		if t == 1:
			c = d
			j = j + k
			k = 1
			continue
		k += 1
	else:
		return True
	return False
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	if s[0] == '0':
		print('NO')
		continue
	i = 1
	l = len(s)
	while i < l:
		q = int(s[0:i])
		if ver(i, s, l):
			print('YES', q)
			break
		i += 1
	else:
		print('NO')


import sys
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	if len(s) == 1 or s[0] == '0':
		print('NO')
	else:
		i = 0
		limit = len(s) // 2
		base = startBase = 1
		got = int(s[i:i + base])
		while i + base < len(s):
			i += base
			want = got + 1
			base = len(str(want))
			got = int(s[i:i + base])
			if got != want:
				startBase += 1
				if startBase > limit:
					break
				i = 0
				base = startBase
				got = int(s[i:i + base])
		print('YES ' + s[:startBase] if startBase <= limit else 'NO')


import sys
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	found = False
	for x in range(len(s) - 1):
		num = int(s[0:x + 1])
		start = num
		pos = 0
		while True:
			s2 = str(num)
			for y in s2:
				if pos >= len(s):
					break
				if s[pos] != y:
					break
				pos += 1
			else:
				if pos == len(s):
					found = True
					print('YES', start)
					break
				num += 1
				continue
			break
		if found:
			break
	if not found:
		print('NO')


import sys
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	if s[0] == '0':
		print('NO')
		continue
	res = False
	for l in range(1, len(s) - 1):
		prefix = s[:l]
		(rest, cnt) = ('', int(prefix))
		while len(rest) < len(s[l:]):
			rest += str(cnt + 1)
			cnt += 1
		if rest == s[l:]:
			res = prefix
	print('YES ' + res if res else 'NO')


import sys
q = int(input().strip())
for a0 in range(q):
	data = [int(c) for c in input().strip()]
	failed = {}

	def tryNext(s, num):
		if (s, num) not in failed:
			nextnum = 0
			ind = s
			while ind < len(data) and nextnum < num + 1:
				nextnum *= 10
				nextnum += data[ind]
				ind += 1
			if ind == len(data) and nextnum == num + 1:
				return True
			elif ind == len(data) or nextnum > num + 1 or data[ind] == 0:
				failed[s, num] = True
			elif tryNext(ind, nextnum):
				return True
			else:
				failed[s, num] = True
		return not failed[s, num]
	index = 0
	tal = 0
	while index < len(data):
		tal *= 10
		tal += data[index]
		index += 1
		if index != len(data) and data[index] != 0 and tryNext(index, tal):
			print('YES', tal)
			break
	if index == len(data):
		print('NO')


import sys
import math

def generator(first, length):
	length = int(length)
	first = int(first)
	temp = first + 1
	s = str(first)
	s += str(temp)
	for i in range(length):
		if len(s) == int(length):
			return s
		temp += 1
		s += str(temp)
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	for i in range(1, round(len(s) / 2) + 2):
		t = generator(s[:i], len(s))
		if t == s:
			print('YES' + ' ' + str(s[:i]))
			break
		elif i >= round(len(s) / 2):
			print('NO')
			break


import sys

def beautiful(s):
	n = len(s)
	if n < 2:
		return 0
	if s[0] == '0':
		return 0
	for i in range(1, n):
		prefix = int(s[:i])
		if beautiful_next(s[i:], prefix):
			return i
	return 0

def beautiful_next(s, k):
	if s == '':
		return True
	if s[0] == '0':
		return False
	next_num = str(k + 1)
	m = len(next_num)
	if s[:m] == next_num:
		if beautiful_next(s[m:], k + 1):
			return True
	return False
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	result = beautiful(s)
	if result:
		print('YES %s' % s[:result])
	else:
		print('NO')


q = int(input())
for _ in range(q):
	answer = 2 ** 200
	s = input()
	for i in range(len(s) - 1):
		num = s[i + 1:]
		a = s[:i + 1]
		a_next = str(int(a) + 1)
		start = int(a)
		while len(num) != 0:
			if num[0] == '0':
				break
			if not num.startswith(a_next):
				break
			num = num[len(a_next):]
			a = a_next
			a_next = str(int(a) + 1)
		if len(num) == 0:
			answer = min(answer, start)
			break
	if answer == 2 ** 200:
		print('NO')
	else:
		print('YES {}'.format(answer))


import sys

def check(x):
	for i in range(0, len(x)):
		if x[i] != '9':
			return
	return 1
q = int(input().strip())
for a0 in range(q):
	s = input().strip()
	if len(s) == 1 or s[0] == '0':
		print('NO')
	else:
		for k in range(0, len(s)):
			j = k + 1
			i = 0
			val = s[0:j]
			inVal = val
			flagL = 0
			flag = 0
			while i < len(s):
				if check(s[i:i + j]) == 1:
					j += 1
					flag = 1
				if i + j + k + 1 > len(s):
					flagL = 0
					break
				if int(s[i + k + 1:i + j + k + 1]) - int(val) == 1:
					val = s[i + k + 1:i + j + k + 1]
					flagL = 1
					if i + j + k + 1 == len(s):
						break
				else:
					flagL = 0
					break
				i = i + len(val)
			if flagL == 1:
				print('YES ' + inVal)
				break
		if flagL == 0:
			print('NO')