You are given a string $s$, consisting only of characters '0' or '1'. Let $|s|$ be the length of $s$.

You are asked to choose some integer $k$ ($k > 0$) and find a sequence $a$ of length $k$ such that:

$1 \le a_1 < a_2 < \dots < a_k \le |s|$;

$a_{i-1} + 1 < a_i$ for all $i$ from $2$ to $k$.

The characters at positions $a_1, a_2, \dots, a_k$ are removed, the remaining characters are concatenated without changing the order. So, in other words, the positions in the sequence $a$ should not be adjacent.

Let the resulting string be $s'$. $s'$ is called sorted if for all $i$ from $2$ to $|s'|$ $s'_{i-1} \le s'_i$.

Does there exist such a sequence $a$ that the resulting string $s'$ is sorted?


-----Input-----

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

Then the descriptions of $t$ testcases follow.

The only line of each testcase contains a string $s$ ($2 \le |s| \le 100$). Each character is either '0' or '1'.


-----Output-----

For each testcase print "YES" if there exists a sequence $a$ such that removing the characters at positions $a_1, a_2, \dots, a_k$ and concatenating the parts without changing the order produces a sorted string.

Otherwise, print "NO".

You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).


-----Examples-----

Input
5
10101011011
0000
11111
110
1100
Output
YES
YES
YES
YES
NO


-----Note-----

In the first testcase you can choose a sequence $a=[1,3,6,9]$. Removing the underlined letters from "10101011011" will produce a string "0011111", which is sorted.

In the second and the third testcases the sequences are already sorted.

In the fourth testcase you can choose a sequence $a=[3]$. $s'=$ "11", which is sorted.

In the fifth testcase there is no way to choose a sequence $a$ such that $s'$ is sorted.

Difficulty: EASY

Solutions:
from sys import stdin, stdout
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import *
from random import *
input = stdin.readline
prin = stdout.write
from random import sample
from collections import Counter, deque
from fractions import *
from math import sqrt, ceil, log2, gcd
mod = 10 ** 9 + 7

def f(arr, i, j, d, dist):
	if i == j:
		return
	nn = max(arr[i:j])
	for tl in range(i, j):
		if arr[tl] == nn:
			dist[tl] = d
			f(arr, i, tl, d + 1, dist)
			f(arr, tl + 1, j, d + 1, dist)

def ps(n):
	cp = 0
	lk = 0
	arr = {}
	while n % 2 == 0:
		n = n // 2
		lk += 1
	for ps in range(3, ceil(sqrt(n)) + 1, 2):
		lk = 0
		cc = 0
		while n % ps == 0:
			n = n // ps
			lk += 1
	if n != 1:
		lk += 1
		return False
	return True

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def factorials(n, r):
	slr = n
	dpr = r
	qlr = 1
	qs = 1
	mod = 10 ** 9 + 7
	for ip in range(n - r + 1, n + 1):
		qlr = qlr * ip % mod
	for ij in range(1, r + 1):
		qs = qs * ij % mod
	ans = qlr * modInverse(qs) % mod
	return ans

def modInverse(b):
	qr = 10 ** 9 + 7
	return pow(b, qr - 2, qr)
from types import GeneratorType

def iterative(f, stack=[]):

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

def power(arr):
	listrep = arr
	subsets = []
	for i in range(2 ** len(listrep)):
		subset = []
		for k in range(len(listrep)):
			if i & 1 << k:
				subset.append(listrep[k])
		subsets.append(subset)
	return subsets

def pda(n):
	list = []
	for i in range(1, int(sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				list.append(i)
			else:
				list.append(n // i)
				list.append(i)
	return list

def dis(xa, ya, xb, yb):
	return sqrt((xa - xb) ** 2 + (ya - yb) ** 2)

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

def ilist():
	return [int(x) for x in input().strip().split()]

def islist():
	return list(map(str, input().split().rstrip()))

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

def google(test, ans):
	return 'Case #' + str(test) + ': ' + str(ans)

def overlap(x1, y1, x2, y2):
	if x2 > y1:
		return y1 - x2
	if y1 > y2:
		return y2 - x2
	return y1 - x2
t = int(input())
for p in range(t):
	s = input()
	n = len(s)
	one = 0
	zero = 0
	cc = 1
	for i in range(1, n):
		if s[i] == s[i - 1]:
			if s[i] == '1':
				one = 1
			elif one == 1:
				cc = 0
				break
			else:
				zero = 1
	if cc:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	(ok, ones) = (True, False)
	for i in range(1, len(s)):
		if not ones and s[i - 1] == s[i] and (s[i] == '1'):
			ones = True
		elif ones and s[i - 1] == s[i] and (s[i] == '0'):
			ok = False
			break
	print('YES' if ok else 'NO')


for _ in range(int(input())):
	case = input()
	i = case.find('11')
	j = case.rfind('00')
	if i < j and i != -1 and (j != -1):
		print('NO')
	else:
		print('YES')


t = int(input())
for p in range(t):
	n = input()
	if n.find('11') == -1 or n.find('00') == -1:
		print('YES')
	elif n.find('00', n.find('11') + 1) == -1:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	(l, r) = (s.rfind('00'), s.find('11'))
	if l != -1 and r != -1:
		if l < r:
			print('YES')
		else:
			print('NO')
	else:
		print('YES')


t = int(input())
while t:
	a = input()
	one = a.find('11')
	zero = a.rfind('00')
	if one != -1 and zero != -1 and (one < zero):
		print('NO')
	else:
		print('YES')
	t -= 1


from collections import deque, defaultdict
from math import sqrt, ceil, factorial, floor, inf, log2, sqrt
import bisect
import copy
from itertools import combinations
import sys

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

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

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	s = input()
	flag = 0
	for i in range(len(s)):
		ind = i
		(c, d) = ([], [])
		for j in range(ind):
			if s[j] == '1':
				c.append(j)
		for j in range(ind + 1, len(s)):
			if s[j] == '0':
				d.append(j)
		m = 0
		for i in range(1, len(c)):
			if c[i] - c[i - 1] < 2:
				m = 1
				break
		for i in range(1, len(d)):
			if d[i] - d[i - 1] < 2:
				m = 1
				break
		if m == 0:
			flag = 1
			break
	if flag == 0:
		print('NO')
	else:
		print('YES')


def fun(c):
	if c == '0':
		for i in range(n - 1, 0, -1):
			if c == s[i] and s[i] == s[i - 1]:
				return i
		return -1
	else:
		for i in range(1, n):
			if c == s[i] and s[i] == s[i - 1]:
				return i
		return n
t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	if fun('0') < fun('1'):
		print('YES')
	else:
		print('NO')


tc = int(input())
for t in range(tc):
	seq = input()
	rmost00 = seq.rfind('00')
	lmost11 = seq.find('11')
	if rmost00 >= 0 and lmost11 >= 0 and (rmost00 > lmost11):
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	s = input()
	if '11' in s and '00' in s and (s.index('11') < s.rfind('00')):
		print('NO')
	else:
		print('YES')


import math
import sys
t = int(input())
for gp in range(t):
	s = input()
	index1 = s.find('11')
	index2 = s.rfind('00')
	if index1 != -1 and index2 != -1 and (index1 < index2):
		print('NO')
	else:
		print('YES')


t = int(input())
for _ in range(t):
	s = input()
	if '11' in s:
		i = s.index('11')
		a = s[i:]
		if '00' in a:
			print('NO')
		else:
			print('YES')
	else:
		print('YES')


for _ in range(int(input())):
	s = input()
	print('YES' if s.find('00', max(s.find('11'), 0)) == -1 or s.find('11') == -1 else 'NO')


for _ in range(int(input())):
	a = input()
	(one, zero, n, b) = (0, 0, len(a), 0)
	for i in range(0, n - 1):
		if a[i] == '1':
			if a[i + 1] == '1':
				one = 1
				b = i
				break
	for j in range(b, n - 1):
		if a[j] == '0':
			if a[j + 1] == '0':
				zero = 1
				break
	if one == 1 and zero == 1:
		print('NO')
	else:
		print('YES')


t = int(input())
for _ in range(t):
	s = input()
	ss = s.replace('10', '')
	print('YES' if ss == ''.join(sorted(ss)) else 'NO')


for _ in range(int(input())):
	string = input()
	oneIdx = None
	try:
		oneIdx = string.index('11')
	except Exception:
		pass
	zeroIdx = None
	try:
		zeroIdx = len(string) - 1 - string[::-1].index('00')
	except Exception:
		pass
	if oneIdx == None or zeroIdx == None:
		print('YES')
	elif oneIdx > zeroIdx:
		print('YES')
	else:
		print('NO')


trials = int(input())
for trial in range(trials):
	n = input()
	if '11' in n:
		x = n.index('11')
		if '00' in n[x:]:
			print('NO')
			n = 0
	if n != 0:
		print('YES')


import sys
from collections import deque
import math
input_ = lambda : sys.stdin.readline().strip('\r\n')
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab, bc, cd: ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x: print(x)
prinT = lambda x: print(x)
f = lambda : sys.stdout.flush()
for _ in range(ii()):
	a = list(ip())
	fl = 0
	b = 0
	l = len(a)
	for i in range(1, l):
		if a[i] == a[i - 1] and fl == 0:
			if a[i] == '1':
				fl = 1
		elif a[i] == a[i - 1] and fl == 1 and (a[i] == '0'):
			b = 1
			break
	if b:
		print('NO')
	else:
		print('YES')


from __future__ import division, print_function
import os
import sys
sys.setrecursionlimit(1000000)
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math
import sys
import bisect
from collections import defaultdict
for t in range(int(input())):
	s = input()
	flag = True
	idx = -1
	idx0 = -1
	for i in range(len(s) - 1):
		if s[i] == '1' and s[i + 1] == '1' and flag:
			idx = i
			flag = False
		if s[i] == '0' and s[i + 1] == '0':
			idx0 = i
	if idx == -1 or idx0 == -1:
		print('YES')
		continue
	if idx < idx0:
		print('NO')
	else:
		print('YES')
main()


t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	(a, b) = (-1, -1)
	if s.count('1') == n or s.count('0') == n:
		print('YES')
	else:
		a = s.find('11')
		b = s.rfind('00')
		if a == -1 or b == -1:
			print('YES')
		elif a < b:
			print('NO')
		else:
			print('YES')


def solve(s, n, can_leave, last, d):
	if n == 0:
		return True
	if (n, can_leave, last) in d:
		return d[n, can_leave, last]
	curr = int(s[n - 1])
	if curr > last and can_leave == False:
		temp = False
	elif curr > last and can_leave == True:
		temp = solve(s, n - 1, False, last, d)
	elif curr <= last and can_leave == True:
		temp = solve(s, n - 1, True, curr, d) or solve(s, n - 1, False, last, d)
	elif curr <= last and can_leave == False:
		temp = solve(s, n - 1, True, curr, d)
	d[n, can_leave, last] = temp
	return temp
for testcase in range(int(input())):
	s = input()
	p = solve(s, len(s), True, float('inf'), {})
	if p:
		print('YES')
	else:
		print('NO')


N = int(input())
for t in range(N):
	s = input()
	M = s.find('11')
	if M == -1:
		print('YES')
		continue
	if s[M:].find('00') != -1:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	s = input()
	n = len(s)
	flag = 0
	for i in range(n - 1):
		if flag == 0:
			if s[i] == '1' and s[i + 1] == '1':
				flag = 1
		elif flag == 1:
			if s[i] == '0' and s[i + 1] == '0':
				flag = 2
		else:
			break
	if flag == 2:
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	s = input()
	if '00' in s[s.find('11'):]:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	ss = input()
	flag = 0
	n = len(ss)
	for i in range(n - 1):
		if ss[i] == '1' and ss[i + 1] == '1':
			break
	for j in range(i + 1, n - 1):
		if ss[j] == '0' and ss[j + 1] == '0':
			flag = 1
			break
	if flag:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	s1 = input()
	if '11' in s1 and '00' in s1 and (s1.find('11') < s1.rfind('00')):
		print('NO')
	else:
		print('YES')


t = int(input())
for z in range(t):
	s = input()
	one = False
	zero = False
	for i in range(1, len(s), 1):
		if one == False and (s[i] == '1' and s[i - 1] == '1'):
			one = True
		if one == True and zero == False and (s[i] == '0' and s[i - 1] == '0'):
			zero = True
		if one and zero:
			break
	if one == True and zero == True:
		print('NO')
	else:
		print('YES')


T = int(input())
while T:
	T -= 1
	s = input()
	k = 0
	for i in range(1, len(s)):
		if k == 0 and s[i] == s[i - 1] == '1':
			k += 1
		if k == 1 and s[i] == s[i - 1] == '0':
			k += 1
			break
	if k == 2:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	s = input()
	if '11' not in s or '00' not in s:
		print('YES')
		continue
	b = s.index('11')
	a = len(s) - s[::-1].index('00') - 2
	if b < a:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	s = input()
	try:
		i = s.index('11') + 2
		if '00' in s[i:]:
			print('NO')
		else:
			print('YES')
	except:
		print('YES')


for _ in range(int(input())):
	n = input()
	d = n.find('11')
	f = n.rfind('00')
	if d != -1 and f != -1 and (d < f):
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	s = input()
	if '11' not in s or '00' not in s:
		print('YES')
		continue
	if s.find('11') < s.rfind('00'):
		print('NO')
	else:
		print('YES')


import sys
lines = sys.stdin.readlines()
T = int(lines[0].strip())
for t in range(T):
	s = lines[t + 1].strip()
	L = len(s)
	satisfy = True
	pairOne = False
	ind = -1
	pairZero = False
	for i in range(1, L):
		if s[i] == '1' and s[i - 1] == '1':
			pairOne = True
			ind = i
			break
	if pairOne:
		for i in range(ind + 2, L):
			if s[i] == '0' and s[i - 1] == '0':
				pairZero = True
				break
	if pairZero:
		print('NO')
	else:
		print('YES')


import sys
import io, os
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	s = str(input().rstrip())
	n = len(s)
	X = []
	Y = []
	for (i, c) in enumerate(s):
		if c == '0':
			X.append(i)
		else:
			Y.append(i)
	if len(X) <= 1 or len(Y) <= 1:
		print('YES')
		continue
	for k in range(n):
		flag = True
		for j in range(len(X) - 1):
			if X[j] >= k and X[j] + 1 == X[j + 1]:
				flag = False
				break
		for j in range(len(Y) - 1):
			if Y[j + 1] < k and Y[j] + 1 == Y[j + 1]:
				flag = False
				break
		if flag:
			print('YES')
			break
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	c1 = s.find('11')
	c2 = s.rfind('00')
	if c1 >= 0 and c2 >= 0 and (c1 < c2):
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = input()
	a = n.rfind('00')
	b = n.find('11')
	if a < 0 or b < 0 or b > a:
		print('YES')
	else:
		print('NO')


t = int(input())

def slv(s):
	pts = s.split('11')
	for pt in pts[1:]:
		if '00' in pt:
			return False
	return True
for _ in range(t):
	s = input()
	if slv(s):
		print('YES')
	else:
		print('NO')


t = int(input())
for j in range(0, t):
	inp = input()
	m = False
	adj_z = False
	adj_o = False
	n = len(inp)
	for i in range(1, n):
		if inp[i] == inp[i - 1]:
			if adj_o == True:
				if inp[i] == '0':
					m = True
			elif inp[i] == '1':
				adj_o = True
			else:
				adj_z = True
	if m == True:
		print('NO')
	else:
		print('YES')


import sys
from math import *
from collections import defaultdict, Counter
t = int(input())
for i in range(t):
	s = input()
	no = s.count('0')
	ed = s.count('1')
	if no == len(s) or ed == len(s):
		print('YES')
		continue
	po1 = 1000000000.0
	for i in range(1, len(s)):
		if s[i] == '1' and s[i - 1] == '1':
			po1 = i
			break
	po0 = -1
	for i in range(len(s) - 1, 0, -1):
		if s[i] == '0' and s[i - 1] == '0':
			po0 = i
			break
	if po1 < po0:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	s = input()
	a = s.find('11')
	b = s.rfind('00')
	if a != -1 and b != -1 and (a < b):
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	s = input()
	i1 = s.find('11')
	i2 = s.rfind('00')
	if i1 != -1 and i2 != -1 and (i1 < i2):
		print('NO')
	else:
		print('YES')


def increasing(arr):
	for i in range(1, len(arr)):
		if arr[i] < arr[i - 1]:
			return False
	return True
t = int(input())
for i in range(t):
	s = input()
	index1 = s.find('11')
	index0 = s.find('00', index1)
	if index1 != -1:
		if index0 > index1:
			print('NO')
		else:
			print('YES')
	else:
		print('YES')


for i in range(int(input())):
	a = input()
	x = a.find('11')
	if a[x:].find('00') != -1:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	s = input()
	n = len(s)
	f = True
	(o, z) = (s.count('1'), s.count('0'))
	if o == n or z == n:
		print('YES')
		continue
	for i in range(n - 1):
		if s[i] == '1' and s[i + 1] == '1':
			for i in range(i + 2, n - 1):
				if s[i] == '0' and s[i + 1] == '0':
					f = False
	if f:
		print('YES')
	else:
		print('NO')


for _ in ' ' * int(input()):
	s = input()
	print('YNEOS'[s.find('00', s.find('11')) != -1::2])


import bisect
for _ in range(int(input())):
	prev = -10
	a = input()
	p = True
	if '11' in a and '00' in a:
		if len(a) - 1 - a[::-1].index('00') - 1 > a.index('11'):
			p = False
	print('NO' if p == False else 'YES')


n = int(input())
for i in range(n):
	x = str(input())
	a = x.find('11')
	b = x.rfind('00')
	if a != -1 and b != -1 and (a < b):
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	s = input()
	n = len(s)
	t = s[::-1]
	idx11 = s.find('11')
	x = t.find('00')
	if x != -1:
		idx00 = n - t.find('00') - 1
	else:
		idx00 = x
	if idx00 != -1 and idx11 != -1 and (idx00 > idx11):
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	s = input()
	milgaya_one = 0
	yahase_zero_dekh = -1
	for i in range(0, len(s) - 1):
		if s[i] == s[i + 1] and s[i] == '1':
			milgaya_one = 1
			yahase_zero_dekh = i + 2
			break
	if milgaya_one == 0:
		print('YES')
		continue
	milgaya_zero = 0
	for i in range(yahase_zero_dekh, len(s) - 1):
		if s[i] == s[i + 1] and s[i] == '0':
			milgaya_zero = 1
			break
	if milgaya_zero == 1:
		print('NO')
	else:
		print('YES')


from collections import Counter
for _ in range(int(input())):
	s = input()
	n = len(s)
	last0 = -1
	last1 = -1
	f = 0
	f2 = 0
	for i in range(n):
		if s[i] == '0' and f == 0:
			last0 = i
		elif s[i] == '1' and f == 0:
			if i != n - 1 and s[i + 1] == '1':
				f = 1
				continue
			else:
				continue
		elif s[i] == '0' and f == 1:
			if i != n - 1 and s[i + 1] == '0':
				f2 = 1
				break
			else:
				continue
	if f2 == 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(0, t):
	m = input()
	x = m.find('11')
	y = m.rfind('00')
	if x == -1 or y == -1:
		ans = 'YES'
	elif x < y:
		ans = 'NO'
	else:
		ans = 'YES'
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	s = input().rstrip()
	zeros = []
	ones = []
	for i in range(len(s) - 1):
		if s[i] == s[i + 1] == '0':
			zeros.append(i)
		elif s[i] == s[i + 1] == '1':
			ones.append(i)
	if not zeros or not ones:
		print('YES')
	elif max(zeros) > min(ones):
		print('NO')
	else:
		print('YES')


t = int(input())
for _ in range(t):
	l = input()
	n = len(l)
	flag = 0
	for i in range(n - 1):
		if flag == 0 and l[i] == '1' and (l[i + 1] == '1'):
			flag = 1
		if flag == 1 and l[i] == '0' and (l[i + 1] == '0'):
			flag = 2
	if flag == 2:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	s = str(input())
	ans = 'YES'
	for i in range(len(s) - 1):
		if s[i] == '1' and s[i + 1] == '1':
			for j in range(i + 2, len(s) - 1):
				if s[j] == '0' and s[j + 1] == '0':
					ans = 'NO'
					break
		if ans == 'NO':
			break
	print(ans)


import sys

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

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

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

def SI():
	return sys.stdin.readline().strip()
t = II()
for s1 in range(t):
	s = SI()
	a = False
	b = False
	check = True
	for i in range(len(s) - 1):
		if s[i] == s[i + 1] and s[i] == '1':
			a = True
		elif s[i] == s[i + 1] and s[i] == '0':
			if a:
				check = False
				break
	if check:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	a = s.find('11')
	if '00' in s[a:]:
		print('NO')
	else:
		print('YES')


def check(s):
	n = len(s)
	i = 0
	while i < n - 1:
		if s[i] == '1' and s[i + 1] == '1':
			break
		i += 1
	while i < n - 1:
		if s[i] == '0' and s[i + 1] == '0':
			return False
		i += 1
	return True
t = int(input())
while t:
	s = input()
	if check(s):
		print('YES')
	else:
		print('NO')
	t -= 1


for _ in range(int(input())):
	s = input()
	ans = s.replace('10', '')
	print('YES' if ans == ''.join(sorted(ans)) else 'NO')


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

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 dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey, reverse=True)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def ceil(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def main():
	for _ in range(ii()):
		s = si()
		n = len(s)
		l = []
		c = 1
		for i in range(1, n):
			if s[i] == s[i - 1]:
				c += 1
			else:
				l.append([c, int(s[i - 1])])
				c = 1
		l.append([c, int(s[-1])])
		if len(l) == 1:
			print('YES')
			continue
		m = len(l)
		flag = 1
		f = 1
		for i in range(m - 1, -1, -1):
			if l[i][0] > 1:
				if l[i][1] == 1:
					if f == 0:
						flag = 0
						break
					f = 1
				else:
					f = 0
		if flag:
			print('YES')
		else:
			print('NO')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	s = input()
	idx = 0
	if not s.startswith('11'):
		idx = s.find('011')
		if idx == -1:
			print('YES')
			continue
	idx = s.find('100', idx)
	if idx == -1:
		print('YES')
		continue
	print('NO')


from sys import stdin
input = stdin.readline
from heapq import heapify, heappush, heappop, heappushpop
from collections import defaultdict as dd, deque as dq, Counter as C
from math import factorial as f, ceil, gcd, sqrt, log
from bisect import bisect_left as bl, bisect_right as br
from itertools import combinations as c, permutations as p
from math import factorial as f, ceil, gcd, sqrt, log
mp = lambda : map(int, input().split())
it = lambda : int(input())
ls = lambda : list(input().strip())
mt = lambda r: [ls() for _ in range(r)]
lcm = lambda a, b: a * b // gcd(a, b)

def fibo_n(n):
	return ((1 + sqrt(5)) / 2) ** n / sqrt(5)
mod = 1000000007

def out(a, test, answer):
	if answer != 'IMPOSSIBLE':
		print('Case #{}: '.format(test + 1), end=' ')
		for el in range(1, a + 1):
			print(v[el], end=' ')
		print()
	else:
		print('Case #{}: {}'.format(test + 1, answer))

def LCS(a, b):
	n = len(a)
	m = len(b)
	t = [[0 for i in range(m + 1)] for j in range(n + 1)]
	mx = 0
	for fst in range(1, n + 1):
		for scd in range(1, m + 1):
			if a[fst - 1] == b[scd - 1]:
				t[fst][scd] = 1 + t[fst - 1][scd - 1]
			mx = max(mx, t[fst][scd])
	return n + m - 2 * mx
for _ in range(it()):
	a = input().strip()
	one = None
	zero = None
	for j in range(1, len(a)):
		if one == None and a[j] + a[j - 1] == '11':
			one = j
		if a[j] + a[j - 1] == '00':
			zero = j
	if one == None or zero == None:
		print('YES')
	elif one < zero:
		print('NO')
	else:
		print('YES')


list1 = []
for i in range(int(input())):
	s = input()
	if '00' in s and '11' not in s or ('11' in s and '00' not in s) or s.find('11') > s.rfind('00') or ('00' not in s and '11' not in s):
		list1.append('YES')
	else:
		list1.append('NO')
print(*list1, sep='\n')


from queue import Queue
from itertools import accumulate
from io import BytesIO, IOBase
from itertools import combinations
import threading
from collections import deque
from functools import reduce, cmp_to_key
import sys
from math import sqrt
import heapq
import random
import math
from collections import defaultdict
from collections import Counter
import io
import os
import bisect
from fractions import Fraction

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

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

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

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

def swap(arr, a, b):
	(arr[a], arr[b]) = (arr[b], arr[a])
t = 1
t = iinput()
for _ in range(t):
	s = input()
	min1 = float('inf')
	max0 = -float('inf')
	for i in range(len(s) - 1):
		val = s[i] + s[i + 1]
		if val == '11':
			min1 = min(min1, i)
		if val == '00':
			max0 = max(max0, i)
	if min1 < max0:
		print('NO')
	else:
		print('YES')


for s in [*open(0)][1:]:
	print('YNEOS'['00' in s[s.find('11'):]::2])


for _ in range(int(input())):
	s = input()
	z = -2
	a = True
	for (i, el) in enumerate(s):
		if not a:
			break
		if el == '1':
			if z + 1 == i:
				if s[z:].count('00') == 0:
					a = True
				else:
					a = False
			else:
				z = i
	if a:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	k = s.find('11')
	if k != -1 and '00' in s[k:]:
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(0, t):
	s = input()
	lst = list(s)
	n = 0
	c = False
	for j in range(0, len(lst) - 1):
		if lst[j] == '1' and lst[j + 1] == '1':
			n = j + 1
			c = True
			break
	if c:
		answer = True
		for k in range(n, len(lst) - 1):
			if lst[k] == '0' and lst[k + 1] == '0':
				print('NO')
				answer = False
				break
			else:
				answer = True
		if answer:
			print('YES')
	else:
		print('YES')


t = int(input())
while t:
	f = 0
	t = t - 1
	l = input()
	if '11' in l:
		s = l.index('11')
		if '00' in l[s + 1:]:
			print('NO')
			f = 1
			continue
	if f == 0:
		print('YES')


for i in range(int(input())):
	s = input()
	x = s.find('11')
	y = s.rfind('00')
	if x != -1 and x < y and (x != -1):
		print('NO')
	else:
		print('YES')


def solve(s):
	i = s.find('11')
	j = s.rfind('00')
	if i != -1 and j != -1 and (i < j):
		return 'NO'
	else:
		return 'YES'

def main():
	t = int(input())
	for i in range(t):
		print(solve(input()))
main()


for _ in range(int(input())):
	a = input()
	try:
		z = a.index('11')
	except:
		z = len(a)
	try:
		t = len(a) - a[::-1].index('00')
	except:
		t = 0
	if z < t:
		print('NO')
	else:
		print('YES')


def solve_problem(string):
	start = string.find('11')
	if start < 0:
		print('YES')
		return
	previousZero = False
	for i in range(start + 2, len(string)):
		if string[i] == '0':
			if previousZero:
				print('NO')
				return
			else:
				previousZero = True
		else:
			previousZero = False
	print('YES')

def solve():
	t = int(input())
	for i in range(0, t):
		string = input().strip()
		solve_problem(string)
solve()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	s = input().strip()
	if s.find('11') < s.rfind('00') and s.find('11') != -1 and (s.rfind('00') != -1):
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	s = list(input())
	ssort = sorted(s)
	if s == ssort:
		ans = 'YES'
	elif len(s) <= 3:
		ans = 'YES'
	else:
		remove1 = True
		ans = 'YES'
		for i in range(len(s) - 1):
			if remove1:
				if s[i] == '1' and s[i + 1] == '1':
					remove1 = False
			elif s[i] == '0' and s[i + 1] == '0':
				ans = 'NO'
				break
	print(ans)


import sys
input = sys.stdin.readline

def print(x, end='\n'):
	sys.stdout.write(str(x) + end)
for i in range(int(input())):
	s = input()
	n = s.find('11')
	m = s.rfind('00')
	if n < m and n != -1 and (m != -1):
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	s = input().strip()
	one = s.find('11')
	l = s[one:].find('00')
	print('YES' if l < 0 else 'NO')


for st in range(int(input())):
	now = input()
	f = now.find('11')
	if f == -1:
		print('YES')
		continue
	ind = -1
	for i in range(len(now), -1, -1):
		if now[i:i + 2] == '00':
			ind = i
			break
	if ind > f:
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	s = input()
	k0 = s.rfind('00')
	k1 = s.find('11')
	f = False
	if k1 == -1 or k0 == -1 or k0 < k1:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	c = 0
	if len(s) <= 3:
		print('YES')
		c = 3
		s = ''
	s += '44'
	for i in range(len(s) - 2):
		if c == 1:
			break
		if s[i:i + 2] == '11':
			for j in range(i, len(s)):
				if s[j:j + 2] == '00':
					print('NO')
					c = 1
					break
	if c == 0:
		print('YES')


for _ in range(int(input())):
	s = input()
	f = -1
	g = -1
	for i in range(1, len(s)):
		if s[i] == '1' and s[i - 1] == s[i]:
			if f > -1:
				continue
			f = i - 1
		elif s[i] == '0' and s[i - 1] == s[i]:
			g = i - 1
	if g > f and f != -1 and (g != -1):
		print('NO')
	else:
		print('YES')


t = int(input())
ans = []
for _ in range(t):
	s = input()
	a = s.find('00')
	b = s.find('11')
	if a == -1 or b == -1:
		ans.append('YES')
		continue
	if s.find('00', b) == -1:
		ans.append('YES')
		continue
	ans.append('NO')
for i in ans:
	print(i)


for t in range(int(input())):
	s = input()
	if '11' in s and '00' in s and (s.find('11') < s.rfind('00')):
		print('NO')
	else:
		print('YES')


def main(s):
	for i in range(1, len(s)):
		if s[i - 1] == s[i] == '1':
			break
	else:
		print('YES')
		return
	for j in range(i + 2, len(s)):
		if s[j - 1] == s[j] == '0':
			print('NO')
			return
	print('YES')
nn = int(input())
for _ in range(nn):
	main(input())


for q in range(int(input())):
	n = input()
	s = 0
	s1 = 0
	p = 0
	l = len(n)
	for i in range(l - 1, 0, -1):
		if n[i] == '0' and n[i - 1] == '0':
			s = 1
			p = i - 1
			break
	for i in range(p, 0, -1):
		if n[i] == '1' and n[i - 1] == '1':
			s1 = 1
			break
	if s1 == 1:
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	a = input()
	b = a.find('11') + 1
	c = a.rfind('00') + 1
	if b and c and (b < c):
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	s = input()
	a = len(s)
	b = s.find('11')
	d = s.rfind('00')
	print('NO' if b != -1 and d != -1 and (b < d) else 'YES')


t = int(input())
for _ in range(t):
	s = input().strip()
	dp = [0, 0]
	for c in s:
		if c == '0':
			dp = [2 * min(dp), dp[0]]
		elif c == '1':
			dp = [2 if min(dp) >= 2 else 1, dp[0]]
	if min(dp) < 2:
		print('YES')
	else:
		print('NO')


from sys import stdin, gettrace
if gettrace():

	def inputi():
		return input()
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def solve():
	ss = input()
	sp = ss.find('11')
	if sp == -1:
		print('YES')
	elif ss.find('00', sp) != -1:
		print('NO')
	else:
		print('YES')

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


T = int(input())
for _ in range(T):
	a = input()
	b = a[::-1]
	N = len(a)
	if '11' in a and '00' in b:
		if a.index('11') <= N - b.index('00') - 2:
			print('NO')
		else:
			print('YES')
	else:
		print('YES')


tc = int(input())
while tc > 0:
	s = input()
	l = len(s)
	Zero = []
	for i in range(l):
		if s[i] == '0':
			Zero.append(i)
	flag = True
	n = len(Zero)
	i = n - 1
	while i >= 0:
		if Zero[i] - Zero[i - 1] == 1:
			flag = False
			break
		else:
			i -= 1
	if flag == True:
		print('YES')
	else:
		i = Zero[i]
		One = []
		while i >= 0:
			if s[i] == '1':
				One.append(i)
			i -= 1
		ff = True
		for i in range(len(One) - 1):
			if abs(One[i] - One[i + 1]) == 1:
				ff = False
		if ff == True:
			print('YES')
		else:
			print('NO')
	tc -= 1


t = int(input())
for i in range(t):
	s = input()
	a = False
	for i in range(1, len(s)):
		if s[i] == s[i - 1] and s[i] == '1':
			a = True
		if a and s[i] == s[i - 1] and (s[i] == '0'):
			print('NO')
			break
	else:
		print('YES')


tc = int(input())
while tc > 0:
	tc -= 1
	s = input()
	pos = s.find('11')
	poss_0 = s[pos:].find('00')
	if poss_0 != -1:
		print('NO')
	else:
		print('YES')


from typing import List

def get_input() -> List[List[int]]:
	n = eval(input())
	ret = []
	for i in range(n):
		li = []
		a = input()
		for j in range(len(a)):
			li.append(int(a[j]))
		ret.append(li)
	return ret

def solve(case: List[int]):
	n = len(case)
	if n <= 3:
		return True
	idx = n - 1
	for i in range(1, n - 1):
		if case[i] == 1 and case[i - 1] == 1 and (case[i + 1] == 0):
			idx = i
			break
	for i in range(idx + 1, n - 1):
		if case[i] == 0 and case[i + 1] == 0:
			return False
	return True

def print_result(ans) -> None:
	if ans:
		print('YES')
	else:
		print('NO')

def solution() -> None:
	cases = get_input()
	for case in cases:
		print_result(solve(case))
solution()


from math import gcd
inp = int(input())
for _ in range(inp):
	s = input()
	i = s.find('11')
	j = s.rfind('00')
	if i != -1 and j != -1 and (i < j):
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	s = input()
	t = s.find('11')
	r = s[t:].find('00')
	if r != -1:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	s = input()
	n = len(s)
	f = [0] * n
	for i in range(n - 1, -1, -1):
		if i == n - 1:
			f[i] = s[i] == '0'
			continue
		f[i] = f[i + 1] + (s[i] == '0')
	if f[0] == 0 or f[0] == n:
		print('YES')
	else:
		i = 0
		flag = 0
		a = 0
		while i < n:
			if s[i] == '1':
				i += 1
				if i < n and s[i] == '1' and (f[i] != 0):
					j = i + 1
					while j < n:
						if s[j] == '0' and j + 1 < n and (s[j + 1] == '0'):
							flag = 1
							break
						j += 1
					a = 1
					break
				if i < n and f[i] <= 1:
					a = 1
					break
			if a == 1:
				break
			i += 1
		if flag == 1:
			print('NO')
		else:
			print('YES')


t = int(input())
for _ in range(t):
	s = input()
	p = -2
	flag = True
	for i in range(len(s)):
		if s[i] == '0':
			if i > p + 1:
				p = i
			else:
				flag = False
				break
	if flag:
		print('YES')
	else:
		p = -2
		flag = True
		for i in range(len(s)):
			if s[i] == '1':
				if i > p + 1:
					p = i
				else:
					flag = False
					break
		if flag:
			print('YES')
		else:
			flag = True
			for j in range(p, len(s)):
				if s[j] == '0':
					if j > p + 1:
						p = j
					else:
						flag = False
						break
			if flag:
				print('YES')
			else:
				print('NO')


import os
import math
import functools
true = True
false = False
from functools import reduce
is_dev = 'vscode' in os.environ
if is_dev:
	inF = open('in.txt', 'r')
	outF = open('out.txt', 'w')

def ins():
	return list(map(int, input_().split(' ')))

def inss():
	return list(input_().split(' '))

def input_():
	if is_dev:
		return inF.readline()[:-1]
	else:
		return input()

def ranin():
	return range(int(input_()))

def print_(data):
	if is_dev:
		outF.write(str(data) + '\n')
	else:
		print(data)
epsilon = 1e-07

@functools.lru_cache()
def solve(s, is_z=True, prev_remove=False):
	if s == '':
		return True
	if s[0] == '0':
		if prev_remove:
			if is_z:
				return solve(s[1:], True, False)
			else:
				return False
		elif is_z:
			return solve(s[1:], True, False)
		else:
			return solve(s[1:], False, True)
	elif not is_z:
		return solve(s[1:], False, False)
	elif prev_remove:
		return solve(s[1:], False, False)
	else:
		return solve(s[1:], False, False) or solve(s[1:], True, True)
for _ in ranin():
	s = input_()
	if solve(s):
		print_('YES')
	else:
		print_('NO')
if is_dev:
	outF.close()

	def compare_file():
		print(open('out.txt', 'r').read() == open('outactual.txt', 'r').read())
	compare_file()


def solve(s):
	a = {}
	for i in range(len(s) - 1):
		if s[i] != s[i + 1]:
			continue
		if s[i] in a:
			a[s[i]].append(i)
		else:
			a[s[i]] = [i]
	if '0' not in a or '1' not in a:
		return True
	return a['0'][-1] < a['1'][0]
t = int(input())
for _ in range(t):
	s = input()
	print('YES' if solve(s) else 'NO')


from sys import stdin, stdout
from collections import deque
import bisect
R = lambda : stdin.readline().strip()
RL = lambda f=None: list(map(f, R().split(' '))) if f else list(R().split(' '))
output = lambda x: stdout.write(str(x) + '\n')
output_list = lambda x: output(' '.join(map(str, x)))
import math
T = int(input())
for _ in range(T):
	s = input()
	one = -1
	ze = -1
	for i in range(0, max(0, len(s) - 1)):
		if s[i] == '1' and s[i + 1] == '1':
			one = i
			break
	for i in range(0, max(0, len(s) - 1)):
		if s[i] == '0' and s[i + 1] == '0':
			ze = i
	if one != -1 and ze != -1 and (one < ze):
		print('NO')
	else:
		print('YES')


t = int(input())
for _ in range(t):
	s = input()
	i = s.find('11')
	if not i == -1:
		j = s.find('00', i, len(s))
		if j == -1:
			print('YES')
		else:
			print('NO')
	else:
		print('YES')


import sys

def main():
	inp = sys.stdin.read().strip().split('\n')[1:]
	out = []
	for s in inp:
		t = s.replace('10', '')
		out.append(('YES', 'NO')[list(t) != sorted(t)])
	return out
print(*main(), sep='\n')


cases = int(input())
while cases:
	cases -= 1
	s = input()
	if '00' in s and '11' in s:
		if s.index('11') < s.rindex('00'):
			print('NO')
		else:
			print('YES')
	else:
		print('YES')


t = int(input())
while t:
	t -= 1
	s = input()
	flag = True
	i1 = s.find('11')
	if i1 != -1:
		if s[i1:].find('00') != -1:
			print('NO')
			continue
	print('YES')


t = int(input())
for _ in range(t):
	s = input()
	countone = 0
	counttwo = 0
	posione = []
	posizero = []
	for i in range(len(s)):
		if s[i] == '1':
			countone += 1
			counttwo = 0
			if countone == 2:
				posione.append(i)
		elif s[i] == '0':
			counttwo += 1
			countone = 0
			if counttwo == 2:
				posizero.append(i)
	if len(posione) > 0 and len(posizero) > 0 and (posizero[-1] > posione[0]):
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	a = input()
	if '11' in a and '00' in a[a.index('11'):]:
		print('NO')
	else:
		print('YES')


T = int(input())
for x in range(T):
	s = input()
	s1 = ''
	i = 0
	n = len(s)
	ans = ''
	l = list(s)
	l.sort()
	for p in l:
		s1 = s1 + p
	if s == s1:
		ans = 'YES'
	else:
		for y in range(1, n):
			if s[y - 1] == '1' and s[y] == '1':
				i = y
				break
		if i == 0 or i == n - 1:
			ans = 'YES'
		elif i + 1 == n - 1:
			ans = 'YES'
		else:
			for z in range(i + 2, n):
				if s[z - 1] == '0' and s[z] == '0':
					ans = 'NO'
					break
				else:
					ans = 'YES'
	print(ans)


for u in range(int(input())):
	s = input()
	a = -1
	if '11' in s:
		a = s.index('11')
	b = -1
	if '00' in s:
		b = len(s) - 1 - s[::-1].index('00')
	if a != -1 and b != -1 and (a < b):
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	s = input()
	zoz = []
	for j in range(len(s)):
		zoz.append(int(s[len(s) - j - 1]))
	dn = False
	pn = False
	c = 0
	for j in zoz:
		if pn == True and j == 0:
			dn = True
		elif pn == False and j == 1 and (dn == True):
			c = 1
		if j == 0:
			pn = True
		else:
			pn = False
	if c == 1:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	s = input()[:-1]
	if s == ''.join(sorted(s)):
		print('YES')
		continue

	def check(s0, x):
		n = len(s0)
		cand = [i for i in range(n) if s0[i] == x]
		flag = 1
		for (a, b) in zip(cand, cand[1:]):
			if b - a == 1:
				flag = 0
				break
		return flag
	n = len(s)
	for i in range(n + 1):
		if check(s[:i], '1') and check(s[i:], '0'):
			print('YES')
			break
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	ind11 = s.find('11')
	ind00 = s[::-1].find('00')
	if ind00 != -1:
		ind00 = len(s) - ind00 - 1
	if ind11 >= ind00 or ind11 == -1:
		print('YES')
	else:
		print('NO')


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

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

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
for _ in range(int(inp())):
	s = inp()
	flg = False
	flg2 = True
	for i in range(len(s) - 1):
		if s[i] == '1' and s[i + 1] == '1':
			flg = True
		if s[i] == '0' and s[i + 1] == '0':
			if flg:
				flg2 = False
				break
	print('YES' if flg2 else 'NO')


t = int(input())
for tt in range(t):
	s = input()
	n = len(s)
	(k, l) = (n, n)
	for i in range(1, n):
		if s[i] == '1' and s[i - 1] == '1':
			k = i
			break
	for i in range(1, n):
		if s[-i] == '0' and s[-i - 1] == '0':
			l = i
			break
	if k + l < n:
		print('NO')
	else:
		print('YES')


from sys import stdin, stdout
nmbr = lambda : int(input())
lst = lambda : list(map(int, input().split()))
for _ in range(nmbr()):
	s = input()
	n = len(s)
	l = []
	for i in range(n):
		prev = next = ' '
		if i - 1 >= 0:
			prev = s[i - 1]
		if i + 1 < n:
			next = s[i + 1]
		if s[i] != prev and s[i] != next:
			continue
		else:
			l += [s[i]]
	print('YES' if sorted(l) == l else 'NO')


def solve():
	s = input()
	ok = False
	n = len(s)
	for i in range(1, n):
		if s[i] == '1' and s[i - 1] == '1':
			ok = True
		elif s[i] == '0' and ok == True:
			if i + 1 < n and s[i + 1] == '0':
				print('NO')
				return
	print('YES')
for _ in range(int(input())):
	solve()


t = int(input())
for _ in range(t):
	s = input().rstrip()
	n = len(s)
	idx = -1
	f = 0
	for i in range(n - 1):
		if s[i] == '1':
			if s[i + 1] == '1':
				idx = i
				break
	if idx != -1:
		for i in range(idx + 1, n - 1):
			if s[i] == '0':
				if s[i + 1] == '0':
					f = 1
					break
		if f == 1:
			print('NO')
		else:
			print('YES')
	else:
		print('YES')


for j in range(1):
	pass
for _ in range(int(input())):
	s = input()
	if s.find('11') < s.rfind('00') and (s.find('11') != -1 and s.rfind('00') != -1):
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	a = input()
	i = 0
	c = 0
	if '11' in a:
		x = a.index('11') + 2
		if x < len(a) and '00' in a[x:]:
			print('NO')
		else:
			print('YES')
	else:
		print('YES')


import sys

def solve(s):
	n = len(s)
	ans = False
	for i in range(n):
		local_ans = True
		removal = []
		for j in range(i):
			if s[j] == '1':
				removal.append(j)
		for j in range(i, n):
			if s[j] == '0':
				removal.append(j)
		for i in range(1, len(removal)):
			if removal[i - 1] + 1 >= removal[i]:
				local_ans = False
		ans |= local_ans
	return 'YES' if ans else 'NO'
if 1 == 2:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = sys.stdin.readline
T = int(input())
for _ in range(T):
	s = input()
	print(solve(s))


for i in range(int(input())):
	s = input()
	if s.count('0') == 0 or s.count('1') == 0:
		print('YES')
		continue
	try:
		one = s.index('11')
		zero = len(s) - 1 - s[::-1].index('00')
		if one < zero:
			print('NO')
		else:
			print('YES')
	except:
		print('YES')


import os
import sys
from io import BytesIO, IOBase
import threading
from bisect import bisect_right
from math import gcd, log
from collections import Counter
from pprint import pprint
from itertools import permutations
from bisect import bisect_right

def main():
	s = [int(c) for c in input()]
	n = len(s)
	pr1 = False
	pv = False
	k = -1
	for i in range(n):
		if s[i] == 1:
			if pv == True:
				pr1 = True
			else:
				pv = True
		else:
			pv = False
			if pr1 == True:
				k = i
				break
	if k == -1:
		print('YES')
		return
	pv = True
	for i in range(k + 1, n):
		if i > 0 and s[i] == s[i - 1] == 0:
			print('NO')
			return
	print('YES')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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


t = int(input())
for test_case in range(t):
	binary = input()
	index = binary.find('11')
	if index < 0:
		print('YES')
		continue
	sub_binary = binary[index + 2:]
	if sub_binary.find('00') >= 0:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	s = input()
	flag = False
	if '00' in s and '11' in s:
		if s.rfind('00') > s.find('11'):
			flag = True
	if flag:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	s = list(input())
	s.remove('\n')
	start = -1
	for i in range(1, len(s)):
		if s[i] == '1' and s[i - 1] == '1':
			start = i + 1
			break
	if start == -1:
		print('YES')
	else:
		ans = True
		for i in range(start + 1, len(s)):
			if s[i] == '0' and s[i - 1] == '0':
				ans = False
				break
		if ans:
			print('YES')
		else:
			print('NO')


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	ans1 = n
	for i in range(n - 1):
		if s[i] == '1' and s[i + 1] == '1':
			ans1 = i
			break
	s = s[::-1]
	ans2 = 0
	for i in range(n - 1):
		if s[i] == '0' and s[i + 1] == '0':
			ans2 = n - i
			break
	if ans1 >= ans2:
		print('YES')
	else:
		print('NO')


il = lambda : list(map(int, input().split()))
iin = lambda : map(int, input().split())
ii = lambda : int(input())
for _ in range(ii()):
	s = input()
	(x, y) = (-1, -1)
	flag = 0
	for i in range(1, len(s)):
		if s[i] == s[i - 1]:
			if s[i] == '0':
				y = i - 1
			if s[i] == '1':
				x = i - 1
		if (x != -1 and y != -1) and x < y:
			print('NO')
			flag = 1
			break
	if flag == 0:
		print('YES')


def f(s):
	f1 = s.find('11')
	if f1 == -1:
		return 'YES'
	else:
		f2 = s.find('00', f1)
		if f2 == -1:
			return 'YES'
		else:
			return 'NO'
t = int(input())
l = []
for i in range(t):
	d = str(input())
	s = f(d)
	l.append(s)
for y in l:
	print(y)


T = int(input())
r = 1
while r <= T:
	s = input()
	ones = -1
	zeros = -1
	for i in range(len(s) - 1):
		if s[i] == '0' and s[i + 1] == '0':
			zeros = i
		if s[i] == '1' and s[i + 1] == '1' and (ones == -1):
			ones = i
	if ones >= 0 and ones < zeros:
		print('NO')
	else:
		print('YES')
	r += 1


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
from itertools import accumulate as ac
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = ip()
for _ in range(t):
	s = ips()
	s = list(s)
	cur = []
	main = False
	n = len(s)
	for i in range(n):
		left = s[:i]
		right = s[i:]
		cur = []
		val = None
		flag = True
		count = 0
		for j in range(0, i, 1):
			if s[j] == '1':
				count += 1
				if val == None:
					val = j
				else:
					if j - 1 == val:
						flag = False
						break
					val = j
			else:
				cur.append('0')
		for j in range(i, n, 1):
			if s[j] == '0':
				count += 1
				if val == None:
					val = j
				else:
					if j - 1 == val:
						flag = False
						break
					val = j
			else:
				cur.append('1')
		if flag and count > 0:
			main = True
			break
	if main:
		ans = 'YES'
	else:
		ans = 'NO'
	print(ans)


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

def solve(__=1):
	for _ in range(__):
		s = input()
		if '11' in s and '00' in s:
			if '00' in s[s.index('11'):]:
				print('NO')
			else:
				print('YES')
		else:
			print('YES')
solve(inp())


t = int(input())
for i in range(t):
	s = input()
	if '00' in s and '11' in s and (s.index('11') < len(s) - s[::-1].index('00')):
		print('NO')
	else:
		print('YES')


import sys
import math
import bisect
import functools
from functools import lru_cache
from sys import stdin, stdout
from math import gcd, floor, sqrt, log, ceil
from heapq import heappush, heappop, heapify
from collections import defaultdict as dd
from collections import Counter as cc
from bisect import bisect_left as bl
from bisect import bisect_right as br

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)
sys.setrecursionlimit(100000000)
intinp = lambda : int(input().strip())
stripinp = lambda : input().strip()
fltarr = lambda : list(map(float, input().strip().split()))
intarr = lambda : list(map(int, input().strip().split()))
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
MOD = 1000000007

@lru_cache(None)
def help(need, left):
	if left == '':
		return True
	if len(left) > 1:
		if left[0] == '0' and need and (left[1] == '1'):
			return help(need, left[2:])
		elif left[1] == '0' and need and (left[0] == '1'):
			return help(need, left[1:])
		elif need and left[1] == '0' and (left[0] == '0'):
			return False
		else:
			return help(need or int(left[1]), left[2:]) or help(need or int(left[0]), left[1:])
	elif left[0] == '0' and need:
		return help(need, left[1:])
	else:
		return help(need or int(left[0]), left[1:]) or help(need, left[1:])
num_cases = intinp()
for _ in range(num_cases):
	s = stripinp()
	if help(0, s):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	first = s.find('11')
	last = s.rfind('00')
	if first != -1 and last != -1 and (first < last):
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	s = list(input())
	ans = 'YES'
	o = 0
	z = 0
	for i in range(len(s) - 1):
		if s[i] == '1' and s[i + 1] == '1':
			o = 1
		elif s[i] == '0' and s[i + 1] == '0' and (o == 1):
			ans = 'NO'
	print(ans)


t = int(input())
for _ in range(t):
	a = input().strip()
	L = len(a)
	if '11' not in a:
		print('YES')
	else:
		for i in range(L - 1):
			if a[i] == '1' and a[i + 1] == '1':
				if '00' in a[i + 2:L]:
					print('NO')
				else:
					print('YES')
				break


for _ in range(int(input())):
	s = input()
	p = -1
	if s == '0' * len(s) or s == '1' * len(s):
		print('YES')
		continue
	for i in range(len(s)):
		if s[i] == '1':
			p = i
			break
	if p == -1:
		p = len(s) - 1
	i = p
	f = 0
	while i < len(s) - 1:
		if s[i] == '1' and s[i + 1] == '1':
			p = i + 2
			f = 1
			break
		elif s[i] == '1' and s[i + 1] == '0':
			i += 2
		else:
			i += 1
	if f == 0:
		p = i
	ans = s[p:]
	if ans.find('00') != -1:
		print('NO')
	else:
		print('YES')


import os
import sys
from io import BytesIO, IOBase
import math
BUFSIZE = 8192
from collections import Counter

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
for _ in range(t):
	s = input()
	f = 0
	for i in range(len(s)):
		r = 1
		for j in range(1, i):
			if s[j] == s[j - 1] == '1':
				r = 0
				break
		for j in range(i + 2, len(s)):
			if s[j] == s[j - 1] == '0':
				r = 0
				break
		if r == 1:
			f = 1
			break
	if f:
		print('YES')
	else:
		print('NO')


def checkifcanbesorted():
	s = input()
	a1 = s.split('11', 1)
	if len(a1) == 1:
		return 'YES'
	a1 = a1[1].split('00', 1)
	return 'YES' if len(a1) == 1 else 'NO'
n = int(input())
for i in range(n):
	print(checkifcanbesorted())


import sys, math
sys.setrecursionlimit(10 ** 8)

def find(s):
	if s.count('00') == 0 or s.count('11') == 0:
		return 'YES'
	if s.index('11') < s.rindex('00'):
		return 'NO'
	return 'YES'
t = int(input())
for _ in range(t):
	s = input()
	print(find(s))


def answer(s):
	if len(s) == 2:
		return 'YES'
	ssorted = sorted(s)
	if ssorted == s:
		return 'YES'
	two_ones = False
	two_ones_addr = -1
	two_zeros = False
	two_zeros_addr = -1
	for i in range(1, len(s)):
		if s[i] == s[i - 1] and s[i] == '1' and (two_ones == False):
			two_ones_addr = i
			two_ones = True
		if s[i] == s[i - 1] and s[i] == '0':
			two_zeros_addr = i
	if two_ones and two_ones_addr < two_zeros_addr:
		return 'NO'
	return 'YES'

def main():
	t = int(input())
	s = [0] * t
	for j in range(t):
		s[j] = input()
	for j in range(t):
		print(answer(s[j]))
main()


t = int(input())
while t:
	s = input()
	pos = s.find('11')
	if pos == -1:
		print('YES')
	elif s.find('00', pos) == -1:
		print('YES')
	else:
		print('NO')
	t -= 1


import sys
input = sys.stdin.readline

def solution(s):
	n = len(s)
	last_position_double_0 = -1
	first_position_double_1 = n + 1
	for pos in range(n - 1):
		if s[pos] == s[pos + 1] == '0':
			last_position_double_0 = pos
	for pos in range(n - 1, 0, -1):
		if s[pos] == s[pos - 1] == '1':
			first_position_double_1 = pos - 1
	if last_position_double_0 < first_position_double_1:
		print('YES')
	else:
		print('NO')
T = int(input())
for t in range(T):
	s = input().strip()
	solution(s)