When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.

Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≤ L'≤ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.

Tell whether Chef can go to heaven.

------ Input ------

The first line contains an integer $T$, the number of test cases. Then the test cases follow. 
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.

------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).

You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).

------ Constraints  ------
$1 ≤ L ≤ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$

------ Subtasks ------

Subtask #1 (100 points): original constraints

----- Sample Input 1 ------ 
3

2

10

3

001

4

0100
----- Sample Output 1 ------ 
YES

NO

YES
----- explanation 1 ------ 
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.

Test case 2: There's no way Chef can go to heaven.

Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.

Source: codechef | Difficulty: EASY
Tags: Greedy algorithms


Solutions:
for i in range(0, int(input())):
	n = int(input())
	l = list(input())
	t = 0
	a = 0
	b = 0
	for j in range(0, n):
		t = t + 1
		if l[j] == '0':
			a = a + 1
		else:
			b = b + 1
		if b >= t / 2:
			print('YES')
			break
		elif j == n - 1 and b < t / 2:
			print('NO')
		else:
			continue


for _ in range(int(input())):
	n = int(input())
	s = input()
	(c, c1) = (0, 0)
	ans = 'NO'
	for i in s:
		if i == '1':
			c1 += 1
		c += 1
		if c1 * 2 >= c:
			ans = 'YES'
			break
	print(ans)


t = int(input())
for ni in range(t):
	l = int(input())
	s = input()
	(s0, s1) = (0, 0)
	pos = 'NO'
	for i in range(len(s)):
		if s[i] == '0':
			s0 = s0 + 1
		else:
			s1 = s1 + 1
		if s1 >= s0:
			pos = 'YES'
			break
	print(pos)


t = int(input())
while t:
	l = int(input())
	s = input()
	if s.count('1') >= s.count('0'):
		print('YES')
	else:
		a = 0
		flag = False
		for i in range(0, l):
			if s[i] == '1':
				a += 1
				if a >= (i + 1) / 2:
					flag = True
					break
		if flag == True:
			print('YES')
		else:
			print('NO')
	t -= 1


a = int(input(''))
for i in range(a):
	x = int(input(''))
	t = input('')
	c1 = 0
	c0 = 0
	flag = 0
	for j in range(len(t)):
		if t[j] == '1':
			c1 = c1 + 1
		else:
			c0 = c0 + 1
		if c1 >= c0:
			flag = 1
	print('YES' if flag else 'NO')


for _ in range(int(input())):
	n = int(input())
	s = input()
	count1 = 0
	count0 = 0
	flag = 0
	for i in range(len(s)):
		if s[i] == '1':
			count1 += 1
		else:
			count0 += 1
		if count1 >= count0:
			flag = 1
	print('YES' if flag else 'NO')


t = int(input())
for i in range(t):
	L = int(input())
	S = input()
	b = 0
	g = 0
	flag = 0
	for j in range(L):
		if S[j] == '0':
			b = b + 1
		elif S[j] == '1':
			g = g + 1
		if g >= b:
			flag = 1
			break
	if flag == 0:
		print('NO')
	else:
		print('YES')


t = int(input())
for t in range(t):
	l = int(input())
	s = input()
	count_0 = 0
	count_1 = 0
	flag = 0
	for i in range(len(s)):
		if s[i] == '0':
			count_0 += 1
		else:
			count_1 += 1
		if count_1 >= count_0 and count_0 != 0 or (count_0 == 0 and count_1 > 0):
			flag = 1
			break
	if flag == 0:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	L = int(input())
	S = input().strip()
	if S.count('1') >= L // 2 + (L % 2 > 0):
		print('YES')
		continue
	count = 0
	yrs = 0
	for c in S:
		count += c == '1'
		yrs += 1
		if count >= yrs // 2 + (yrs % 2 > 0):
			print('YES')
			break
	else:
		print('NO')


for tc in range(int(input())):
	L = int(input())
	S = input()
	(g, t) = (0, 0)
	ans = 'NO'
	for i in S:
		t += 1
		if i == '1':
			g += 1
		if g / t >= 0.5:
			ans = 'YES'
			break
		else:
			ans = 'NO'
	print(ans)


import re
for i in range(int(input())):
	l = int(input())
	str1 = input()
	sum1 = 0
	sum2 = 0
	if str1[0] == '1':
		print('YES')
	else:
		for i in str1:
			if i == '0':
				sum1 = sum1 + 1
			else:
				sum2 = sum2 + 1
			if sum2 >= sum1:
				print('YES')
				break
			elif sum2 + sum1 == len(str1):
				print('NO')


t = int(input())
for i in range(t):
	l = int(input())
	s = input()
	flag = 0
	(count1, count2) = (0, 0)
	for i in s:
		if i == '0':
			count1 += 1
		else:
			count2 += 1
		if count2 >= count1:
			flag = 1
			break
	if flag:
		print('YES')
	else:
		print('NO')


t = int(input())
while t != 0:
	n = int(input())
	s = input()
	c = 0
	f = 0
	for k in range(n):
		if s[k] == '1':
			c += 1
			if c >= (k + 1) / 2:
				f = 1
				break
	if f == 1:
		print('YES')
	else:
		print('NO')
	t -= 1


for _ in range(int(input())):
	n = int(input())
	s = input()
	(o, z) = (0, 0)
	c = 'NO'
	for i in s:
		if i == '0':
			z += 1
		else:
			o += 1
			if o >= z:
				c = 'YES'
				break
	print(c)


for _ in range(int(input())):
	l = int(input())
	s = input()
	z = 0
	o = 0
	ans = 'NO'
	for c in s:
		if c == '0':
			z += 1
		else:
			o += 1
			if o >= z:
				ans = 'YES'
				break
	print(ans)


for i in range(int(input())):
	a = int(input())
	s = input()
	c = d = 0
	for i in range(len(s)):
		if s[i] == '1':
			c += 1
		if c * 100 / (i + 1) >= 50:
			print('YES')
			break
	else:
		print('NO')


import math
for i in range(int(input())):
	n = int(input())
	s = input()
	c = 0
	if s.count('1') >= s.count('0'):
		print('YES')
	else:
		o = 0
		z = 0
		for i in s:
			if i == '1':
				o += 1
			else:
				z += 1
			if o == z:
				c += 1
				print('YES')
				break
		if c == 0:
			print('NO')


t = int(input())
for _ in range(t):
	l = int(input())
	s = input()
	cntz = 0
	cnto = 0
	t = True
	for i in range(l):
		if s[i] == '0':
			cntz += 1
		if s[i] == '1':
			cnto += 1
		if cntz == cnto:
			t = False
			break
	if cntz < cnto or not t:
		print('YES')
	else:
		print('NO')


T = int(input())
for _ in range(T):
	L = int(input())
	S = input()
	zeros = 0
	ones = 0
	flag = False
	for i in S:
		if i == '1':
			ones += 1
		else:
			zeros += 1
		if ones >= zeros:
			flag = True
			break
	print('YES' if flag else 'NO')


for i in range(int(input())):
	a = int(input())
	b = input()
	ch = 0
	bj = 0
	for i in range(1, a + 1):
		if b[i - 1] == '1':
			ch += 1
		if ch / i >= 0.5:
			bj += 1
			break
	if bj == 1:
		print('YES')
	else:
		print('NO')


t = int(input())
for k in range(t):
	n = int(input())
	a = str(input())
	b = 0
	c = 0
	d = 0
	while b != len(a):
		if a[b] == '0':
			c += 1
		else:
			d += 1
		b += 1
		if c <= d:
			b = len(a)
	if c <= d:
		print('YES')
	else:
		print('NO')


T = int(input())
for i in range(T):
	L = int(input())
	S = input()
	c = 0
	li = []
	for j in S:
		li.append(j)
	for i in range(L):
		if li[i] == '1':
			c = c + 1
		if c * 100 / (i + 1) >= 50:
			z = c * 100 / (i + 1)
			break
		else:
			z = c * 100 / (i + 1)
	print('YES' if z >= 50 else 'NO')


for _ in range(int(input())):
	n = int(input())
	s = input()
	one = 0
	chk = 0
	for i in range(1, n + 1):
		if s[i - 1] == '1':
			one += 1
		if one / i >= 0.5:
			chk = 1
			break
	if chk == 1:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	l = int(input())
	s = input()
	good = s.count('1')
	bad = s.count('0')
	if good >= len(s) / 2:
		print('YES')
	else:
		(cb, cg, flag) = (0, 0, False)
		for i in s:
			if i == '1':
				cg += 1
			else:
				cb += 1
			if cg >= cb:
				print('YES')
				flag = True
				break
		if flag == False:
			print('NO')


t = int(input())
for i in range(t):
	l = int(input())
	s = input()
	c = 0
	d = 0
	ans = False
	for i in s:
		if i == '0':
			c += 1
		else:
			d += 1
		if c <= d:
			ans = True
			break
	if ans:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	s = input()
	heaven = False
	one = 0
	total = 0
	for i in s:
		if i == '1':
			one += 1
			total += 1
			if 2 * one >= total:
				heaven = True
				break
		else:
			total += 1
	if heaven:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	st = input()
	g = 0
	b = 0
	d = 0
	for i in st:
		if i == '0':
			b = b + 1
		else:
			g = g + 1
		if g >= b:
			print('YES')
			d = d + 1
			break
	if d == 0:
		print('NO')


for _ in range(int(input())):
	l = int(input())
	s = input()
	c = 0
	c1 = 0
	x = 0
	for i in range(l):
		if s[i] == '0':
			c += 1
		else:
			c1 += 1
		if c1 >= c:
			x = i + 1
			break
	if x == 0:
		print('NO')
	else:
		print('YES')


q = int(input())
while q > 0:
	q -= 1
	n = int(input())
	l = input()
	count = 0
	flag = 0
	for i in range(0, n):
		if l[i] == '1':
			count += 1
		if count / (i + 1) * 100 >= 50:
			flag = 1
			break
	if flag == 0:
		print('NO')
	else:
		print('YES')


for t in range(int(input())):
	l = input()
	s = input()
	one = 0
	zero = 0
	c = 0
	for i in s:
		if i == '1':
			one = one + 1
		else:
			zero = zero + 1
		if one >= zero:
			c = c + 1
			print('YES')
			break
	if c == 0:
		print('NO')


tests = int(input())
for i in range(tests):
	length = int(input())
	string = input()
	ans = 'NO'
	zeroes = 0
	ones = 0
	for j in string:
		if j == '0':
			zeroes += 1
		else:
			ones += 1
		if ones >= zeroes:
			ans = 'YES'
			break
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	(x, y) = (0, 0)
	for i in s:
		if i == '1':
			x += 1
		else:
			y += 1
		if x >= y:
			print('YES')
			break
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	s = input()
	(a, b) = (0, 0)
	for i in s:
		if i == '1':
			a += 1
		else:
			b += 1
		if a >= b:
			print('YES')
			break
	else:
		print('NO')


T = int(input())

def algo():
	L = int(input())
	S = input()
	b = 0
	g = 0
	out = 0
	for i in S:
		if i == '0':
			b += 1
		else:
			g += 1
			if g >= b:
				out = 1
				break
	if out == 1:
		print('YES')
	else:
		print('NO')
for i in range(T):
	algo()


T = int(input())
for i in range(T):
	n = int(input())
	l = str(input())
	bad = 0
	good = 0
	p = False
	for z in l:
		if z == '1':
			good += 1
		else:
			bad += 1
		if good >= bad:
			p = True
	if p:
		print('YES')
	else:
		print('NO')


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	s = stdin.readline().strip()
	q = 0
	for c in s:
		q += -1 if c == '0' else 1
		if q >= 0:
			break
	print('NO' if q < 0 else 'YES')


for _ in range(int(input())):
	n = int(input())
	s = input()
	(c1, c2, f) = (0, 0, 0)
	for i in s:
		if i == '0':
			c1 += 1
		else:
			c2 += 1
		if c2 >= c1:
			print('YES')
			f = 1
			break
	if f == 0:
		print('NO')


t = int(input())
while t:
	t -= 1
	n = int(input())
	s = input()
	count0 = 0
	count1 = 0
	f = 0
	for i in s:
		if i == '0':
			count0 += 1
		else:
			count1 += 1
		if count1 >= count0:
			print('YES')
			f = 1
			break
	if f == 0:
		print('NO')


for i in range(int(input())):
	L = int(input())
	S = str(input())
	Y = 0
	flag = False
	if S.count('1') >= L / 2:
		flag = True
	else:
		for ii in range(L):
			Y = Y + int(S[ii])
			if Y / (ii + 1) >= 0.5:
				flag = True
				break
	print('YES') if flag else print('NO')


for _ in range(int(input())):
	N = int(input())
	S = input()
	(One, zero) = (0, 0)
	flag = False
	for i in range(N):
		if S[i] == '0':
			zero += 1
		else:
			One += 1
		if One >= zero:
			flag = True
			break
	if flag:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	l = int(input())
	s = input()
	h = []
	hl = []
	for j in s:
		if j == '0':
			hl.append(j)
		else:
			h.append(j)
		if len(h) >= len(hl):
			print('YES')
			break
	else:
		print('NO')


t = int(input())
for i in range(t):
	L = int(input())
	S = input()
	good = 0
	bad = 0
	poss = False
	for i in range(L):
		if S[i] == '1':
			good += 1
		else:
			bad += 1
		if good >= bad:
			poss = True
	if poss:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	l = int(input())
	s = input()
	x = 'NO'
	g = 0
	b = 0
	if s.count('1') >= l / 2:
		x = 'YES'
	else:
		for i in s:
			if g >= b and g != 0:
				x = 'YES'
				break
			elif i == '1':
				g += 1
			else:
				b += 1
	print(x)


t = int(input())
for _ in range(t):
	n = int(input())
	life = str(input())
	count = 0
	if life.count('1') >= life.count('0'):
		print('YES')
	else:
		i = 0
		while i < n:
			if life[i] == '0':
				count = count - 1
			else:
				count = count + 1
				if count >= 0:
					break
			i = i + 1
		if count >= 0:
			print('YES')
		else:
			print('NO')


for i in range(int(input())):
	L = int(input())
	s = input()
	ones = 0
	zeros = 0
	for j in range(len(s)):
		if s[j] == '0':
			zeros += 1
		else:
			ones += 1
		if ones >= zeros:
			print('YES')
			break
	else:
		print('NO')


t = int(input())
while t > 0:
	l = int(input())
	s = input()
	i = 0
	flg = 0
	c0 = 0
	c1 = 0
	while i < l:
		if s[i] == '1':
			c1 += 1
			if c1 * 100 / (i + 1) >= 50:
				flg = 1
				print('YES')
				break
		i += 1
	if flg == 0:
		print('NO')
	t -= 1


for _ in range(int(input())):
	L = int(input())
	S = input()
	bad = 0
	good = 0
	for i in range(L):
		if i != 0 and bad <= good:
			break
		if S[i] == '0':
			bad += 1
		else:
			good += 1
	if bad <= good:
		print('YES')
	else:
		print('NO')


import math
for _ in range(int(input())):
	n = int(input())
	s = input()
	l = 0
	c = 0
	for i in range(n):
		if i != 0 and l <= c:
			break
		elif s[i] == '0':
			l += 1
		else:
			c += 1
	if l <= c:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	g = 0
	b = 0
	ded = True
	l = int(input())
	s = input()
	for j in s:
		ded = True
		if j == '1':
			g += 1
			if g >= b:
				print('YES')
				ded = False
				break
		elif j == '0':
			b += 1
			if g >= b:
				print('YES')
				ded = False
				break
	if ded:
		print('NO')


t = int(input())
while t > 0:
	n = int(input())
	strg = list(input())
	count_zero = 0
	for i in range(n):
		var = 'NO'
		if strg[i] == '0':
			count_zero += 1
		if i + 1 - count_zero >= count_zero:
			var = 'YES'
			break
	print(var)
	t -= 1


testcasenum = int(input())

def heaven(deeds):
	good_deeds = 0
	bad_deeds = 0
	for i in range(len(deeds)):
		if deeds[i] == 1:
			good_deeds += 1
		elif deeds[i] == 0:
			bad_deeds += 1
		if good_deeds >= bad_deeds:
			return 'YES'
	return 'NO'
for __ in range(testcasenum):
	life = int(input())
	deeds = list(map(int, list(input())))
	result = heaven(deeds)
	print(result)


n = int(input())
num = []
dt = []
for i in range(0, n):
	num.append(int(input()))
	dt.append(input())
for j in range(0, n):
	pas = 0
	gd = 0
	bd = 0
	lst = list(dt[j])
	for k in range(0, num[j]):
		if lst[k] == '0':
			bd = bd + 1
		else:
			gd = gd + 1
		if gd >= bd:
			pas = pas + 1
	if pas == 0:
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	l = 0
	c = 0
	j = int(input())
	st = input()
	for i in range(0, len(st)):
		if i != 0 and l <= c:
			break
		elif st[i] == '0':
			l = l + 1
		else:
			c = c + 1
	if l <= c:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	a = int(input())
	b = input()
	g = 0
	p = 0
	k = 0
	for i in b:
		if i == '1':
			g += 1
		if i == '0':
			p += 1
		if g >= p:
			print('YES')
			k = 1
			break
	if k == 0:
		print('NO')


T = int(input())
for i in range(T):
	L = int(input())
	S = input()
	count = 0
	count1 = 0
	for j in S:
		if int(j) == 1:
			count += 1
		else:
			count1 += 1
		if count >= count1:
			print('YES')
			break
	if count1 > count:
		print('NO')


t = int(input())
while t > 0:
	l = int(input())
	s = input()
	countz = 0
	counto = 0
	for i in range(0, len(s)):
		if s[i] == '0':
			countz = countz + 1
		else:
			counto = counto + 1
		if counto >= countz:
			print('YES')
			break
	if countz > counto:
		print('NO')
	t = t - 1


def main():
	for _ in range(int(input())):
		L = int(input())
		S = input()
		(gy, by) = (0, 0)
		ans = 'NO'
		for i in range(L):
			if S[i] == '1':
				gy += 1
			else:
				by += 1
			if gy >= by:
				ans = 'YES'
				break
		print(ans)
main()


t = int(input())
for i in range(t):
	L = int(input())
	S = input()
	total1 = 0
	total2 = 0
	flag = 0
	for i in range(L):
		if S[i] == '0':
			total1 += 1
		else:
			total2 += 1
			if total2 >= total1:
				flag = 1
				print('YES')
				break
	if flag == 0:
		print('NO')


class Person:

	def __init__(self, deed):
		self.deed = deed

	def good_deed(self):
		self.deed += 1

	def bad_deed(self):
		self.deed -= 1
person = Person(1)
t = int(input())
while t:
	t -= 1
	n = int(input())
	s = input()
	person.deed = 1
	for i in s:
		if i == '0':
			person.bad_deed()
		else:
			person.good_deed()
		if person.deed > 0:
			break
	if person.deed > 0:
		print('YES')
	else:
		print('NO')