$n$ students attended the first meeting of the Berland SU programming course ($n$ is even). All students will be divided into two groups. Each group will be attending exactly one lesson each week during one of the five working days (Monday, Tuesday, Wednesday, Thursday and Friday), and the days chosen for the groups must be different. Furthermore, both groups should contain the same number of students.

Each student has filled a survey in which they told which days of the week are convenient for them to attend a lesson, and which are not.

Your task is to determine if it is possible to choose two different week days to schedule the lessons for the group (the first group will attend the lesson on the first chosen day, the second group will attend the lesson on the second chosen day), and divide the students into two groups, so the groups have equal sizes, and for each student, the chosen lesson day for their group is convenient.


-----Input-----

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

Then the descriptions of $t$ testcases follow.

The first line of each testcase contains one integer $n$ ($2 \le n \le 1000$) — the number of students.

The $i$-th of the next $n$ lines contains $5$ integers, each of them is $0$ or $1$. If the $j$-th integer is $1$, then the $i$-th student can attend the lessons on the $j$-th day of the week. If the $j$-th integer is $0$, then the $i$-th student cannot attend the lessons on the $j$-th day of the week.

Additional constraints on the input: for each student, at least one of the days of the week is convenient, the total number of students over all testcases doesn't exceed $10^5$.


-----Output-----

For each testcase print an answer. If it's possible to divide the students into two groups of equal sizes and choose different days for the groups so each student can attend the lesson in the chosen day of their group, print "YES" (without quotes). Otherwise, print "NO" (without quotes).


-----Examples-----

Input
2
4
1 0 0 1 0
0 1 0 0 1
0 0 0 1 0
0 1 0 1 0
2
0 0 0 1 0
0 0 0 1 0
Output
YES
NO


-----Note-----

In the first testcase, there is a way to meet all the constraints. For example, the first group can consist of the first and the third students, they will attend the lessons on Thursday (the fourth day); the second group can consist of the second and the fourth students, and they will attend the lessons on Tuesday (the second day).

In the second testcase, it is impossible to divide the students into groups so they attend the lessons on different days.

Difficulty: EASY

Solutions:
from itertools import combinations

def solve(test_case):
	n = int(input())
	mat = []
	for i in range(n):
		mat.append([int(x) for x in input().split()])
	sets = []
	for j in range(5):
		temp = set()
		for i in range(n):
			if mat[i][j] == 1:
				temp.add(i)
		if len(temp) >= n / 2:
			sets.append(temp)
	if len(sets) < 2:
		print('NO')
		return
	combs = combinations(sets, 2)
	for comb in combs:
		if len(comb[0] | comb[1]) == n:
			print('YES')
			return
	print('NO')
t = int(input())
for i in range(t):
	solve(i + 1)


t = int(input())
for _ in range(t):
	n = int(input())
	l = []
	for i in range(n):
		l.append(list(map(int, input().split())))
	s = [sum([l[i][j] for i in range(n)]) for j in range(5)]
	c = []
	for i in range(5):
		if s[i] >= n // 2:
			c.append(i)
	if len(c) < 2:
		print('NO')
	else:
		possible = False
		x = []
		for i in c:
			x.append([l[j][i] for j in range(n)])
		for i in range(len(x) - 1):
			for j in range(i + 1, len(x)):
				(onei, onej, both) = (0, 0, 0)
				for k in range(n):
					if x[i][k] + x[j][k] == 0:
						break
					if x[i][k] + x[j][k] == 2:
						both += 1
					elif x[i][k] == 1:
						onei += 1
					else:
						onej += 1
				if onei + onej + both < n:
					continue
				if onei + both >= n // 2 and onej + both >= n // 2:
					possible = True
					break
			if possible:
				break
		print('YES' if possible else 'NO')


import io, os, sys
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
output = sys.stdout.write

def solve(N, grid):
	sz = [0] * 5
	cols = [0] * 5
	for d in range(5):
		for r in range(N):
			cols[d] |= grid[r][d] << r
			sz[d] += grid[r][d]
	target = (1 << N) - 1
	for d1 in range(5):
		for d2 in range(d1 + 1, 5):
			if cols[d1] | cols[d2] == target and sz[d1] >= N // 2 and (sz[d2] >= N // 2):
				return 'YES\n'
	return 'NO\n'

def main():
	T = int(input())
	for _ in range(T):
		N = int(input())
		grid = [list(map(int, input().split())) for _ in range(N)]
		out = solve(N, grid)
		output(out)
main()


import collections
import itertools
t = int(input())
for _ in range(t):
	n = int(input())
	students = []
	days = [0 for _ in range(5)]
	days_to_students = collections.defaultdict(set)
	for i in range(n):
		student = list(map(int, input().split()))
		for (day, amount) in enumerate(student):
			if amount:
				days[day] += 1
				days_to_students[day].add(i)
	good_days = []
	for i in range(5):
		if days[i] >= n // 2:
			good_days.append(i)
	for (a, b) in itertools.combinations(good_days, 2):
		if len(days_to_students[a] | days_to_students[b]) == n:
			print('YES')
			break
	else:
		print('NO')


t = int(input())
for i in range(t):
	count1 = [0, 0, 0, 0, 0]
	n = int(input())
	m = n // 2
	a = []
	for j in range(n):
		a.append(input().split())
		for day in range(5):
			count1[day] += int(a[j][day])
	kt = False
	for j in range(4):
		if count1[j] >= m:
			for g in range(j + 1, 5):
				if count1[g] >= m:
					kt = True
					for k in range(n):
						if a[k][j] == a[k][g] == '0':
							kt = False
							break
					if kt == True:
						print('YES')
						break
			if kt == True:
				break
	if kt == False:
		print('NO')


import sys
input = sys.stdin.readline
t = int(input())
result = []
for _ in range(t):
	n = int(input())
	matrix = []
	for z in range(n):
		matrix.append(list(map(int, input().split())))

	def solve():
		for i in range(5):
			for x in range(i + 1, 5):
				(firstGroup, secondGroup, both) = (0, 0, 0)
				for z in range(n):
					if matrix[z][i] and (not matrix[z][x]):
						firstGroup += 1
					if matrix[z][x] and (not matrix[z][i]):
						secondGroup += 1
					if matrix[z][x] and matrix[z][i]:
						both += 1
				if firstGroup > n // 2 or secondGroup > n // 2:
					continue
				if firstGroup + secondGroup + both == n:
					return 'YES'
		return 'NO'
	print(solve())


import os
import sys
from io import BytesIO, IOBase
import math
from collections import Counter

def func(n, array):
	sets = [set() for i in range(5)]
	for (i, subarray) in enumerate(array):
		for (index, status) in enumerate(subarray):
			if status == 1:
				sets[index].add(i)
	candidates = []
	for i in sets:
		if len(i) >= n // 2:
			candidates.append(i)
	for i in range(len(candidates)):
		for j in range(i + 1, len(candidates)):
			if not set(range(n)) - candidates[i].union(candidates[j]):
				return 'YES'
	return 'NO'

def main():
	num_test = int(parse_input())
	result = []
	for _ in range(num_test):
		n = int(parse_input())
		array = []
		for _ in range(n):
			array.append([int(i) for i in parse_input().split()])
		result.append(func(n, array))
	print('\n'.join(map(str, result)))
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))
parse_input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	n = int(input())
	data = []
	for _ in range(n):
		data.append(list(map(int, input().split())))
	days = []
	for j in range(5):
		sumday = 0
		for i in range(n):
			sumday += data[i][j]
		if sumday >= n / 2:
			days.append(j)
	if len(days) < 2:
		print('NO')
		continue
	Possible = False
	for i in range(len(days)):
		for j in range(i + 1, len(days)):
			students = [False] * n
			for k in range(n):
				students[k] = data[k][days[i]] or data[k][days[j]]
			if all(students):
				Possible = True
				break
		if Possible:
			print('YES')
			break
	else:
		print('NO')


import bisect
import collections
import copy
import functools
import itertools
import math
import operator
import sys
import os
from heapq import heappop, heappush
from typing import Callable, Generic, Iterable, List, Tuple, TypeVar, Union
sys.setrecursionlimit(100000)
is_local = 'TERM_PROGRAM' in os.environ
input = sys.stdin.readline
INF = float('inf')

def debug(*args, **kwargs):
	if is_local:
		print(*args, **kwargs)

def I():
	return input().rstrip()

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

def II():
	return int(input())

def IIS():
	return map(int, input().split())

def LIIS():
	return list(map(int, input().split()))
from typing import Union
MOD = 10 ** 9 + 7

class Mod:
	mod = MOD

	def __init__(self, x: int) -> None:
		self.x = x % self.mod

	def __add__(self, other: Union['Mod', int]) -> 'Mod':
		if isinstance(other, int):
			return Mod(self.x + other)
		return Mod(self.x + other.x)

	def __sub__(self, other: Union['Mod', int]) -> 'Mod':
		if isinstance(other, int):
			return Mod(self.x - other)
		return Mod(self.x - other.x)

	def __mul__(self, other: Union['Mod', int]) -> 'Mod':
		if isinstance(other, int):
			return Mod(self.x * other)
		return Mod(self.x * other.x)

	def __truediv__(self, other: Union['Mod', int]) -> 'Mod':
		if isinstance(other, int):
			return Mod(self.x // other)
		return Mod(self.x * other.inv().x)

	def __eq__(self, other: 'Mod') -> bool:
		return self.x == other.x

	def __le__(self, other: 'Mod') -> bool:
		return self.x <= other.x

	def __lt__(self, other: 'Mod') -> bool:
		return self.x < other.x

	def __ge__(self, other: 'Mod') -> bool:
		return self.x >= other.x

	def __gt__(self, other: 'Mod') -> bool:
		return self.x > other.x

	def __ne__(self, other: 'Mod') -> bool:
		return self.x != other.x

	def inv(self) -> 'Mod':
		a = self.x
		b = self.mod
		(u, v) = (1, 0)
		while b > 0:
			t = a // b
			(a, b) = (b, a - t * b)
			(u, v) = (v, u - t * v)
		return Mod(u)

	def __pow__(self, ex: int) -> 'Mod':
		a = self.x
		res = 1
		while ex > 0:
			if ex & 1:
				res = res * a % self.mod
			a = a * a % self.mod
			ex >>= 1
		return Mod(res)

	def __str__(self) -> str:
		return str(self.x)

	def __repr__(self) -> str:
		return str(self.x)

def MII():
	return Mod(int(input()))

def MIIS():
	return map(Mod, map(int, input().split()))

def LMIIS():
	return list(map(Mod, map(int, input().split())))

def main():
	q = II()
	for _ in range(q):
		n = II()
		students = []
		for _ in range(n):
			students.append(LIIS())
		ans = solve(n, students)
		print(ans)

def solve(n, students):
	for i in range(5):
		for j in range(i):
			gi = set()
			gj = set()
			for k in range(n):
				if students[k][i] == 1:
					gi.add(k)
				if students[k][j] == 1:
					gj.add(k)
			if len(gi | gj) == n and len(gi) >= n // 2 and (len(gj) >= n // 2):
				return 'YES'
	return 'NO'
main()


def solve(n, a):
	n2 = n // 2
	for i in range(4):
		for j in range(i + 1, 5):
			(o1, o2, both) = (0, 0, 0)
			for k in range(n):
				if a[k][i]:
					if a[k][j]:
						both += 1
					else:
						o1 += 1
				elif a[k][j]:
					o2 += 1
				else:
					break
			if o1 + o2 + both == n:
				if o1 <= n2 and o2 <= n2:
					return 'YES'
	return 'NO'
t = int(input())
for i_t in range(t):
	n = int(input())
	a = []
	for i_n in range(n):
		a.append(list(map(int, input().split(' '))))
	print(solve(n, a))


import sys
input = sys.stdin.readline

def il():
	return list(map(int, input().split()))

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

def imi():
	return map(int, input().split())

def ist():
	return input()

def solve(i, j, n, li):
	a = 0
	b = 0
	c = 0
	for s in li:
		if s[i] == s[j] == 1:
			b += 1
		elif s[i] == 1:
			a += 1
		elif s[j] == 1:
			c += 1
	if a + b + c == n:
		if a <= n // 2 and c <= n // 2:
			return 1
		else:
			return 0
	else:
		return 0
t = ii()
for _ in range(t):
	n = ii()
	li = []
	c = 0
	for i in range(n):
		st = il()
		li.append(st)
	for i in range(5):
		for j in range(i + 1, 5):
			if solve(i, j, n, li):
				c = 1
				break
		if c:
			break
	else:
		print('NO')
		continue
	print('YES')


for _ in range(int(input())):
	n = int(input())
	half = n // 2
	week = [[0, set({})], [0, set({})], [0, set({})], [0, set({})], [0, set({})]]
	ref = []
	flag = 0
	for i in range(n):
		a = list(map(int, input().split()))
		for x in range(5):
			if a[x]:
				week[x][1].add(i)
				week[x][0] += 1
	for i in range(5):
		if week[i][0] >= half:
			for b in ref:
				if n == len(b.union(week[i][1])):
					flag = 1
					break
			ref.append(week[i][1])
		if flag:
			break
	print('YES' if flag else 'NO')


t = int(input())
for _ in range(t):
	n = int(input())
	days = {'Monday': [], 'Tuesday': [], 'Wednesday': [], 'Thursday': [], 'Friday': []}
	for i in range(n):
		student = list(map(int, input().split()))
		if student[0]:
			days['Monday'].append(i)
		if student[1]:
			days['Tuesday'].append(i)
		if student[2]:
			days['Wednesday'].append(i)
		if student[3]:
			days['Thursday'].append(i)
		if student[4]:
			days['Friday'].append(i)
	days = sorted(list(days.values()), key=len)
	match = False
	days = [i for i in days if len(i) >= n / 2]
	for i in range(len(days)):
		if match:
			break
		for j in range(i + 1, len(days)):
			a = days[i]
			b = days[j]
			total = len(a) + len(b)
			unique = len(set(days[i] + days[j]))
			extra = total - unique
			if total - extra >= n:
				print('YES')
				match = True
				break
	if not match:
		print('NO')


CASES = int(input())
for _ in range(CASES):
	n = int(input())
	cases = []
	for i in range(n):
		cases.append(list(map(int, input().split())))
	days = []
	for i in range(5):
		temp = set()
		for j in range(n):
			if cases[j][i]:
				temp.add(j)
		days.append(temp)
	flag = False
	for i in range(5):
		if flag:
			break
		for j in range(i + 1, 5):
			if len(days[i] | days[j]) == n and len(days[i]) >= n // 2 and (len(days[j]) >= n // 2):
				flag = True
				break
	if flag:
		print('YES')
	else:
		print('NO')


import heapq
import math
import sys
import collections
import bisect
import time
import random
import itertools
import string
from collections import Counter, defaultdict

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

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

def get_string():
	return sys.stdin.readline().strip()
for t in range(int(input())):
	n = int(input())
	arr = []
	for i in range(n):
		arr.append(get_list())
	poss = False
	for i in range(5):
		for j in range(i + 1, 5):
			s1 = set()
			s2 = set()
			for no in range(n):
				if arr[no][i] == 1:
					s1.add(no)
				if arr[no][j] == 1:
					s2.add(no)
			joined_set = s1.union(s2)
			if len(s1) >= n // 2 and len(s2) >= n // 2 and (len(joined_set) == n):
				poss = True
				break
	if poss:
		print('YES')
	else:
		print('NO')


I = input
for _ in [0] * int(I()):
	n = int(I())
	a = [x for x in zip(*(I() for _ in [0] * n)) if 2 * x.count('1') >= n]
	print('YNEOS'[all(((*'00',) in [*zip(x, y)] for (i, x) in enumerate(a) for y in a[:i]))::2])


for _ in range(int(input())):
	n = int(input())
	l = []
	for i in range(n):
		l.append(list(map(int, input().split())))
	ll = []
	for i in range(5):
		c = []
		for j in range(n):
			if l[j][i] == 1:
				c.append(j + 1)
		ll.append(c)
	del l, c
	z = 0
	for i in range(5):
		for j in range(i + 1, 5):
			if len(ll[i]) >= n // 2 and len(ll[j]) >= n // 2:
				s = set(ll[i]) | set(ll[j])
				if len(s) == n:
					z = -1
					break
		if z == -1:
			break
	if z == -1:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def st():
	return input().rstrip('\n')

def lis():
	return list(map(int, input().split()))

def ma():
	return map(int, input().split())
t = inp()
while t:
	t -= 1
	n = inp()
	r = []
	for i in range(n):
		r.append(lis())
	if n % 2:
		print('NO')
		continue
	s = 'NO'
	for i in range(5):
		for j in range(i + 1, 5):
			(of, sf, bf) = (0, 0, 0)
			for k in range(n):
				if r[k][i] == 1 and r[k][j] == 1:
					bf += 1
				elif r[k][i] == 1:
					of += 1
				elif r[k][j] == 1:
					sf += 1
			need = n // 2
			req1 = max(0, n // 2 - of)
			req2 = max(0, n // 2 - sf)
			if req1 + of == req2 + sf and req1 + req2 == bf:
				s = 'YES'
	print(s)


import os
import sys
from io import BytesIO, IOBase
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')
from collections import Counter, defaultdict
import math
import heapq
import bisect

def nck(n, k):
	res = 1
	for i in range(1, k + 1):
		res = res * (n - i + 1) // i
	return res
for _ in range(int(input())):
	n = int(input())
	g = []
	a = [0] * 5
	for i in range(n):
		s = list(map(int, input().split()))
		for j in range(5):
			if s[j] == 1:
				a[j] += 1
		g.append(s)
	f = 0
	for i in range(5):
		for j in range(i + 1, 5):
			if f == 1:
				break
			if a[i] > n // 2 and a[j] > n // 2:
				v1 = a[i]
				v2 = a[j]
				for k in range(n):
					if g[k][i] == 1 and g[k][j] == 1:
						if v1 < v2:
							v2 -= 1
						else:
							v1 -= 1
				if v1 >= n // 2 and v2 >= n // 2:
					f = 1
			elif a[i] == n // 2 and a[j] >= n // 2:
				v1 = a[i]
				v2 = a[j]
				for k in range(n):
					if g[k][i] == 1 and g[k][j] == 1:
						if v1 < v2:
							v2 -= 1
						else:
							v1 -= 1
				if v1 >= n // 2 and v2 >= n // 2:
					f = 1
			elif a[i] > n // 2 and a[j] == n // 2:
				v1 = a[i]
				v2 = a[j]
				for k in range(n):
					if g[k][i] == 1 and g[k][j] == 1:
						if v1 < v2:
							v2 -= 1
						else:
							v1 -= 1
				if v1 >= n // 2 and v2 >= n // 2:
					f = 1
	print('YES' if f == 1 else 'NO')


import os
import sys
from io import BytesIO, IOBase
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 t in range(int(input())):
	n = int(input())
	l = [list(map(int, input().split())) for i in range(n)]
	l1 = [0] * n
	ans = 'NO'
	for i in range(5):
		a = 0
		for k in range(n):
			if l[k][i]:
				l1[k] = 1
				a += 1
		if a >= n // 2:
			for j in range(5):
				if i != j:
					b = 0
					x = a
					for k in range(n):
						if l[k][j] == 1:
							if l1[k] and x > n // 2:
								b += 1
								x -= 1
							elif not l1[k]:
								b += 1
					if b == n // 2:
						ans = 'YES'
						break
			if ans == 'YES':
				break
		l1 = [0] * n
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = [[] for i in range(n)]
	for j in range(n):
		a[j] = list(map(int, input().split()))
	ans = False
	for j in range(5):
		for k in range(5):
			if k != j:
				cnt1 = 0
				cnt2 = 0
				cntno = 0
				for z in range(n):
					if a[z][j] == 1:
						cnt1 += 1
					if a[z][k] == 1:
						cnt2 += 1
					if a[z][j] == 0 and a[z][k] == 0:
						cntno += 1
				if cnt1 >= n // 2 and cnt2 >= n // 2 and (cntno == 0):
					ans = True
	if ans:
		print('YES')
	else:
		print('NO')


T = int(input())
for testcase in range(1, T + 1):
	n = int(input())
	nn = 2 ** n - 1
	b = [False * 5]
	c = ['' for i in range(5)]
	for i in range(n):
		x = input().split()
		for j in range(5):
			c[j] = c[j] + x[j]
	d = []
	for j in range(5):
		if c[j].count('1') >= n // 2:
			d.append(int(c[j], 2))
	found = False
	for i in range(len(d) - 1):
		for j in range(i + 1, len(d)):
			(x, y) = (d[i], d[j])
			if x | y == nn:
				found = True
				break
		if found:
			break
	if found:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	s = []
	s.append(set())
	s.append(set())
	s.append(set())
	s.append(set())
	s.append(set())
	for i in range(n):
		l = [int(x) for x in input().split()]
		for j in range(5):
			if l[j]:
				s[j].add(i + 1)
	flag = True
	for i in range(4):
		for j in range(i + 1, 5, 1):
			intersectionLen = len(s[i] & s[j])
			x1 = len(s[i]) - intersectionLen
			x2 = len(s[j]) - intersectionLen
			x1req = n // 2 - x1
			x2req = n // 2 - x2
			if x1req < 0 or x2req < 0:
				continue
			if x1req + x2req == intersectionLen:
				print('YES')
				flag = False
				break
		if not flag:
			break
	if flag:
		print('NO')


import math
import os
import sys
from sys import *
from decimal import *
from io import BytesIO, IOBase
from itertools import *
from collections import *
from array import *
import random
M = 10 ** 9 + 7
import heapq
import bisect
from functools import lru_cache
from queue import PriorityQueue
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')

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

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

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

def fsep():
	return map(float, inp().split())

def inpu():
	return int(inp())

def binarySearch(arr, n, key):
	left = 0
	right = n - 1
	while left <= right:
		mid = (right + left) // 2
		if arr[mid] == key:
			return mid
		if arr[mid] <= key:
			left = mid + 1
		else:
			right = mid - 1
	return -1

def sumofdigits(n):
	n = str(n)
	s1 = 0
	for i in n:
		s1 += int(i)
	return s1

def perfect_square(n):
	s = math.sqrt(n)
	if s == int(s):
		return True
	return False

def luckynumber(x, n, a):
	if x > 0:
		a.append(x)
	if x > 10 ** 9:
		return a
	elif x < 1000000000000.0:
		luckynumber(x * 10 + 4, n, a)
		luckynumber(x * 10 + 7, n, a)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def query1(l, r):
	if l >= r:
		return -1
	print('?', l + 1, r + 1)
	sys.stdout.flush()
	return int(input()) - 1

def answer(p):
	print('!', p + 1)
	sys.stdout.flush()
	exit()

def rse(arr, n):
	stack = []
	ans = []
	for i in range(n - 1, -1, -1):
		if len(stack) == 0:
			ans.append(n)
		else:
			while len(stack) != 0:
				if stack[-1][0] >= arr[i]:
					stack.pop()
				else:
					break
			if len(stack) == 0:
				ans.append(n)
			else:
				ans.append(stack[-1][1])
		stack.append([arr[i], i])
	ans.reverse()
	return ans

def lse(arr, n):
	stack = []
	ans = []
	for i in range(n):
		if len(stack) == 0:
			ans.append(-1)
		else:
			while len(stack) != 0:
				if stack[-1][0] >= arr[i]:
					stack.pop()
				else:
					break
			if len(stack) == 0:
				ans.append(-1)
			else:
				ans.append(stack[-1][1])
		stack.append([arr[i], i])
	return ans

def mah(arr):
	max1 = 0
	p = rse(arr, len(arr))
	q = lse(arr, len(arr))
	for i in range(len(arr)):
		a = (p[i] - q[i] - 1) * arr[i]
		max1 = max(a, max1)
	return max1

def maxSumIS(arr, n):
	msis = arr.copy()
	for i in range(1, n):
		for j in range(i):
			if arr[i] > arr[j] and msis[i] < msis[j] + arr[i]:
				msis[i] = msis[j] + arr[i]
	c = max(msis)
	p = 5
	return c

def binarysearch2(arr, target):
	lo = 0
	hi = len(arr) - 1
	while lo <= hi:
		mid = (lo + hi) // 2
		if arr[mid] == target:
			if mid != len(arr) - 1:
				if arr[mid + 1] != target:
					return mid
				else:
					lo += 1
			else:
				return mid
			continue
		if arr[mid] > target:
			hi = mid - 1
		else:
			lo = mid + 1

def nge(arr, n):
	stack = []
	ans = []
	for i in range(n - 1, -1, -1):
		if len(stack) == 0:
			ans.append(-1)
		else:
			while len(stack) > 0:
				if stack[-1][0] < arr[i]:
					stack.pop()
				else:
					break
			if len(stack) == 0:
				ans.append(-1)
			else:
				ans.append(stack[-1][1])
		stack.append([arr[i], i])
	ans.reverse()
	return ans

def alperm(nums, path, result):
	if not nums:
		result.add(tuple(path))
		return
	for i in range(0, len(nums)):
		alperm(nums[:i] + nums[i + 1:], path + [nums[i]], result)
	return result

def minsum(arr, n, m, res, l):
	if n == 1 and m == 1:
		res += arr[0][0]
		l.append(res)
	else:
		if n != 1:
			p = res + arr[n - 1][m - 1]
			minsum(arr, n - 1, m, p, l)
		if m != 1:
			p = res + arr[n - 1][m - 1]
			minsum(arr, n, m - 1, p, l)
	return min(l)

def find_shortest_path(graph, start, end, path):
	path = path + [start]
	if start == end:
		return path
	if start not in graph:
		return None
	shortest = None
	for node in graph[start]:
		if node not in path:
			newpath = find_shortest_path(graph, node, end, path)
			if newpath:
				if not shortest or len(newpath) < len(shortest):
					shortest = newpath
	return shortest

def test(n, d):
	a = random.randint(1, n - 2)
	p = pow(a, d, n)
	if p == 1 or p == n - 1:
		return True
	while d != n - 1:
		d *= 2
		p = pow(p, 2, n)
		if p == n - 1:
			return True
	return False

def isprime(n):
	if n == 1:
		return False
	if n == 2:
		return True
	if n == 3:
		return True
	d = n - 1
	while d % 2 == 0:
		d //= 2
	for i in range(5):
		if test(n, d) == False:
			return False
	return True

def muin(a, m):
	(x, y, mo) = (1, 0, m)
	if m == 1:
		return 0
	while m > 0:
		(x, y) = (y, x - a // m * y)
		(a, m) = (m, a % m)
	if x < 0:
		return mo + x
	else:
		return x

def good(l, c):
	ch = chr(c)
	if len(l) == 1:
		return 1 if ch != l[0] else 0
	k = len(l) // 2
	lm = k - l[:k].count(ch) + good(l[k:], c + 1)
	rm = k - l[k:].count(ch) + good(l[:k], c + 1)
	return min(lm, rm)

def facto(fact):
	(fact[0], fact[1]) = (1, 1)
	for i in range(2, 10 ** 6 + 1):
		fact[i] = fact[i - 1] * i % M

def comb(n, r, fact):
	return fact[n] * pow(fact[n - r] * fact[r], M - 2, M) % M

def numberToBase(n, b):
	if n == 0:
		return 0
	digits = []
	while n:
		digits.append(n % b)
		n //= b
	return sum(digits)

def main():
	t = 1
	t = inpu()
	for _ in range(t):
		n = inpu()
		l = []
		(mon, tue, wed, thu, fr) = (0, 0, 0, 0, 0)
		p = []
		for i in range(n):
			(a, b, c, d, e) = sep()
			p.append([a, b, c, d, e])
			if a == 1:
				mon += 1
			if b == 1:
				tue += 1
			if c == 1:
				wed += 1
			if d == 1:
				thu += 1
			if e == 1:
				fr += 1
		l = [mon, tue, wed, thu, fr]
		ll = []
		flag = False
		for i in range(5):
			for j in range(5):
				if i != j:
					if l[i] + l[j] >= n and l[i] >= n // 2 and (l[j] >= n // 2):
						ll.append([i, j])
		for (i, j) in ll:
			s = set()
			for k in range(n):
				if p[k][i] == 1:
					s.add(k)
			for k in range(n):
				if p[k][j] == 1:
					s.add(k)
			if len(s) == n:
				print('YES')
				break
		else:
			print('NO')
main()


from typing import Counter
import sys
from collections import defaultdict as dd
from math import *

def vinp():
	return map(int, input().split())

def linp():
	return list(map(int, input().split()))

def sinp():
	return input()

def inp():
	return int(input())

def mod(f):
	return f % 1000000007

def pr(*x):
	print(*x)

def finp():
	f = open('input.txt', 'r')
	f = f.read().split('\n')
	return f

def finp():
	f = open('input.txt', 'r')
	f = f.read().split('\n')
	return f

def fout():
	return open('output.txt', 'w')

def fpr(f, x):
	f.write(x + '\n')

def csort(c):
	sorted(c.items(), key=lambda pair: pair[1], reverse=True)

def indc(l, n):
	c = {}
	for i in range(n):
		c[l[i]] = c.get(l[i], []) + [i + 1]
	return c
cou = inp()
for _ in range(cou):
	n = inp()
	l = [linp() for i in range(n)]
	p = True
	for i in range(5):
		for j in range(i + 1, 5):
			f1 = 0
			f2 = 0
			b = 0
			for k in range(n):
				if l[k][i] and l[k][j]:
					b += 1
				elif l[k][i]:
					f1 += 1
				elif l[k][j]:
					f2 += 1
			if f1 + f2 + b == n and (f1 + b >= n / 2 and f2 + b >= n / 2) and p:
				p = False
				pr('YES')
	if p:
		pr('NO')


for _ in range(int(input())):
	n = int(input())
	db = {0: [0, set()], 1: [0, set()], 2: [0, set()], 3: [0, set()], 4: [0, set()]}
	for i in range(n):
		inp = [int(i) for i in input().split()]
		for j in range(5):
			if inp[j] == 1:
				db[j][0] += 1
				db[j][1].add(i)
	pas = False
	for i in range(4):
		for j in range(i + 1, 5):
			if db[i][0] < n // 2 or db[j][0] < n // 2:
				continue
			if len(db[i][1].union(db[j][1])) == n:
				pas = True
				break
		if pas:
			break
	print('YES' if pas else 'NO')


import os
import sys
from io import BytesIO, IOBase

def main():

	def check():
		half = n // 2
		for i in range(5):
			for j in range(i + 1, 5):
				if len(li[i]) < half or len(li[j]) < half:
					continue
				if len(li[i] | li[j]) == n:
					return True
		return False
	for _ in range(int(input())):
		n = int(input())
		li = [set() for _ in range(5)]
		for i in range(n):
			temp = list(map(int, input().split()))
			for j in range(5):
				if temp[j] == 1:
					li[j].add(i)
		if check():
			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')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def main():
	for _ in range(int(input())):
		n = int(input())
		a = []
		s = [0, 0, 0, 0, 0]
		fl = False
		for i in range(n):
			a.append(list(map(int, input().split())))
		for i in range(5):
			s[i] = sum([x[i] for x in a])
		for i in range(5):
			for j in range(i, 5):
				if i != j and (s[i] >= n // 2 and s[j] >= n // 2) and (sum([0 if not a[x][i] and (not a[x][j]) else 1 for x in range(n)]) == n):
					print('YES')
					fl = True
					break
			if fl:
				break
		if not fl:
			print('NO')
main()


import sys
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	n = int(input())
	mat = [list(map(int, input().split())) for i in range(n)]
	ok = False
	for i in range(5):
		for j in range(5):
			if i == j:
				continue
			cnti = 0
			cntj = 0
			cntij = 0
			for k in range(n):
				if mat[k][i] == 1 and mat[k][j] == 1:
					cntij += 1
				elif mat[k][i] == 1:
					cnti += 1
				elif mat[k][j] == 1:
					cntj += 1
			if cnti + cntj + cntij != n:
				continue
			if cnti <= n // 2 and cntj <= n // 2:
				ok = True
	if ok:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	g = []
	arr = [0] * 5
	for i in range(n):
		s = list(map(int, input().split()))
		for j in range(5):
			if s[j] == 1:
				arr[j] += 1
		g.append(s)
	f = 0
	for i in range(5):
		for j in range(i + 1, 5):
			if f == 1:
				break
			if arr[i] > n // 2 and arr[j] > n // 2:
				v1 = arr[i]
				v2 = arr[j]
				for k in range(n):
					if g[k][i] == 1 and g[k][j] == 1:
						if v1 < v2:
							v2 -= 1
						else:
							v1 -= 1
				if v1 >= n // 2 and v2 >= n // 2:
					f = 1
			elif arr[i] == n // 2 and arr[j] >= n // 2:
				v1 = arr[i]
				v2 = arr[j]
				for k in range(n):
					if g[k][i] == 1 and g[k][j] == 1:
						if v1 < v2:
							v2 -= 1
						else:
							v1 -= 1
				if v1 >= n // 2 and v2 >= n // 2:
					f = 1
			elif arr[i] > n // 2 and arr[j] == n // 2:
				v1 = arr[i]
				v2 = arr[j]
				for k in range(n):
					if g[k][i] == 1 and g[k][j] == 1:
						if v1 < v2:
							v2 -= 1
						else:
							v1 -= 1
				if v1 >= n // 2 and v2 >= n // 2:
					f = 1
	print('YES' if f == 1 else 'NO')


import sys
input = sys.stdin.readline
from itertools import combinations
for _ in range(int(input())):
	n = int(input())
	w = [[], [], [], [], []]
	for i in range(n):
		p = list(map(int, input().split()))
		for j in range(5):
			if p[j]:
				w[j] += [i]
	for i in combinations(range(0, 5), 2):
		len1 = len(w[i[0]])
		len2 = len(w[i[1]])
		if len(set(w[i[0]]) | set(w[i[1]])) == n:
			len1 = len(set(w[i[0]]) - set(w[i[1]]))
			len2 = len(set(w[i[1]]) - set(w[i[0]]))
			if len1 <= n / 2 and len2 <= n / 2:
				print('YES')
				break
	else:
		print('NO')


def check():
	for i in range(5):
		for j in range(i + 1, 5):
			flag = cnt1 = cnt2 = 0
			for k in range(n):
				if a[k][i] == a[k][j] == '0':
					flag = 1
					break
				if a[k][i] == '1':
					cnt1 += 1
				if a[k][j] == '1':
					cnt2 += 1
			if cnt1 >= n / 2 and cnt2 >= n / 2 and (flag == 0):
				return 1
	return 0
for _ in range(int(input())):
	n = int(input())
	a = [input().split() for i in range(n)]
	print('YES' if check() else 'NO')


import io, os, sys
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
output = sys.stdout.write

def solve(N, grid):
	for a in range(5):
		for b in range(a + 1, 5):
			ca = cb = cab = 0
			for i in range(N):
				if grid[i][a]:
					ca += 1
				if grid[i][b]:
					cb += 1
				if grid[i][a] or grid[i][b]:
					cab += 1
			if cab == N and ca >= N // 2 and (cb >= N // 2):
				return 'YES\n'
	return 'NO\n'

def main():
	T = int(input())
	for _ in range(T):
		N = int(input())
		grid = [list(map(int, input().split())) for _ in range(N)]
		out = solve(N, grid)
		output(out)
main()


from math import *
from collections import defaultdict as dt
from sys import stdin
inp = lambda : stdin.readline().strip()
I = lambda : int(inp())
M = lambda : map(int, inp().split())
L = lambda : list(M())
mod = 1000000007
inf = 100000000000000000000
ss = 'abcdefghijklmnopqrstuvwxyz'

def solve():
	n = I()
	d = dt(list)
	for i in range(n):
		a = L()
		for j in range(5):
			if a[j]:
				d[j].append(i)
	for i in range(5):
		for j in range(i + 1, 5):
			if len(d[i]) >= n // 2 and len(d[j]) >= n // 2 and (len(set(d[i] + d[j])) == n):
				print('YES')
				return
	print('NO')
tt = 1
tt = I()
for _ in range(tt):
	solve()


for _ in range(int(input())):
	n = int(input())
	arr = []
	for i in range(n):
		nxt = list(map(int, input().split(' ')))
		arr.append(nxt)
	found = False
	for i in range(4):
		free_i = sum([x[i] for x in arr])
		if free_i >= n // 2:
			extra = free_i - n // 2
			for j in range(i + 1, 5):
				free_j = sum([x[j] for x in arr])
				if free_j >= n // 2 and free_j - sum([x[i] and x[j] for x in arr]) + extra >= n // 2:
					print('YES')
					found = True
					break
		if found:
			break
	if not found:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	l = []
	for i in range(n):
		a = list(map(int, input().split()))
		l.append(a)
	flag = False
	for x in range(5):
		for y in range(x + 1, 5):
			c1 = 0
			c2 = 0
			c3 = 0
			for k in range(n):
				if l[k][x] == 1 and l[k][y] == 1:
					c3 = c3 + 1
				elif l[k][x] == 1:
					c1 = c1 + 1
				elif l[k][y] == 1:
					c2 = c2 + 1
				else:
					break
			if c1 + c3 + c2 == n and c1 + c3 >= n / 2 and (c2 + c3 >= n / 2):
				flag = True
	if flag == True:
		print('YES')
	else:
		print('NO')


class Comba:

	def __init__(self, mod):
		self.fact = array.array('i', [0] * MX)
		self.fact[0] = 1
		self.fact_inv = array.array('i', [0] * MX)
		self.mod = mod
		for i in range(1, MX):
			self.fact[i] = self.fact[i - 1] * i % self.mod
		self.fact_inv[MX - 1] = pow(self.fact[MX - 1], self.mod - 2, self.mod)
		for i in range(MX - 2, -1, -1):
			self.fact_inv[i] = self.fact_inv[i + 1] * (i + 1) % self.mod

	def ncr(self, n, r):
		if r > n or n < 0 or r < 0:
			return 0
		return self.fact[n] * self.fact_inv[r] % self.mod * self.fact_inv[n - r] % self.mod

	def npr(self, n, r):
		if r > n or n < 0 or r < 0:
			return 0
		return self.fact[n] * self.fact_inv[n - r] % self.mod

def lcm(a, b):
	return a * b // gcd(a, b)

def rw_file():
	sys.stdin = open('', 'r')
	sys.stdout = open('', 'w')

def re(data=str):
	return data(sys.stdin.readline().rstrip())

def mp(data=str):
	return map(data, sys.stdin.readline().split())
import sys, array
from bisect import bisect_left, bisect_right, insort_left
from math import ceil, floor, log, sqrt, gcd
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop, heapify
(mod, mod9, nl, MX) = (1000000007, 998244353, '\n', 200003)

def solve(tc):
	n = re(int)
	grid = [list(mp(int)) for i in range(n)]
	for d1 in range(5):
		for d2 in range(d1 + 1, 5):
			(cnt1, cnt2, both) = (0, 0, 0)
			bad = False
			for i in range(n):
				if not grid[i][d1] and (not grid[i][d2]):
					bad = True
					break
				elif grid[i][d1] and grid[i][d2]:
					both += 1
				elif grid[i][d1]:
					cnt1 += 1
				elif grid[i][d2]:
					cnt2 += 1
			if not bad:
				(ok1, ok2) = (False, False)
				if cnt1 + both >= n // 2:
					ok1 = True
					both -= n // 2 - cnt1 if n // 2 > cnt1 else 0
				if cnt2 + both >= n // 2:
					ok2 = True
					both -= n // 2 - cnt2 if n // 2 > cnt2 else 0
				if ok1 and ok2:
					print('YES')
					return
	print('NO')
	return None

def main():
	tests = 1
	tests = re(int)
	for case in range(1, tests + 1):
		solve(case)
main()


def get_column(mat, i):
	return [row[i] for row in mat]
t = int(input())
for _ in range(t):
	students = []
	n = int(input())
	for __ in range(n):
		student = list(map(int, input().split()))
		students.append(student)
	flag = 1
	for i in range(4):
		foo = get_column(students, i)
		if foo.count(1) < n / 2:
			continue
		for j in range(i + 1, 5):
			bar = get_column(students, j)
			if bar.count(1) < n / 2:
				continue
			flag = 0
			for k in range(n):
				if foo[k] == 0 and bar[k] == 0:
					flag = 1
					break
			if not flag:
				break
		if not flag:
			break
	if flag:
		print('NO')
	else:
		print('YES')


from sys import stdin, stdout
input = stdin.readline
t = int(input().strip())
for _ in range(t):
	n = int(input().strip())
	arr = list()
	for i in range(n):
		a = list(map(int, input().strip().split()))
		arr.append(a)
	arr1 = list(zip(*arr))
	temp = [sum(array) for array in arr1]
	days = [i for i in range(5) if temp[i] >= n // 2]
	size = len(days)
	flag = 0
	for i in range(size):
		for j in range(i + 1, size):
			temp1 = arr1[days[i]]
			temp2 = arr1[days[j]]
			temp = [temp1[k] + temp2[k] for k in range(n)]
			res = 0 in temp
			if not res:
				flag = 1
				break
		if flag == 1:
			break
	if flag == 1:
		ans = 'YES'
	else:
		ans = 'NO'
	stdout.write(ans + '\n')


def f():
	n = int(input())
	l = [set() for i in range(5)]
	for i in range(n):
		a = list(map(int, input().split()))
		for j in range(5):
			if a[j]:
				l[j].add(i)
	for i in range(4):
		for j in range(i + 1, 5):
			if len(l[i] | l[j]) == n and min(len(l[i]), len(l[j])) >= n // 2:
				return 'YES'
	return 'NO'
for _ in range(int(input())):
	print(f())


t = int(input())
for _ in range(t):
	n = int(input())
	arr = []
	for g in range(n):
		arr.append(input().split())
	middle = n / 2
	solve = False
	for x in range(5):
		y = x + 1
		for y in range(y, 5):
			sl = sr = sb = 0
			for s in arr:
				if s[x] == '0' and s[y] == '0':
					break
				if s[x] == s[y]:
					sb += 1
				elif s[x] == '1':
					sl += 1
				else:
					sr += 1
			while sl < middle and sb > 0:
				sl += 1
				sb -= 1
			while sr < middle and sb > 0:
				sr += 1
				sb -= 1
			if sl == sr and sl == middle:
				solve = True
	print('YES' if solve else 'NO')


for _ in range(int(input())):
	dic = {1: [], 2: [], 3: [], 4: [], 5: []}
	n = int(input())
	for j in range(n):
		lst = list(map(int, input().split()))
		for i in range(len(lst)):
			if lst[i] == 1:
				dic[i + 1].append(j + 1)
	val = list(dic.values())
	c = 0
	for i in range(len(val) - 1):
		nst = []
		for j in range(i + 1, len(val)):
			if len(val[i]) >= n // 2 and len(val[j]) >= n // 2:
				nst = val[i] + val[j]
				if len(set(nst)) == n:
					print('YES')
					c = 1
					break
		if c == 1:
			break
	if c == 0:
		print('NO')


def allDays(arr, a, b):
	n = len(arr)
	c = 0
	for i in range(n):
		if arr[i][a] == 1 or arr[i][b] == 1:
			c += 1
	return n == c
t = int(input())
for z in range(t):
	n = int(input())
	a = []
	for i in range(n):
		a.append([int(x) for x in input().split()])
	count = [0 for i in range(5)]
	c = False
	for i in a:
		for j in range(5):
			if i[j] == 1:
				count[j] += 1
	for i in range(5):
		for j in range(i + 1, 5):
			if allDays(a, i, j) and count[i] >= n / 2 and (count[j] >= n / 2):
				c = True
	if c:
		print('YES')
	else:
		print('NO')


import itertools
t = int(input())
for i in range(t):
	available_list = [[] for i in range(5)]
	possible_day_index = set()
	n = int(input())
	for u in range(1, n + 1):
		available_status_student = list(map(int, input().split()))
		for j in range(5):
			if available_status_student[j] != 0:
				available_list[j].append(u)
	for days_index in range(0, 5):
		if len(available_list[days_index]) >= int(n / 2):
			possible_day_index.add(days_index)
	possible_answer = list(itertools.combinations(possible_day_index, 2))
	if len(possible_day_index) < 2:
		print('NO')
		continue
	else:
		for possible_element in possible_answer:
			a = set(available_list[possible_element[0]])
			b = set(available_list[possible_element[1]])
			if not len(a | b) == n:
				continue
			elif len(a) < n / 2 and len(b) < n / 2:
				continue
			else:
				print('YES')
				break
		else:
			print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	answer = 'NO'
	sum_list = [0] * 5
	st_day = []
	for _ in range(n):
		temp = list(map(int, input().split()))
		st_day.append(temp)
		sum_list = [a + b for (a, b) in zip(temp, sum_list)]
	for i in range(5):
		if sum_list[i] < n // 2:
			continue
		for j in range(i + 1, 5):
			if sum_list[j] < n // 2:
				continue
			answer = 'YES'
			for student in st_day:
				if student[i] + student[j] == 0:
					answer = 'NO'
			if answer == 'YES':
				break
		if answer == 'YES':
			break
	print(answer)


t = int(input())
res = []
for i in range(t):
	num_stud = int(input())
	tab = []
	for j in range(num_stud):
		lin = list(map(int, input().split()))
		tab.append(lin)
	sum_col = []
	for j in range(5):
		s_col = 0
		for s in range(num_stud):
			s_col += tab[s][j]
		sum_col.append(s_col)
	t_res = False
	for j in range(5):
		if sum_col[j] < num_stud // 2:
			continue
		for k in range(j + 1, 5):
			if sum_col[k] < num_stud // 2:
				continue
			br = False
			for l in range(num_stud):
				if tab[l][j] == 0 and tab[l][k] == 0:
					br = True
			if br:
				continue
			t_res = True
			break
		if t_res:
			break
	if t_res:
		res.append('YES')
	else:
		res.append('NO')
for el in res:
	print(el)


import sys, math, bisect
from random import randint
inf = float('inf')
mod = 10 ** 9 + 7

def nCr(n, r):
	return fact(n) / (fact(r) * fact(n - r))

def fact(n):
	res = 1
	for i in range(2, n + 1):
		res = res * i
	return res

def lcm(a, b):
	return int(a / math.gcd(a, b) * b)

def gcd(a, b):
	return int(math.gcd(a, b))

def tobinary(n):
	return bin(n)[2:]

def binarySearch(a, x):
	i = bisect.bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	else:
		return -1

def lowerBound(a, x):
	i = bisect.bisect_left(a, x)
	if i:
		return i - 1
	else:
		return -1

def upperBound(a, x):
	i = bisect.bisect_right(a, x)
	if i != len(a) + 1 and a[i - 1] == x:
		return i - 1
	else:
		return -1

def primesInRange(n):
	ans = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			ans.append(p)
	return ans

def primeFactors(n):
	factors = []
	while n % 2 == 0:
		factors.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			factors.append(i)
			n = n // i
	if n > 2:
		factors.append(n)
	return factors

def isPrime(n, k=5):
	if n < 2:
		return True
	for i in range(0, k):
		a = randint(1, n - 1)
		if pow(a, n - 1, n) != 1:
			return False
	return True

def find_closest(arr, target):
	min_diff = 1e+19
	low = 0
	high = len(arr) - 1
	closest_num = None
	if len(arr) == 0:
		return None
	if len(arr) == 1:
		return arr[0]
	while low <= high:
		mid = (low + high) // 2
		min_diff_left = 1e+19
		min_diff_right = 1e+19
		if mid + 1 < len(arr):
			min_diff_right = abs(arr[mid + 1] - target)
		if mid - 1 >= 0:
			min_diff_left = abs(arr[mid - 1] - target)
		if min_diff_left < min_diff:
			min_diff = min_diff_left
			closest_num = arr[mid - 1]
		if min_diff_right < min_diff:
			min_diff = min_diff_right
			closest_num = arr[mid + 1]
		if arr[mid] < target:
			low = mid + 1
		elif arr[mid] > target:
			high = mid - 1
		else:
			return arr[mid]
	return closest_num
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop, heapify
import string
for _ in range(int(input())):
	n = int(input())
	arr = []
	for i in range(n):
		arr.append(list(map(int, input().split())))

	def isPossible(day1, day2):
		d1 = set()
		d2 = set()
		for row in range(n):
			if arr[row][day1]:
				d1.add(row)
		for row in range(n):
			if arr[row][day2]:
				d2.add(row)
		if len(d1) < n // 2 or len(d2) < n // 2:
			return False
		return len(d1.union(d2)) == n
	flag = False
	for day1 in range(5):
		if flag:
			break
		for day2 in range(5):
			if day1 == day2:
				continue
			if isPossible(day1, day2):
				flag = True
				break
	if flag:
		print('YES')
	else:
		print('NO')


T = int(input())
for _ in range(T):
	n = int(input())
	students = []
	for _ in range(n):
		s = list(map(int, input().split(' ')))
		students.append(s)
	days = [0, 0, 0, 0, 0]
	for s in students:
		for x in range(5):
			days[x] += s[x]

	def check(d1, d2):
		n1 = 0
		n2 = 0
		n12 = 0
		for s in students:
			if s[d1] and s[d2]:
				n12 += 1
			elif s[d1]:
				n1 += 1
			elif s[d2]:
				n2 += 1
			else:
				return False
		if n12 + n1 + n2 != n:
			return False
		if max(n1, n2) - min(n1, n2) > n12:
			return False
		n12 -= max(n1, n2) - min(n1, n2)
		if n12 % 2:
			return False
		return True
	res = False
	while 1:
		if res:
			break
		top = max(days)
		topD = days.index(top)
		days[topD] = 0
		if top < n // 2:
			res = False
			break
		for d_i in range(5):
			d = days[d_i]
			if d < n // 2:
				days[d_i] = 0
			elif check(topD, d_i):
				res = True
				break
	if res:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	days = []
	for i in range(n):
		days.append(list(map(int, input().split())))
	found = False
	for i in range(5):
		a = set((k for (k, day) in enumerate(days) if day[i] == 1))
		for j in range(i + 1, 5):
			b = set((k for (k, day) in enumerate(days) if day[j] == 1))
			if len(a.union(b)) == n and len(a) >= n // 2 and (len(b) >= n // 2):
				print('YES')
				found = True
				break
		if found:
			break
	else:
		print('NO')


from os import path
from io import BytesIO, IOBase
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, Counter, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

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

def si():
	return input().rstrip()

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('0')
file = 1

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

def solve():
	for _ in range(1, ii() + 1):
		n = ii()
		a = []
		for i in range(n):
			a.append(li())
		ok = False
		if n & 1:
			print('NO')
			continue
		for i in range(5):
			for j in range(i + 1, 5):
				(cnt, cnt1) = (0, 0)
				cnt2 = 0
				for k in range(n):
					if a[k][i]:
						cnt += 1
					if a[k][j]:
						cnt1 += 1
					if a[k][i] and a[k][j]:
						cnt2 += 1
				if cnt > cnt1:
					(cnt, cnt1) = (cnt1, cnt)
				if cnt1 - cnt2 <= cnt and cnt + cnt1 - cnt2 == n:
					ok = True
					break
		print('YES' if ok else 'NO')
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


t = int(input())
for i in range(t):
	n = int(input())
	arr = []
	for i in range(n):
		y = [k for k in map(int, input().split())]
		arr.append(y)
	ok = False
	for x in range(5):
		for y in range(x + 1, 5):
			a = 0
			b = 0
			ab = 0
			for k in range(n):
				if arr[k][x] == 1 and arr[k][y] == 1:
					ab += 1
				elif arr[k][x] == 1:
					a += 1
				elif arr[k][y] == 1:
					b += 1
				else:
					break
			if a + ab + b == n and a + ab >= n / 2 and (b + ab >= n / 2):
				ok = True
	print('YES' if ok else 'NO')


t = int(input())
for _ in range(t):
	n = int(input())
	c = [list(map(int, input().split())) for _ in range(n)]
	ans = 'NO'
	for i in range(4):
		for j in range(i + 1, 5):
			p = [0] * 4
			for k in range(n):
				if c[k][i] == 1:
					if c[k][j] == 1:
						p[0] += 1
					else:
						p[1] += 1
				elif c[k][j] == 1:
					p[2] += 1
				else:
					p[3] += 1
			if p[3] > 0:
				continue
			if p[1] + p[0] < n // 2 or p[2] + p[0] < n // 2:
				continue
			ans = 'YES'
	print(ans)


for _ in range(int(input())):
	n = int(input())
	p = [(i, j) for i in range(5) for j in range(i + 1, 5)]
	students = []
	for i in range(n):
		a = list(map(int, input().split()))
		p = [(i, j) for (i, j) in p if a[i] or a[j]]
		students.append(a)
	for (i, j) in p:
		(only_i, only_j) = (0, 0)
		for a in students:
			if a[i] and (not a[j]):
				only_i += 1
			elif a[j] and (not a[i]):
				only_j += 1
		if only_j <= n // 2 and only_i <= n // 2:
			print('YES')
			break
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	check = False
	mat = [list(map(int, input().split())) for i in range(n)]
	for i in range(5):
		for j in range(i + 1, 5):
			stud = set()
			d1 = d2 = 0
			for k in range(n):
				if mat[k][i] == 1:
					d1 += 1
					stud.add(k)
				if mat[k][j] == 1:
					d2 += 1
					stud.add(k)
			if d1 >= n / 2 and d2 >= n / 2 and (len(stud) == n):
				check = True
				break
		if check:
			break
	if check:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	p = []
	for _ in range(n):
		week = input().split()
		p.append(week)
	possible = False
	for d1 in range(4):
		if possible:
			break
		for d2 in range(d1 + 1, 5):
			cnt_d1 = 0
			cnt_d2 = 0
			cnt_d12 = 0
			skip = False
			for week in p:
				if week[d1] == week[d2] == '1':
					cnt_d12 += 1
				elif week[d1] == '1':
					cnt_d1 += 1
				elif week[d2] == '1':
					cnt_d2 += 1
				else:
					skip = True
			if skip:
				continue
			if cnt_d1 <= n // 2 and cnt_d2 <= n // 2:
				possible = True
	if possible:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	g = [list(map(int, input().split())) for _ in range(n)]
	if n % 2:
		print('NO')
	else:

		def go():
			for i in range(5):
				for j in range(i + 1, 5):
					(a, b, c) = (0, 0, 0)
					for x in range(n):
						if g[x][i] and g[x][j]:
							c += 1
						elif g[x][i]:
							a += 1
						elif g[x][j]:
							b += 1
						else:
							break
					else:
						if a <= n // 2 and b <= n // 2:
							return 'YES'
			return 'NO'
		print(go())


for _ in range(int(input())):
	n = int(input())
	a = list()
	f = False
	for i in range(n):
		a.append(list(map(int, input().split())))
	for i in range(5):
		for j in range(i + 1, 5):
			p = q = r = 0
			for k in range(n):
				p += a[k][i] == 1
				q += a[k][j] == 1
				r += a[k][j] == 1 and a[k][i] == 1
			p -= r
			q -= r
			if p <= n // 2 and q <= n // 2 and (p + q + r == n):
				f = True
	print('YES' if f else 'NO')


from collections import defaultdict

def result(a1, n):
	list_len = []
	ab = defaultdict(set)
	for i in range(5):
		for j in range(n):
			if a1[j][i] == 1:
				ab[i].add(j)
	for i in range(5):
		if len(ab[i]) >= n // 2:
			list_len.append(i)
	for i in range(len(list_len)):
		for j in range(i + 1, len(list_len)):
			t = ab[list_len[i]].union(ab[list_len[j]])
			if len(t) == n:
				print('YES')
				return
	print('NO')
for i in range(int(input())):
	a1 = []
	ab = int(input())
	for j in range(ab):
		a1.append(list(map(int, input().split())))
	result(a1, ab)


from itertools import combinations
combs = list(combinations(range(5), r=2))
t = int(input())
for _ in range(t):
	n = int(input())
	a = [list(map(int, input().split())) for _ in range(n)]
	a = list(zip(*a))
	totalFail = True
	for c in combs:
		failed = False
		cnt0 = sum(a[c[0]])
		cnt1 = sum(a[c[1]])
		for (p0, p1) in zip(a[c[0]], a[c[1]]):
			if p0 + p1 == 0:
				failed = True
				break
		if failed or cnt0 < n // 2 or cnt1 < n // 2:
			continue
		totalFail = False
		break
	if totalFail:
		print('NO')
	else:
		print('YES')


cases = int(input())
for _ in range(cases):
	matrix = []
	num = int(input())
	for i in range(num):
		arr = list(map(int, input().split()))
		matrix.append(arr)
	new_mat = [list(x) for x in zip(*matrix)]
	sets = []
	md = num // 2
	for row in new_mat:
		st = set((i for (i, num) in enumerate(row, start=1) if num == 1))
		if len(st) >= md:
			sets.append(st)
	broken = False
	if len(sets) < 2:
		print('NO')
		continue
	for (i, s) in enumerate(sets):
		for (j, s2) in enumerate(sets):
			if i != j:
				newst = s.union(s2)
				if len(newst) == num and len(s) >= md and (len(s2) >= md):
					print('YES')
					broken = True
					break
		if broken:
			break
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	d = {'M': [], 'T': [], 'W': [], 'Th': [], 'F': []}
	for i in range(n):
		(m, t, w, th, f) = map(int, input().split())
		if m == 1:
			d['M'].append(i + 1)
		if t == 1:
			d['T'].append(i + 1)
		if w == 1:
			d['W'].append(i + 1)
		if th == 1:
			d['Th'].append(i + 1)
		if f == 1:
			d['F'].append(i + 1)
	if n % 2 != 0:
		print('NO')
	else:
		l = []
		for x in d:
			if len(d[x]) >= n // 2:
				l.append(x)
		if len(l) == 1 or len(l) == 0:
			print('NO')
		else:
			f = 0
			for i in range(len(l) - 1):
				for j in range(i + 1, len(l)):
					u = set(d[l[i]]).union(set(d[l[j]]))
					if len(u) == n:
						f = 1
						print('YES')
						break
				if f == 1:
					break
			if f == 0:
				print('NO')


import sys
from collections import deque
import heapq
import bisect
import copy
MOD = 1000000007
NO = lambda : print('NO')
YES = lambda : print('YES')
_1 = lambda : print(-1)
ari = lambda : [int(_) for _ in input().split()]
cin = lambda : int(input())
cis = lambda : input()
show = lambda x: print(x)
test_case = 1
test_case = int(input())
sys.setrecursionlimit(10 ** 6)

def ans():
	n = cin()
	arr = []
	for i in range(n):
		arr.append(cis().split())
	for i in range(5):
		for j in range(5):
			if i != j:
				cnt1 = 0
				cnt2 = 0
				cntno = 0
				for k in range(n):
					if arr[k][j] == '1':
						cnt1 += 1
					if arr[k][i] == '1':
						cnt2 += 1
					if arr[k][i] == '0' and arr[k][j] == '0':
						cntno += 1
				if cnt1 >= n // 2 and cnt2 >= n // 2 and (cntno == 0):
					print('YES')
					return
	print('NO')
	return
for _ in range(test_case):
	ans()


def intersection(lst1, lst2, n):
	com = 0
	for i in range(n):
		com += lst1[i] & lst2[i]
	return com
t = int(input())
for _ in range(t):
	n = int(input())
	days = [[], [], [], [], []]
	for i in range(n):
		lst = list(map(int, input().split()))
		for i in range(5):
			days[i].append(lst[i])
	lstTot = []
	i = 0
	while i < len(days):
		tot = sum(days[i])
		if tot < n / 2:
			days.pop(i)
		else:
			lstTot.append(tot)
			i += 1
	flag = False
	if len(days) > 1:
		for i in range(len(days)):
			for j in range(i + 1, len(days)):
				common = intersection(days[i], days[j], n)
				if lstTot[i] + lstTot[j] - common >= n:
					flag = True
			if flag == True:
				break
	if flag:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	matrix = []
	for i in range(n):
		matrix.append(list(map(int, input().split())))
	bothday = []
	for i in range(6):
		for j in range(i + 1, 5):
			bothday.append([i, j])
	found = False
	for (i, j) in bothday:
		ci = 0
		cj = 0
		cnot = 0
		for s in range(n):
			ci += matrix[s][i]
			cj += matrix[s][j]
			if matrix[s][j] == 0 and matrix[s][i] == 0:
				cnot += 1
		if ci >= n // 2 and cj >= n // 2 and (cnot == 0):
			found = True
			break
	if found:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	data = []
	for i in range(n):
		data.append(list(map(int, input().split())))
	ok = False
	for d1 in range(5):
		for d2 in range(d1 + 1, 5):
			both = 0
			only_1 = 0
			only_2 = 0
			for i in data:
				if i[d1] == 1 and i[d2] == 1:
					both += 1
				elif i[d1] == 1:
					only_1 += 1
				elif i[d2] == 1:
					only_2 += 1
			to_add = min(both, max(0, n // 2 - only_1))
			only_1 += to_add
			both -= to_add
			only_2 += both
			if only_1 >= n // 2 and only_2 >= n // 2:
				ok = True
	if ok:
		print('YES')
	else:
		print('NO')


def solve(n, prefs):
	h = n // 2
	for d1 in range(5):
		for d2 in range(d1 + 1, 5):
			d1c = 0
			d2c = 0
			both = 0
			for p in prefs:
				if p[d1] == 1 and p[d2] == 1:
					both += 1
				elif p[d1] == 1:
					d1c += 1
				elif p[d2] == 1:
					d2c += 1
			if d1c > h or d2c > h:
				continue
			if d1c == h and d2c == h:
				return 'YES'
			rem = n - d1c - d2c
			if both >= rem:
				return 'YES'
	return 'NO'
t = int(input().strip())
inputs = []
for _ in range(t):
	n = int(input().strip())
	prefs = []
	for _ in range(n):
		p = list(map(int, input().strip().split()))
		prefs.append(p)
	inputs.append((n, prefs))
for (n, prefs) in inputs:
	print(solve(n, prefs))


def main():
	n = int(input())
	arr = []
	for _ in range(n):
		arr.append(list(map(int, input().split())))
	day = [set() for _ in range(5)]
	for i in range(5):
		for j in range(n):
			if arr[j][i] == 1:
				day[i].add(j)
	day2 = []
	for i in range(len(day)):
		if len(day[i]) >= n / 2:
			day2.append(day[i])
	day = day2
	for i in range(len(day)):
		for j in range(i + 1, len(day)):
			if len(day[i].union(day[j])) == n:
				print('YES')
				return
	print('NO')
t = int(input())
for _ in range(t):
	main()


for _ in range(int(input())):
	n = int(input())
	arr = []
	for x in range(n):
		temp = input().split()
		arr.append(temp)
	dicti = {}
	dicti[0] = set()
	dicti[1] = set()
	dicti[2] = set()
	dicti[3] = set()
	dicti[4] = set()
	for i in range(len(arr)):
		for j in range(len(arr[i])):
			if arr[i][j] == '1':
				dicti[j].add(i)
	keys = []
	for i in dicti:
		if len(dicti[i]) >= n // 2:
			keys.append(i)
	flag = 0
	for i in range(len(keys)):
		for j in range(i + 1, len(keys)):
			lol = dicti[keys[i]].intersection(dicti[keys[j]])
			temp1 = n // 2 - (len(dicti[keys[i]]) - len(lol))
			temp2 = n // 2 - (len(dicti[keys[j]]) - len(lol))
			if temp1 + temp2 == len(lol):
				flag = 1
				break
	if flag == 1:
		print('YES')
	else:
		print('NO')


def solve():
	n = int(input())
	students = [[] for _ in range(n)]
	for i in range(n):
		students[i] = list(map(int, input().split()))
	days = [set() for _ in range(5)]
	for student_idx in range(n):
		for day in range(5):
			if students[student_idx][day]:
				days[day].add(student_idx)
	for day1 in range(5):
		students_available_day_1 = days[day1]
		if not students_available_day_1:
			continue
		for day2 in range(day1 + 1, 5):
			students_available_day_2 = days[day2]
			if not students_available_day_2:
				continue
			if len(students_available_day_1) >= n // 2 and len(students_available_day_2) >= n // 2 and (len(students_available_day_1 | students_available_day_2) == n):
				return True
	return False
for i in range(int(input())):
	if solve():
		print('YES')
	else:
		print('NO')


import math
from sys import stdin
input = stdin.readline
test = int(input())
for _ in range(test):
	(n, arr, result) = (int(input()), [], True)
	arr = [set() for _ in range(5)]
	for j in range(n):
		data = list(map(int, input().split()))
		for i in range(5):
			if data[i]:
				arr[i].add(j)
	if n % 2 == 1:
		print('NO')
		continue
	result = False
	for i in range(5):
		a = len(arr[i])
		if a < n // 2 or result:
			continue
		for j in range(i + 1, 5):
			b = len(arr[j])
			if b < n // 2:
				continue
			union = len(arr[i].union(arr[j]))
			if union == n:
				result = True
	if result:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	days = []
	d = {i: set() for i in range(5)}
	for _1 in range(n):
		a = map(int, input().split())
		for (i, v) in enumerate(a):
			if v == 1:
				d[i].add(_1)
	isFound = False
	for i in range(5):
		for j in range(i + 1, 5):
			if len(d[j]) >= n // 2 and len(d[i]) >= n // 2 and (len(d[i].union(d[j])) == n):
				print('YES')
				isFound = True
				break
		if isFound:
			break
	else:
		print('NO')


def solve():
	n = int(input())
	a = [list(map(int, input().split())) for _ in range(n)]
	for i in range(4):
		for j in range(i + 1, 5):
			cnt = 0
			day1 = 0
			day2 = 0
			bo = 1
			for stu in range(n):
				if a[stu][i] == 0 and a[stu][j] == 0:
					bo = 0
					break
				elif a[stu][i] == 1 and a[stu][j] == 1:
					cnt += 1
				elif a[stu][i] == 1:
					day1 += 1
				elif a[stu][j] == 1:
					day2 += 1
			if day1 <= n // 2 and day2 <= n // 2 and bo:
				return 'YES'
	return 'NO'

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


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	l = []
	for x in range(n):
		l1 = [int(x) for x in input().split()]
		l.append(l1)
	for x in range(5):
		for y in range(5):
			if x != y:
				(g1, g2, gb) = (0, 0, 0)
				for z in range(n):
					if l[z][x] and l[z][y]:
						gb += 1
					elif l[z][x]:
						g1 += 1
					elif l[z][y]:
						g2 += 1
				g1 = n // 2 - g1
				g2 = n // 2 - g2
				if g1 >= 0 and g2 >= 0 and (g1 + g2 == gb):
					return 1
	return 0
_ = 1
_ = int(input())
while _ > 0:
	_ -= 1
	print('YES' if solve() else 'NO')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	w = [input()[:-1].split() for _ in range(n)]
	w = [''.join(i) for i in zip(*w) if i.count('1') >= n // 2]
	x = len(w)
	ans = 'NO'
	for i in range(x):
		for j in range(i + 1, x):
			if bin(int('0b' + w[i], 2) | int('0b' + w[j], 2)) == '0b' + '1' * n:
				ans = 'YES'
				break
		if ans == 'YES':
			break
	print(ans)


q = int(input())
for i in range(q):
	n = int(input())
	a = [list(map(int, input().split())) for i in range(n)]
	cal = [0, 0, 0, 0, 0]
	for i in range(len(a)):
		for j in range(len(a[0])):
			if a[i][j] == 1:
				cal[j] += 1
	possible = [True, True, True, True, True]
	for i in range(5):
		if cal[i] * 2 < n:
			possible[i] = False
	if possible.count(True) <= 1:
		print('NO')
		continue
	tag = True
	for i in range(5):
		if not possible[i]:
			continue
		for j in range(i + 1, 5):
			if not possible[j]:
				continue
			tag = True
			for k in range(n):
				if a[k][i] + a[k][j] == 0:
					tag = False
					break
			if tag:
				break
		if tag:
			break
	if tag:
		print('YES')
	else:
		print('NO')


t = int(input())
for test_case in range(t):
	n = int(input())
	pairs = []
	for a in range(4):
		for b in range(a + 1, 5):
			pairs.append((a, b))
	tallies = []
	for c in range(10):
		tallies.append([[0, 0], [0, 0]])
	for i in range(n):
		line = str(input()).split()
		line = list(map(int, line))
		for c in range(10):
			p = pairs[c]
			(i, j) = (p[0], p[1])
			(x, y) = (line[i], line[j])
			tallies[c][x][y] += 1
	flag = False
	half = n // 2
	for c in range(10):
		tally = tallies[c]
		if tally[0][0] == 0 and tally[0][1] <= half and (tally[1][0] <= half):
			flag = True
			break
	if flag:
		print('YES')
	else:
		print('NO')


def fun(n, ls):
	for i in range(5):
		for j in range(i + 1, 5):
			prefer_i = 0
			prefer_j = 0
			both = 0
			for k in range(n):
				val1 = ls[k][i]
				val2 = ls[k][j]
				if val1 == 1 and val2 == 1:
					both += 1
					continue
				if val1 == 1:
					prefer_i += 1
					continue
				if val2 == 1:
					prefer_j += 1
			if prefer_j == prefer_i and prefer_i >= n // 2:
				print('YES')
				return
			maxx = max(prefer_j, prefer_i)
			minn = min(prefer_j, prefer_i)
			extra = maxx - minn
			if both >= extra:
				both -= extra
				minn += extra
				if both % 2 == 0:
					if maxx + both // 2 >= n // 2 and minn + both // 2 >= n // 2:
						print('YES')
						return
	print('NO')
	return
T = int(input())
for _ in range(T):
	n = int(input())
	ls = []
	for _ in range(n):
		lt = list(map(int, input().split()))
		ls.append(lt)
	fun(n, ls)


for _ in range(int(input())):
	n = int(input())
	a = [0] * n
	ok = False
	for i in range(n):
		a[i] = [int(x) for x in input().split(' ')]
	for i in range(5):
		for j in range(i + 1, 5):
			ok = True
			coui = 0
			couj = 0
			for k in range(n):
				if a[k][i] == 1 and a[k][j] == 0:
					coui += 1
				elif a[k][i] == 0 and a[k][j] == 1:
					couj += 1
				elif a[k][i] == 0 and a[k][j] == 0:
					ok = False
					break
			if coui > n / 2 or couj > n / 2:
				ok = False
			if ok:
				break
		if ok:
			break
	if ok:
		print('YES')
	else:
		print('NO')


def getResult(grid):
	sum_map = {}
	for (id, ln) in enumerate(list(zip(*grid))):
		sum_map[id] = ln
	for x in range(5):
		for y in range(x + 1, 5):
			sx = sum_map[x]
			sy = sum_map[y]
			if sum(sx) < n // 2 or sum(sy) < n // 2:
				continue
			sx_set = [(id, val) for (id, val) in enumerate(sx)]
			sx_set = [x[0] for x in filter(lambda x: x[1] == 1, sx_set)]
			sy_set = [(id, val) for (id, val) in enumerate(sy)]
			sy_set = [x[0] for x in filter(lambda x: x[1] == 1, sy_set)]
			if len(set(sx_set + sy_set)) == n:
				return True
	return False
t = int(input())
for _ in range(t):
	n = int(input())
	grid = []
	for ln in range(n):
		row = input()
		grid.append([int(x) for x in row.split()])
	if getResult(grid):
		print('YES')
	else:
		print('NO')


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from collections import Counter
from collections import defaultdict as dd
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
stdmap = lambda : map(int, stdstr().split())
stdarr = lambda : list(map(int, stdstr().split()))
mod = 1000000007
for _ in range(stdint()):
	n = stdint()
	attend = []
	c = Counter()
	for i in range(n):
		x = stdarr()
		attend.append(x)
		for j in range(5):
			if x[j] == 1:
				c[j] += 1
	pos = False
	for i in range(5):
		for j in range(i + 1, 5):
			chosen = [False] * n
			for k in range(n):
				if attend[k][i] == 1:
					chosen[k] = True
				if attend[k][j] == 1:
					chosen[k] = True
			g1 = c[i]
			g2 = c[j]
			if g1 >= n // 2 and g2 >= n // 2 and (chosen.count(True) == n):
				pos = True
				break
		if pos:
			break
	if pos:
		print('YES')
	else:
		print('NO')


import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def solve(x, y):
	one = []
	two = []
	both = []
	flag = 0
	for i in range(n):
		if a[i][x] == 1 and a[i][y] == 1:
			both.append(i)
		elif a[i][x] == 1:
			one.append(i)
		elif a[i][y] == 1:
			two.append(i)
		else:
			flag = 1
			break
	if len(one) > n // 2 or len(two) > n // 2:
		return 0
	if flag:
		return 0
	return 1
for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		curr = [int(i) for i in input().split()]
		a.append(curr)
	flag = 0
	for i in range(5):
		for j in range(i + 1, 5):
			if solve(i, j):
				flag = 1
				break
		if flag:
			break
	if flag:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

def check(x, y, z):
	num1 = 0
	num2 = 0
	k = len(z)
	for i in range(k):
		if z[i][x] == 0 and z[i][y] == 0:
			return False
		num1 += z[i][x]
		num2 += z[i][y]
	return num1 >= k / 2 and num2 >= k / 2
T = int(input())
for t in range(T):
	n = int(input())
	if n % 2 == 1:
		print('NO')
	a = []
	for i in range(n):
		b = list(map(int, input().strip().split()))
		a.append(b)
	ans = 'NO'
	for day1 in range(4):
		for day2 in range(day1 + 1, 5):
			if check(day1, day2, a):
				ans = 'YES'
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = [[] for _ in range(5)]
	for id in range(n):
		for (i, c) in enumerate(input().split()):
			if c == '1':
				s[i].append(id)
	f = 0
	for i in range(5):
		if f:
			break
		for j in range(i + 1, 5):
			s1 = set(s[i])
			s2 = set(s[j])
			if len(s1) >= n // 2 and len(s2) >= n // 2:
				l = len(s1.intersection(s2))
				d1 = 0 if len(s1) - l >= n // 2 else len(s1) - l - n // 2
				d2 = 0 if len(s2) - l >= n // 2 else len(s2) - l - n // 2
				if d1 + d2 + l >= 0:
					f = 1
					break
	if f:
		print('YES')
	else:
		print('NO')


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	li = []
	for i in range(n):
		t = list(map(int, input().split()))
		li.append(t)
	ans = []
	for i in range(5):
		r = []
		for j in range(n):
			if li[j][i] == 1:
				r.append(j)
		if r != []:
			ans.append(r)
	f = 0
	for i in range(len(ans)):
		for j in range(len(ans)):
			if i != j:
				if len(list(set(ans[i] + ans[j]))) == n and len(ans[i]) >= n // 2 and (len(ans[j]) >= n // 2):
					f = 1
					break
	if f == 1:
		print('YES')
	else:
		print('NO')


def groups(matrix, n):
	d = [[] for x in range(5)]
	for x in range(n):
		for y in range(5):
			if matrix[x][y] == 1:
				d[y].append(x)
	density = []
	for x in range(5):
		if len(d[x]) >= n / 2:
			density.append(d[x])
	if len(density) <= 1:
		return False
	for i in range(len(density)):
		for j in range(i + 1, len(density)):
			temp = set(density[i] + density[j])
			if len(temp) == n:
				return True
	return False
t = int(input())
final = []
for _ in range(t):
	n = int(input())
	matrix = []
	for x in range(n):
		matrix.append(list(map(int, input().split())))
	ans = groups(matrix, n)
	final.append(ans)
for _ in range(t):
	if final[_] == True:
		print('YES')
	else:
		print('NO')


def count():
	for i in range(4):
		for j in range(i + 1, 5):
			b = set()
			for k in range(len(u[i])):
				b.add(u[i][k])
			for k in range(len(u[j])):
				b.add(u[j][k])
			if len(b) == n and len(u[i]) >= n / 2 and (len(u[j]) >= n / 2):
				print('YES')
				return
	print('NO')
for _ in range(int(input())):
	n = int(input())
	a = []
	u = [[] for i in range(5)]
	for i in range(n):
		a = list(map(int, input().split()))
		for j in range(5):
			if a[j]:
				u[j].append(i)
	count()


t = int(input())
for i in range(t):
	n = int(input())
	etudiants = []
	for i in range(n):
		raw = input().split()
		etudiant = []
		for jour in raw:
			etudiant.append(int(jour))
		etudiants.append(etudiant)
	jours = ['lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi']
	dispo = {day: [] for day in jours}
	indispo = {day: [] for day in jours}
	indice = 0
	for key in dispo:
		for i in range(n):
			if etudiants[i][indice] == 1:
				dispo[key].append(i)
		indice += 1
	jours_possible = []
	for key in dispo:
		if len(dispo[key]) >= n / 2:
			jours_possible.append(key)
	res = 'NO'
	for key in jours_possible:
		for i in range(n):
			if i not in dispo[key]:
				indispo[key].append(i)
		for key2 in jours_possible:
			test = True
			for el in indispo[key]:
				if el not in dispo[key2]:
					test = False
			if key2 != key and test == True:
				res = 'YES'
				break
	print(res)


for _ in range(int(input())):
	n = int(input())
	d = [set(), set(), set(), set(), set()]
	for i in range(n):
		g = input().split()
		for j in range(5):
			if g[j] == '1':
				d[j].add(i)
	bl = False
	for i in range(5):
		for j in range(i + 1, 5):
			if not bl and len(d[i].union(d[j])) == n and (len(d[i]) >= n // 2) and (len(d[j]) >= n // 2):
				bl = True
	print('YES' if bl else 'NO')


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

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())):
	n = int(input())
	arr = []
	for i in range(n):
		a = get_array()
		arr.append(a)
	only = [0] * 5
	both = [[0 for i in range(5)] for j in range(5)]
	for i in range(5):
		for j in range(n):
			only[i] += arr[j][i]
	for i in range(5):
		for j in range(i + 1, 5):
			for k in range(n):
				if arr[k][i] == 1 and arr[k][j] == 1:
					both[i][j] += 1
	req = n // 2
	flag = False
	for i in range(5):
		for j in range(i + 1, 5):
			onlyi = only[i] - both[i][j]
			onlyj = only[j] - both[i][j]
			if onlyi <= req and onlyj <= req:
				req1 = req - onlyi
				req2 = req - onlyj
				if req1 + req2 == both[i][j]:
					flag = True
					break
		if flag == True:
			break
	if flag == True:
		print('YES')
	else:
		print('NO')


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, defaultdict
from pprint import pprint
from itertools import permutations
from bisect import bisect_right
import heapq
mod = 10 ** 9 + 7

def main():
	n = int(input())
	arr = []
	for i in range(n):
		arr.append(list(map(int, input().split())))
	for i in range(5):
		for j in range(i + 1, 5):
			x = n // 2
			y = n // 2
			cnt = 0
			for k in range(n):
				if arr[k][i] == 1 and arr[k][j] == 0:
					x -= 1
				elif arr[k][i] == 0 and arr[k][j] == 1:
					y -= 1
				elif arr[k][i] == 1 and arr[k][j] == 1:
					cnt += 1
			if x >= 0 and y >= 0 and (cnt == x + y):
				print('YES')
				return
	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')
(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 i in range(t):
	n = int(input())
	a = []
	for j in range(n):
		a.append(list(map(int, input().split())))
	ans = False
	for j in range(5):
		for k in range(5):
			if k != j:
				c1 = 0
				c2 = 0
				count = 0
				for z in range(n):
					if a[z][j] == 1:
						c1 += 1
					if a[z][k] == 1:
						c2 += 1
					if a[z][j] == 0 and a[z][k] == 0:
						count += 1
				if c1 >= int(n / 2) and c2 >= int(n / 2) and (count == 0):
					ans = True
	if ans:
		print('YES')
	else:
		print('NO')


import math
import os
import random
import re
import sys

def solve():
	n = int(input())
	mappings = {}
	for i in range(1, 6):
		mappings[i] = set()
	for i in range(n):
		all_inputs = input()
		all_inputs = [int(val) for val in all_inputs.split(' ')]
		for j in range(1, 6):
			if all_inputs[j - 1] == 1:
				mappings[j].add(i)
	for i in range(1, 5):
		if len(mappings[i]) < n / 2:
			continue
		for j in range(i + 1, 6):
			if len(mappings[j]) < n / 2:
				continue
			dup = len(mappings[i].intersection(mappings[j]))
			if len(mappings[i]) + len(mappings[j]) - dup == n:
				print('YES')
				return
	print('NO')
t = int(input())
for i in range(t):
	solve()


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
inp_vars_int = lambda : map(int, input().split())
inp_list_int = lambda : list(map(int, input().split()))
t = int(input())
for _ in range(t):
	n = int(input())
	days = {d: set() for d in range(5)}
	for i in range(n):
		st = inp_list_int()
		for (j, d) in enumerate(st):
			if d == 1:
				days[j].add(i)
	res = False
	for i in range(5):
		for j in range(i + 1, 5):
			if len(days[i]) >= n // 2 and len(days[j]) >= n // 2:
				if len(days[i].union(days[j])) == n:
					res = True
					break
	print('YES' if res else 'NO')


def solve():
	n = int(input())
	d = [set() for _ in range(5)]
	for i in range(n):
		inp = input().split(' ')
		for j in range(5):
			if inp[j] == '1':
				d[j].add(i + 1)
	d = list(filter(lambda x: True if len(x) >= n // 2 else False, d))
	if len(d) < 2:
		return 'NO'
	for i in range(len(d)):
		for j in range(len(d)):
			if i != j and len(d[j].union(d[i])) == n:
				return 'YES'
	return 'NO'
for _ in range(int(input())):
	print(solve())


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	arr = []
	f = 0
	for i in range(0, n):
		temp = list(map(int, input().split()))
		arr.append(temp)
	for i in range(0, 5):
		for j in range(i + 1, 5):
			ctr = 0
			temp = 0
			h = 0
			res = 0
			for k in range(0, n):
				if arr[k][i] == 1:
					h += 1
					ctr += 1
				if arr[k][j] == 1:
					h += 1
					temp += 1
				if arr[k][j] == 1 and arr[k][i] == 1:
					h += 1
					res += 1
			ctr = ctr - res
			temp = temp - res
			if ctr <= int(n / 2) and temp <= int(n / 2) and (ctr + temp + res == n):
				f = 1
				break
	if f == 0:
		print('NO')
	else:
		print('YES')


from sys import stdin, stdout

def INPUT():
	return list((int(i) for i in stdin.readline().split()))

def inp():
	return stdin.readline()

def out(x):
	return stdout.write(x)
from math import *
from decimal import *
INT_MAX = 10 ** 13
from bisect import bisect_left
import sys
MOD = 10 ** 9 + 7
from random import randint as R
inf = 12345676543
from collections import deque
from sys import setrecursionlimit

def sec(a, b):
	n = len(a)
	if sum(a) >= n // 2 and sum(b) >= n // 2:
		for i in range(n):
			if a[i] == b[i] == 0:
				return False
		return True
	return False
for _ in range(int(input())):
	n = int(input())
	A = []
	for _ in range(n):
		A.append(INPUT())
	count = [0] * 5
	for i in range(5):
		a = 0
		for j in range(n):
			a += A[j][i]
		count[i] = a
	ans = False
	for i in range(5):
		for j in range(i + 1, 5):
			x = []
			y = []
			for k in range(n):
				x.append(A[k][i])
				y.append(A[k][j])
			if sec(x, y) == True:
				ans = True
	if ans:
		print('YES')
	else:
		print('NO')


import traceback
import os
import sys
from io import BytesIO, IOBase
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 = IOWrapper(sys.stdin)
input = lambda : sys.stdin.readline().rstrip('\r\n')

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))
import math
from collections import defaultdict as dfd, defaultdict, Counter, deque
from functools import lru_cache
from itertools import accumulate
from heapq import *
import bisect

def geti():
	return int(input())

def gets():
	return input()

def getil():
	return list(map(int, input().split()))

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

def getinps(s):
	inps = s.split()
	m = {'i': geti, 's': gets, 'il': getil, 'sl': getsl}
	if len(inps) == 1:
		return m[s]()
	return [m[k]() for k in inps]

def get2d(nrows, ncols, n=0):
	return [[n] * ncols for r in range(nrows)]

def get_acc(a):
	return list(accumulate(a))

def get_ncr(n, r, mod=10 ** 9 + 7):
	num = den = 1
	r = min(r, n - r)
	for i in range(r):
		num = num * (n - i) % mod
		den = den * (i + 1) % mod
	return num * pow(den, mod - 2, mod) % mod

def get_nc2(n):
	return n * (n - 1) // 2

def get_npr(n, r):
	if n < r:
		return 0
	return math.factorial(n) // math.factorial(r)

def put(a):
	return ' '.join(map(str, a))
ALPHABETS = 'abcdefghijklmnopqrstuvwxyz'
VOWELS = 'aeiou'
CONSONANTS = 'bcdfghjklmnpqrstvwxyz'
inf = float('inf')
mod = 10 ** 9 + 7

class Solution:

	def main(self):
		(N,) = getil()
		M = N // 2
		grid = [[0] * N for _ in range(5)]
		for i in range(N):
			a = getil()
			for j in range(5):
				grid[j][i] = a[j]
		D = 5
		for l in range(D - 1):
			for r in range(l + 1, D):
				(x, y, z) = (0, 0, 0)
				for i in range(N):
					if grid[l][i] == grid[r][i] == 1:
						z += 1
					elif grid[l][i]:
						x += 1
					elif grid[r][i]:
						y += 1
				(kl, kr) = (max(0, M - x), max(0, M - y))
				if kl + kr <= z:
					return True
		return False
try:
	Sol = Solution()
	Test = geti()
	for Case in range(Test):
		ans = Sol.main()
		if ans is not None:
			ans = 'YES' if ans else 'NO'
			print(ans)
except Exception as e:
	print(e)
	traceback.print_exc()


for _ in range(int(input())):
	n = int(input())
	arr = list()
	for i in range(n):
		arr.append(list(map(int, input().split())))
	pos = False
	for i in range(4):
		for j in range(i + 1, 5):
			if pos:
				break
			a = 0
			b = 0
			c = 0
			for k in range(n):
				if arr[k][i] == 1:
					a += 1
				if arr[k][j] == 1:
					b += 1
				if arr[k][i] == 1 and arr[k][j] == 1:
					c += 1
			if a + b - c == n and a >= n // 2 and (b >= n // 2):
				print('YES')
				pos = True
	if pos == False:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	l = []
	for i in range(n):
		l.append(list(map(int, input().split())))
	at = set()
	if n % 2 != 0:
		print('NO')
		continue
	ansf = 0
	for i in range(5):
		for j in range(i + 1, 5):
			(tp1, tp2) = (0, 0)
			f = 0
			for k in range(n):
				if l[k][i] == 0 and l[k][j] == 0:
					f = 1
					break
				tp1 += l[k][i]
				tp2 += l[k][j]
			if f == 1:
				continue
			elif tp1 >= n // 2 and tp2 >= n // 2:
				ansf = 1
				break
		if ansf == 1:
			break
	if ansf == 1:
		print('YES')
	else:
		print('NO')


from sys import stdin

def read_input():
	n = int(stdin.readline())
	g = []
	for _ in range(n):
		g.append(list(map(int, stdin.readline().split())))
	return (n, g)

def solve(n, g):
	for day1 in range(5):
		for day2 in range(5):
			if day1 != day2:
				(a, b, c) = (0, 0, 0)
				for h in g:
					if h[day1] == 1 and h[day2] == 1:
						c += 1
					elif h[day1] == 1:
						a += 1
					elif h[day2] == 1:
						b += 1
				if a + b + c == n and a + c >= n // 2 and (b + c >= n // 2):
					return 'YES'
	return 'NO'

def main():
	t = int(stdin.readline())
	for _ in range(t):
		input = read_input()
		answer = solve(*input)
		print(answer)
main()


def pr(ned):
	for i in range(5):
		for j in range(i + 1, 5):
			f = len(ned[i].intersection(ned[j]))
			nx = len(ned[i]) - f
			ny = len(ned[j]) - f
			if f + nx + ny == n:
				raz = abs(nx - ny)
				if f >= raz and (f - raz) % 2 == 0:
					return 'YES'
	return 'NO'
for _ in range(int(input())):
	n = int(input())
	sete = [[int(i) for i in input().split()] for _ in range(n)]
	ned = {}
	for i in range(5):
		ned[i] = set()
		for j in range(n):
			if sete[j][i] == 1:
				ned[i].add(j)
	print(pr(ned))


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

def main():

	def solve():
		n = int(input())
		arr = []
		for i in range(n):
			s = list(map(int, input().split()))
			arr.append(s)
		for i in range(5):
			for j in range(i + 1, 5):
				c1 = 0
				c2 = 0
				c3 = 0
				for k in range(n):
					if arr[k][i] == 1:
						c1 += 1
					if arr[k][j] == 1:
						c2 += 1
					if arr[k][j] == 1 and arr[k][i] == 1:
						c3 += 1
				c1 -= c3
				c2 -= c3
				if c1 <= n / 2 and c2 <= n / 2 and (c1 + c2 + c3 == n):
					return 'YES'
		return 'NO'
	t = int(input())
	for i in range(t):
		print(solve())
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()


n = int(input())
respostas = []
for x in range(n):
	m = int(input())
	flag = False
	dias = [[], [], [], [], []]
	for z in range(m):
		aluno = input().split(' ')
		for k in range(5):
			if aluno[k] == '1':
				dias[k].append(z)
	metade = m / 2
	pos = []
	for p in range(5):
		if len(dias[p]) >= metade:
			pos.append(dias[p])
	for t in range(len(pos) - 1):
		dia1 = pos[t]
		for r in range(t + 1, len(pos)):
			dia2 = pos[r]
			common = list(set(dia1).intersection(dia2))
			rest1 = list(set(dia1) ^ set(common))
			rest2 = list(set(dia2) ^ set(common))
			if len(rest1) + len(rest2) + len(common) == m:
				flag = True
				break
		if flag:
			break
	if flag:
		respostas.append('YES')
	else:
		respostas.append('NO')
for y in range(n):
	print(respostas[y])


t = int(input())
for ti in range(t):
	l = int(input())
	ss = []
	ds = [[] for _ in range(5)]
	for si in range(l):
		rd = [int(x) for x in input().split()]
		ss.append(rd)
		[ds[i].append(c) for (i, c) in enumerate(rd)]

	def test(ss, ds):
		ssum = [sum((s[i] for s in ss)) for i in range(5)]
		for i1 in range(5):
			if ssum[i1] < l // 2:
				continue
			for i2 in range(i1 + 1, 5):
				if ssum[i2] < l // 2:
					continue
				for (a, b) in zip(ds[i1], ds[i2]):
					if a == 0 and b == 0:
						break
				else:
					return True
		return False
	print('YES' if test(ss, ds) else 'NO')


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def input_list():
	return list(map(int, input().split()))

def input_string():
	s = input()
	return list(s[:len(s) - 1])

def input_int_gen():
	return map(int, input().split())
tests = inp()
for _ in range(tests):
	n = inp()
	k = {0: 0, 1: 0, 2: 0, 3: 0, 4: 0}
	l = []
	for _ in range(n):
		a = input_list()
		l.append(a)
	flag = False
	for i in range(4):
		for j in range(i + 1, 5):
			(ii, jj, ij) = (0, 0, 0)
			for a in l:
				if a[i] and a[j]:
					ij += 1
				elif a[i]:
					ii += 1
				elif a[j]:
					jj += 1
			if ii + jj + ij == n and ii + ij >= n // 2 and (jj + ij >= n // 2):
				print('YES')
				flag = True
				break
		if flag:
			break
	if not flag:
		print('NO')


from itertools import combinations

def solve(days, all_students):
	required = all_students // 2
	for (a, b) in combinations(list(range(5)), 2):
		(n1, n2) = (len(days[a]), len(days[b]))
		students = days[a].union(days[b])
		if len(students) == all_students and n1 >= required and (n2 >= required):
			return 'YES'
	return 'NO'
for _ in range(int(input())):
	n = int(input())
	days = [set() for _ in range(5)]
	totals = [0] * 5
	for student in range(n):
		for (day, value) in enumerate(input().split()):
			if value == '1':
				days[day].add(student)
				totals[day] += 1
	print(solve(days, n))


from sys import stdin
from collections import defaultdict

def solve():
	results = []
	for _ in range(int(stdin.readline().strip())):
		n = int(stdin.readline().strip())
		days = []
		for _ in range(n):
			a = list(map(int, stdin.readline().strip().split()))
			days.append(a)
		available = defaultdict(set)
		for i in range(n):
			for j in range(5):
				if days[i][j] == 1:
					available[j].add(i)
		for i in range(4):
			cnt = 0
			if len(available[i]) >= n // 2:
				for j in range(i + 1, 5):
					if len(available[j]) < n // 2:
						continue
					tmp1 = set(available[i])
					tmp2 = set(available[j])
					tmp = tmp1 & tmp2
					for x in tmp:
						if len(tmp1) > n // 2:
							tmp1.remove(x)
							continue
						if len(tmp2) > n // 2:
							tmp2.remove(x)
							continue
					if len(tmp1) == len(tmp2) == n // 2 and len(tmp1 & tmp2) == 0:
						cnt = 2
						break
			if cnt == 2:
				break
		results.append('YES' if cnt == 2 else 'NO')
	print('\n'.join(map(str, results)))
solve()


for _ in range(int(input())):
	n = int(input())
	c = [set(), set(), set(), set(), set()]
	for i in range(n):
		(b1, b2, b3, b4, b5) = map(lambda x: bool(int(x)), input().split())
		if b1:
			c[0].add(i)
		if b2:
			c[1].add(i)
		if b3:
			c[2].add(i)
		if b4:
			c[3].add(i)
		if b5:
			c[4].add(i)
	f = 'NO'
	for j in range(5):
		for q in range(j + 1, 5):
			if len(c[j]) >= n / 2 and len(c[q]) >= n / 2 and (c[j] | c[q] == set(range(n))):
				f = 'YES'
				break
	print(f)


for _ in range(int(input())):
	n = int(input())
	sur = []
	for i in range(n):
		sur.append(list(map(str, input().split())))
	choices = [(m1, m2) for m1 in range(5) for m2 in range(m1, 5) if m1 != m2]
	for x in choices:
		(m1, m2) = (x[0], x[1])
		both = 0
		(fir, sec) = (0, 0)
		for y in sur:
			if y[m1] == '1' and y[m2] == '1':
				both += 1
			elif y[m1] == '1':
				fir += 1
			elif y[m2] == '1':
				sec += 1
		if fir + sec + both == n and fir <= n // 2 and (sec <= n // 2):
			print('YES')
			break
	else:
		print('NO')


from sys import stdout
output = []
pairs = [(i, j) for i in range(4) for j in range(i + 1, 5)]
for _t in range(int(input())):
	n = int(input())
	students = [list(map(int, input().split(' '))) for _ in range(n)]
	for (i, j) in pairs:
		(oi, oj) = (0, 0)
		for s in students:
			if s[i] == 0 == s[j]:
				break
			if s[i] == 0 != s[j]:
				oi += 1
			elif s[i] != 0 == s[j]:
				oj += 1
		else:
			if max(oi, oj) <= n // 2:
				output.append('YES')
				break
	else:
		output.append('NO')
stdout.write('\n'.join(map(str, output)))


from collections import Counter, deque
import math
from random import randint
from bisect import bisect
import sys
import re
MOD = 1000000007
MAX = sys.maxsize
MIN = -sys.maxsize

class get:

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

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

	def float():
		return list(map(float, input().split()))

	def map():
		return map(int, input().split())

def sqrt(x):
	return int(math.sqrt(x)) + 1

def gcd(*args):
	result = args[0]
	for item in args:
		result = math.gcd(result, item)
	return result

def LCM(a, b):
	return a * b // math.gcd(a, b)

def solve():
	n = int(input())
	d = {0: set(), 1: set(), 2: set(), 3: set(), 4: set()}
	for i in range(n):
		kk = get.int()
		for j in range(5):
			if kk[j] == 1:
				d[j].add(i)
	mylist = []
	for (a, b) in d.items():
		if len(b) >= n // 2:
			mylist.append(b)
	if len(mylist) <= 1:
		print('NO')
	else:
		temp = False
		for i in range(len(mylist) - 1):
			for j in range(i + 1, len(mylist)):
				s1 = mylist[i].union(mylist[j])
				if len(s1) == n:
					print('YES')
					temp = True
					break
			if temp == True:
				break
		if temp == False:
			print('NO')
for _ in range(int(input())):
	solve()


import sys
import itertools
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		N = int(input())
		A = [[int(x) for x in input().split()] for _ in range(N)]
		half = N // 2
		f = False
		for (one, two) in itertools.combinations(range(5), 2):
			used = set()
			for (i, a) in enumerate(A):
				if a[one] == 1 and a[two] == 0:
					used.add(i)
					if len(used) == half:
						break
			if len(used) != half:
				for (i, a) in enumerate(A):
					if a[one] == 1 and i not in used:
						used.add(i)
						if len(used) == half:
							break
			if len(used) != half:
				continue
			for (i, a) in enumerate(A):
				if a[two] == 1 and i not in used:
					used.add(i)
			if len(used) == N:
				f = True
				break
		if f:
			print('YES')
		else:
			print('NO')
main()


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	if n % 2:
		print('NO')
		continue
	flag = 0
	s = [set(), set(), set(), set(), set()]
	for y in range(n):
		a = [int(x) for x in input().split()]
		for z in range(5):
			if a[z] == 1:
				s[z].add(y)
	for x in range(5):
		for y in range(x + 1, 5):
			if len(s[x]) >= n // 2 and len(s[y]) >= n // 2 and (len(s[x] | s[y]) == n):
				flag = 1
				break
		if flag:
			break
	print('YES' if flag else 'NO')


import operator
import bisect
import math
from queue import PriorityQueue as pq
from heapq import heapify, heappop, heappush, heappushpop, nlargest, heapreplace, nsmallest
from itertools import permutations, accumulate
import os
import array
import sys
from io import BytesIO, IOBase
from collections import Counter, deque, OrderedDict, defaultdict
from bisect import bisect_right, insort_right
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')
getint = lambda : int(sys.stdin.readline().rstrip('\r\n'))
getints = lambda : map(int, sys.stdin.readline().rstrip('\r\n').split())
li = lambda : list(map(int, sys.stdin.readline().rstrip('\r\n').split()))
getstrs = lambda : map(str, sys.stdin.readline().rstrip('\r\n').split())
ls = lambda : list(map(str, sys.stdin.readline().rstrip('\r\n').split()))

def prog_name():
	n = getint()
	d = {1: [], 2: [], 3: [], 4: [], 5: []}
	for x in range(n):
		temp = li()
		for y in range(5):
			if temp[y] == 1:
				d[y + 1].append(x + 1)
	for a in d:
		if len(d[a]) >= n // 2:
			for b in d:
				if len(d[b]) >= n // 2:
					if a != b:
						if len(set(d[a]).union(set(d[b]))) == n:
							print('YES')
							return
	print('NO')

def main():
	T = getint()
	for unique in range(T):
		prog_name()
main()


import os, sys
from io import BytesIO, IOBase
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))
try:
	(sys.stdin, sys.stdout, sys.stderr) = (open('input.txt', 'r'), open('output.txt', 'w'), open('error.txt', 'w'))
except:
	pass
ii1 = lambda : int(sys.stdin.readline().strip())
is1 = lambda : sys.stdin.readline().strip()
iia = lambda : list(map(int, sys.stdin.readline().strip().split()))
isa = lambda : sys.stdin.readline().strip().split()
mod = int(1000000000.0 + 7)
from collections import *
import itertools
MOD = 1000000007
from math import *
import math
import bisect
for _ in range(ii1()):
	n = ii1()
	l = [[] for i in range(n)]
	for i in range(n):
		l[i] = iia()
	ans = False
	for j in range(5):
		for k in range(5):
			if j == k:
				continue
			cnt1 = 0
			cnt2 = 0
			cntno = 0
			for z in range(n):
				if l[z][j] == 1:
					cnt1 += 1
				if l[z][k] == 1:
					cnt2 += 1
				if l[z][j] == 0 and l[z][k] == 0:
					cntno += 1
			if cnt1 >= n // 2 and cnt2 >= n // 2 and (cntno == 0):
				ans = True
				break
		if ans == True:
			break
	if ans == True:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	gr = []
	ans = 'NO'
	for i in range(n):
		a = list(map(int, input().split()))
		gr.append(a)
	for i in range(5):
		f = False
		for j in range(i + 1, 5):
			temp = [0] * n
			flag = True
			count1 = 0
			count2 = 0
			for k in range(n):
				if gr[k][i] == 1:
					count1 += 1
				if gr[k][j] == 1:
					count2 += 1
				temp[k] = gr[k][i] + gr[k][j]
				if temp[k] == 0:
					flag = False
					break
			if flag and count1 >= n / 2 and (count2 >= n / 2):
				ans = 'YES'
				f = True
				break
		if f:
			break
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = []
	for i in range(n):
		a.append(list(map(int, input().split())))
	li = []
	for i in range(5):
		nli = []
		for j in range(n):
			if a[j][i] == 1:
				nli.append(j + 1)
		if len(nli) >= n // 2:
			li.append(nli)
	if len(li) >= 2:
		y = 0
		for i in range(len(li)):
			for j in range(i + 1, len(li)):
				nnli = li[i] + li[j]
				nnli = set(nnli)
				nnli = list(nnli)
				if len(nnli) == n:
					y = 1
		if y == 1:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


def do():
	n = int(input()) // 2
	dat = []
	for i in range(2 * n):
		dat.append(list(map(int, input().split())))
	for i in range(5):
		for j in range(i + 1, 5):
			cani = canj = canboth = canno = 0
			for ind in range(2 * n):
				if dat[ind][i] == dat[ind][j] == 1:
					canboth += 1
				elif dat[ind][i] == 1:
					cani += 1
				elif dat[ind][j] == 1:
					canj += 1
				else:
					canno += 1
			if canno > 0:
				continue
			if cani > n or canj > n:
				continue
			print('YES')
			return
	print('NO')
	return
q = int(input())
for _ in range(q):
	do()


from itertools import combinations
for _ in range(int(input())):
	weekdays = []
	for _ in range(5):
		weekdays.append([])
	n = int(input())
	for i in range(n):
		arr = list(map(int, input().split()))
		for j in range(5):
			if arr[j] == 1:
				weekdays[j].append(i + 1)
	count = []
	for i in range(5):
		if len(weekdays[i]) >= int(n / 2):
			count.append(i)
	comb = combinations(count, 2)
	for i in comb:
		backup = len(weekdays[i[0]]) + len(weekdays[i[1]]) - n
		setA = set(weekdays[i[0]])
		setB = set(weekdays[i[1]])
		inter = setA.intersection(setB)
		if len(inter) <= backup:
			print('YES')
			break
	else:
		print('NO')


t = int(input())
for _ in range(t):
	f = []
	se = []
	t = []
	fo = []
	fi = []
	n = int(input())
	for j in range(n):
		s = [int(x) for x in input().split()]
		for i in range(5):
			if s[i] == 1:
				if i == 0:
					f.append(j)
				elif i == 1:
					se.append(j)
				elif i == 2:
					t.append(j)
				elif i == 3:
					fo.append(j)
				else:
					fi.append(j)
	l = []
	k = n // 2
	if len(f) >= k:
		l.append(f)
	if len(se) >= k:
		l.append(se)
	if len(t) >= k:
		l.append(t)
	if len(fo) >= k:
		l.append(fo)
	if len(fi) >= k:
		l.append(fi)
	c = 0
	l2 = set((x for x in range(n)))
	for i in range(len(l)):
		s = set(l[i])
		for j in range(i + 1, len(l)):
			s1 = set(l[j])
			if len(s) >= k and len(s1) >= k and (s.union(s1) == l2):
				print('YES')
				c = 1
				break
		if c == 1:
			break
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	res = [set(), set(), set(), set(), set()]
	for i in range(n):
		days = input().split(' ')
		for (idx, day) in enumerate(days):
			if days[idx] == '1':
				res[idx].add(i)
	flag = 0
	for r in res:
		if len(r) >= n // 2:
			flag += 1
	if flag < 2:
		print('NO')
	else:
		flag = False
		try:
			for i in range(4):
				for j in range(i + 1, 5):
					union = res[i].union(res[j])
					if len(union) == n and len(res[i]) >= n // 2 and (len(res[j]) >= n // 2):
						flag = True
						raise Exception
		except Exception:
			pass
		if flag:
			print('YES')
		else:
			print('NO')


for _ in range(int(input())):
	n = int(input())
	ans = 'NO'
	l = [[], [], [], [], []]
	for i in range(n):
		temp = 0
		for j in input().split(' '):
			if int(j) == 1:
				l[temp].append(i)
			temp += 1
	final = []
	for i in l:
		if len(i) >= n / 2:
			final.append(i)
	for i in range(len(final) - 1):
		for j in range(1, len(final)):
			i1 = set(final[i])
			i2 = set(final[j])
			if len(i1.union(i2)) == n:
				ans = 'YES'
				break
	print(ans)


from itertools import permutations as per
from math import factorial as fact
from difflib import SequenceMatcher
t = int(input())
for _ in range(t):
	n = int(input())
	a = []
	for i in range(n):
		a.append(input().split())
	ans = 0
	for i in range(5):
		for j in range(i + 1, 5):
			c1 = c2 = c3 = 0
			for k in range(n):
				if a[k][i] == '1' and a[k][j] == '1':
					c3 += 1
				elif a[k][i] == '1':
					c1 += 1
				elif a[k][j] == '1':
					c2 += 1
				else:
					break
			else:
				if c1 <= n // 2 and c2 <= n // 2:
					ans = 1
					print('YES')
					break
		if ans:
			break
	else:
		print('NO')


import time
from collections import deque

def inpt():
	return int(input())

def inpl():
	return list(map(int, input().split()))

def inpm():
	return map(int, input().split())

def solve():
	n = inpt()
	l = [[] for i in range(5)]
	for i in range(n):
		x = inpl()
		for j in range(5):
			l[j].append(x[j])
	for i in range(5):
		for j in range(5):
			if i != j:
				x = sum([int(l[i][k] == 1 and l[i][k] != l[j][k]) for k in range(n)])
				y = sum([int(l[j][k] == 1 and l[i][k] != l[j][k]) for k in range(n)])
				z = sum([int(l[i][k] == l[j][k] == 1) for k in range(n)])
				if x + y + z == n and x <= n / 2 and (y <= n / 2):
					print('YES')
					return
	print('NO')

def main():
	m = 10 ** 9 + 7
	t = inpt()
	while t:
		t -= 1
		solve()
main()


import sys
input = sys.stdin.readline
from pprint import pprint
import math
INF = 1 << 63

def do():
	n = int(input())
	dat = []
	for i in range(n):
		l = list(map(int, input().split()))
		dat.append(l)
	needn = n / 2
	for i in range(5):
		for j in range(i + 1, 5):
			cani = 0
			canj = 0
			canboth = 0
			canno = 0
			for ind in range(n):
				if dat[ind][i] == dat[ind][j] == 1:
					canboth += 1
				elif dat[ind][i] == 1:
					cani += 1
				elif dat[ind][j] == 1:
					canj += 1
				else:
					canno += 1
			if cani > needn:
				continue
			if canj > needn:
				continue
			if canno > 0:
				continue
			print('YES')
			return
	print('NO')
	return
q = int(input())
for _ in range(q):
	do()


from __future__ import print_function
from math import *
from collections import deque
import os
import sys
from io import BytesIO, IOBase

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')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
for _ in range(inp()):
	n = inp()
	l = []
	for i in range(n):
		l.append(inlt())
	f = 0
	for i in range(5):
		for j in range(i + 1, 5):
			first = 0
			second = 0
			both = 0
			ac = 1
			for k in range(n):
				if l[k][i] == 1 and l[k][j] == 1:
					both += 1
				if l[k][i] == 1 and l[k][j] != 1:
					first += 1
				if l[k][i] == 0 and l[k][j] == 1:
					second += 1
				if l[k][i] == l[k][j] == 0:
					ac = 0
			if ac == 1:
				if first <= n // 2 and second <= n // 2:
					f = 1
	if f:
		print('YES')
	else:
		print('NO')


from collections import defaultdict, Counter, deque
from math import sqrt, log10, log, floor, factorial, gcd
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations
import sys, io, os
input = sys.stdin.readline
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
inf = float('inf')
mod = 10 ** 9 + 7

def yn(a):
	print('YES' if a else 'NO')
ceil = lambda a, b: (a + b - 1) // b
t = int(input())
for i in range(t):
	n = int(input())
	d = [[0] * n for i in range(5)]
	counter = [0] * 5
	for ii in range(n):
		l = [int(i) for i in input().split()]
		for i in range(5):
			if l[i]:
				d[i][ii] = 1
				counter[i] += 1
	pos = 0
	for i in range(5):
		for j in range(i + 1, 5):
			if counter[i] >= n // 2 and counter[j] >= n // 2:
				flg = 1
				for k in range(n):
					if not d[i][k] and (not d[j][k]):
						flg = 0
						break
				if flg:
					pos = 1
	if pos:
		print('YES')
	else:
		print('NO')


num_cases = int(input())
for _ in range(num_cases):
	num_students = int(input())
	students_per_group = num_students // 2
	set1 = set()
	set2 = set()
	set3 = set()
	set4 = set()
	set5 = set()
	for i in range(num_students):
		avail = [True if each == '1' else False for each in input().split(' ')]
		if avail[0]:
			set1.add(i)
		if avail[1]:
			set2.add(i)
		if avail[2]:
			set3.add(i)
		if avail[3]:
			set4.add(i)
		if avail[4]:
			set5.add(i)
	sets = [set1, set2, set3, set4, set5]
	solved = False
	for i in range(5):
		for j in range(5):
			if i == j:
				continue
			a = sets[i]
			b = sets[j]
			if len(a | b) != num_students:
				continue
			both = a & b
			a_only = a - b
			b_only = b - a
			a_requires = max(0, students_per_group - len(a_only))
			b_requires = max(0, students_per_group - len(b_only))
			num_both = len(both)
			num_both -= a_requires
			num_both -= b_requires
			if num_both >= 0:
				print('YES')
				solved = True
				break
		if solved:
			break
	if not solved:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	d = {i: {} for i in range(5)}
	for i in range(n):
		a = list(input().split())
		for j in range(5):
			if a[j] == '1':
				d[j][i] = True
	pos = []
	for i in d:
		if len(d[i]) >= n // 2:
			pos.append(d[i])
	got = False
	for i in range(len(pos)):
		for j in range(i + 1, len(pos)):
			isit = True
			for k in range(n):
				if pos[i].get(k) == None and pos[j].get(k) == None:
					isit = False
					break
			if isit:
				got = True
				break
	print('YES' if got else 'NO')


t = int(input())
for g in range(t):
	n = int(input())
	week = [[], [], [], [], []]
	for i in range(n):
		k = input().split(' ')
		for j in range(5):
			if k[j] == '1':
				week[j].append(i)
	p = n / 2
	fak = week.copy()
	for i in week:
		if len(i) < p:
			fak.remove(i)
	week = fak
	k = True
	if len(week) < 2:
		print('NO')
	else:
		for (index, i) in enumerate(week):
			fake = week[index + 1:]
			for j in fake:
				nl = list(set(i + j))
				if len(nl) == n:
					print('YES')
					k = False
					break
			if k == False:
				break
		if k == True:
			print('NO')


for _ in range(int(input())):
	n = int(input())
	arr = []
	for _ in range(n):
		arr.append(list(map(int, input().split())))
	done = False
	for j in range(5):
		for k in range(j + 1, 5):
			(day_j, day_k, common) = (0, 0, 0)
			for i in range(n):
				if arr[i][j] == 1:
					if arr[i][k] == 1:
						common += 1
					else:
						day_j += 1
				if arr[i][k] == 1:
					if arr[i][j] == 1:
						common += 1
					else:
						day_k += 1
			if day_j + day_k + common // 2 == n and (day_j <= n // 2 and day_k <= n // 2):
				done = True
				break
	if not done:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	if n % 2 == 1:
		print('NO')
		break
	r = {1: set(), 2: set(), 3: set(), 4: set(), 0: set()}
	f = 0
	for i in range(n):
		r1 = input().split()
		for j in range(5):
			if r1[j] == '1':
				r[j].add(i)
	a = []
	for i in range(4):
		if len(r[i]) >= n // 2 and f == 0:
			for j in range(i + 1, 5):
				if len(r[j]) >= n // 2:
					if len(r[i] | r[j]) == n:
						f = 1
						print('YES')
						break
	if f == 0:
		print('NO')


import sys
from collections import Counter
import math
import bisect
import heapq
from itertools import combinations
from itertools import permutations
from collections import defaultdict
from collections import Counter
num_cases = int(sys.stdin.readline().strip())
for case in range(1, num_cases + 1):
	N = int(sys.stdin.readline().strip())
	all_A = []
	yoeil = [0, 0, 0, 0, 0]
	double_yoeil = defaultdict(int)
	for _ in range(N):
		A = list(map(int, sys.stdin.readline().split()))
		for (index, value) in enumerate(A):
			if value == 1:
				yoeil[index] += 1
		combi = [0, 1, 2, 3, 4]
		combi = list(combinations(combi, 2))
		for info in combi:
			(alpha, beta) = info
			if A[alpha] == 1 and A[beta] == 1:
				double_yoeil[str(alpha) + str(beta)] += 1
	combi = [0, 1, 2, 3, 4]
	combi = list(combinations(combi, 2))
	signal = 0
	for info in combi:
		(alpha, beta) = info
		real_alpha = yoeil[alpha]
		real_beta = yoeil[beta]
		real_cross = double_yoeil[str(alpha) + str(beta)]
		if real_alpha + real_beta - real_cross == N:
			if real_alpha - real_cross <= N / 2 and real_beta - real_cross <= N / 2:
				signal = 1
				print('YES')
				break
	if signal == 0:
		print('NO')


from typing import DefaultDict

def solve(n, grid):
	graph = DefaultDict(int)
	day = DefaultDict(int)
	for i in range(n):
		for j in range(5):
			day[j] += grid[i][j]
			for k in range(5):
				graph[j, k] = graph[j, k] + 1 if grid[i][j] == grid[i][k] == 1 else graph[j, k]
	for i in range(5):
		for j in range(5):
			if i != j:
				tot = day[i] + day[j] - graph[i, j]
				diff = abs(day[i] - day[j])
				if tot == n and graph[i, j] >= diff:
					print('YES')
					return
	print('NO')
	return

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		grid = []
		for _ in range(n):
			row = list(map(int, input().split()))
			grid.append(row)
		solve(n, grid)
main()


import math
from collections import Counter

def mapIn():
	return map(int, input().split())

def listIn():
	return list(map(int, input().split()))

def intIn():
	return int(input())
intMax = float('inf')
intMin = float('-inf')
d4x = [1, -1, 0, 0]
d4y = [0, 0, 1, -1]
d8x = [1, -1, 0, 0, -1, -1, 1, 1]
d8y = [0, 0, 1, -1, -1, 1, -1, 1]

def checkBit(n, i):
	return n >> i & 1
mod = int(1000000000.0 + 7)

def solve():
	n = int(input())
	p = []
	for i in range(n):
		p.append(listIn())
	for i in range(4):
		for j in range(i + 1, 5):
			(c1, c2, c3) = (0, 0, 0)
			for k in range(n):
				if p[k][i] == 1:
					c1 += 1
				if p[k][j] == 1:
					c2 += 1
				if p[k][i] == 1 and p[k][j] == 1:
					c3 += 1
			c1 -= c3
			c2 -= c3
			if c1 <= n // 2 and c2 <= n // 2 and (c1 + c2 + c3 == n):
				print('YES')
				return
	print('NO')
t = int(input())
for tc in range(t):
	solve()


t = int(input())

def f():
	n = int(input())
	s = []
	for i in range(n):
		s.append(list(map(int, input().split(' '))))
	for a in range(5):
		for b in range(5):
			if b == a:
				continue
			cnta = 0
			cntb = 0
			cntno = 0
			for i in s:
				if i[a] + i[b] == 0:
					cntno = 1
					break
				if i[a] + i[b] == 2:
					pass
				elif i[a] == 1:
					cnta += 1
				elif i[b] == 1:
					cntb += 1
			if cnta <= n // 2 and cntb <= n // 2 and (cntno == 0):
				print('YES')
				return
	print('NO')
	return
while t:
	f()
	t -= 1


def solve(n, s):
	for i in range(5):
		for j in range(i + 1, 5):
			a = b = c = 0
			for k in range(n):
				a += s[k][i] or s[k][j]
				b += s[k][i]
				c += s[k][j]
			if a == n and b >= n // 2 and (c >= n // 2):
				print('YES')
				return
	print('NO')
for _ in range(int(input())):
	n = int(input())
	s = [[int(s) for s in input().split()] for _ in range(n)]
	solve(n, s)


for _ in range(int(input())):
	n = int(input())
	d = {}
	for i in range(5):
		d[i] = set()
	for i in range(n):
		l = list(map(int, input().split()))
		for j in range(5):
			if l[j] == 1:
				d[j].add(i)
	flag = 0
	for i in range(5):
		for j in range(i + 1, 5):
			e1 = d[i].copy()
			e2 = d[j].copy()
			if len(e1) < n // 2:
				continue
			if len(e2) < n // 2:
				continue
			c3 = len(e1 & e2)
			c1 = len(e1) - c3
			c2 = len(e2) - c3
			if c1 > n // 2 or c2 > n // 2:
				continue
			if c1 + c2 + c3 < n:
				continue
			flag = 1
			break
		if flag:
			break
	if flag:
		print('YES')
	else:
		print('NO')


def solve():
	n = int(input())
	try:
		arr = []
		for i in range(n):
			a = list(map(int, input().split()))
			arr.append(a)
		flag = False
		for i in range(5):
			for j in range(i + 1, 5):
				(g1, g2, both) = (0, 0, 0)
				for k in range(n):
					if arr[k][i] == 1 and arr[k][j] == 1:
						both += 1
					else:
						if arr[k][i] == 1:
							g1 += 1
						if arr[k][j] == 1:
							g2 += 1
				if g1 + g2 == n - both and g1 >= n // 2 - both and (g2 >= n // 2 - both):
					flag = True
		if flag:
			print('YES')
		else:
			print('NO')
	except EOFError as e:
		print('Error')
for case in range(int(input())):
	solve()


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	a = [list(input().split()) for _ in range(n)]
	s = [{i for i in range(n) if a[i][w] == '1'} for w in range(5)]
	for i in range(4):
		for j in range(i + 1, 5):
			if len(s[i]) < n // 2 or len(s[j]) < n // 2:
				continue
			if len(s[i].union(s[j])) == n:
				print('YES')
				return
	print('NO')
for _ in range(int(input())):
	solve()


import sys
inp = sys.stdin.readline

def s(submask, arr):
	x = submask
	r = 0
	while x < len(arr):
		r += arr[x]
		x = x + 1 | submask
	return r

def solve():
	n = int(inp())
	c = [0] * 32
	for i in range(n):
		mask = int(inp().strip().replace(' ', ''), 2)
		c[mask] += 1
	if n % 2 != 0:
		print('NO')
		return
	n2 = n // 2
	for i in range(5):
		first1 = s(1 << i, c)
		for j in range(i):
			second = s(1 << j, c)
			both = s(1 << i | 1 << j, c)
			first = first1 - both
			second -= both
			w = max(min(n2 - first, both), 0)
			first += w
			both -= w
			w = max(min(n2 - second, both), 0)
			if first >= n2 and second + w >= n2:
				print('YES')
				return
	print('NO')

def main():
	for i in range(int(inp())):
		solve()
main()


import sys
from math import factorial, gcd
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify, nlargest, nsmallest
from itertools import groupby, accumulate
from copy import deepcopy
MOD = 10 ** 9 + 7
INF = float('inf')
input = sys.stdin.readline
rl = lambda : list(map(int, input().split()))
rs = lambda : sys.stdin.readline().strip()
for _ in range(int(input())):
	n = int(input())
	grid = [rl() for _ in range(n)]
	cand = []
	for col in zip(*grid):
		if sum(col) >= n // 2:
			cand.append(col)
	flag = False
	for i in range(len(cand)):
		col1 = set([k for k in range(n) if cand[i][k] == 1])
		for j in range(i + 1, len(cand)):
			col2 = set([k for k in range(n) if cand[j][k] == 1])
			if len(col2 - col1) + len(col1) >= n or len(col1 - col2) + len(col2) >= n:
				flag = True
				break
		if flag:
			break
	print('YES' if flag else 'NO')


def printPossible(arr, n):
	combination = []
	counts = []
	for i in range(5):
		count = 0
		for j in range(n):
			count += arr[j][i]
		if count >= n // 2:
			combination.append(i)
			counts.append(count)
	for i in range(len(combination)):
		for j in range(i + 1, len(combination)):
			count = 0
			for k in range(n):
				count += arr[k][combination[i]] & arr[k][combination[j]]
			remaining1 = counts[i] - count
			remaining2 = counts[j] - count
			if remaining1 >= remaining2:
				temp = remaining1 + count - n // 2
				if temp + remaining2 >= n // 2:
					print('YES')
					return
			else:
				temp = remaining2 + count - n // 2
				if temp + remaining1 >= n // 2:
					print('YES')
					return
	print('NO')

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		arr = [0] * n
		for j in range(n):
			arr[j] = [int(num) for num in input().split()]
		printPossible(arr, n)
main()