#include<bits/stdc++.h>

using namespace std;

const int N = 1e3 + 10;

int a[N][N];
int n;

void solve() {
cin >> n;
for (int i = 0; i < n; i ++) {
for (int j = 0; j < 5; j ++)
cin >> a[i][j];
}
bool f = 0;
for (int i = 0; i < 5 ; i++) {
for (int j = 0; j < 5 ;j ++) {
if (i == j) continue;
int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
for (int k = 0; k < n; k ++) {
if (a[k][j] && a[k][i]) {
c4 ++;
}
else if (a[k][j] && !a[k][i]) {
c1 ++;
}
else if (!a[k][j] && a[k][i]) {
c2 ++;
}
else c3 ++;
}
if (!(c3 || c1 > n / 2 || c2 > n / 2)) {
f = 1;
}
}
}
if (f)
puts("YES");
else puts("NO");
}
int main () {
int t;
cin >> t;
while (t --) solve();
return 0;
}

分类讨论 枚举两天a, b 将人分为4种标记a的,标记b的,标记ab的,不标记ab的。 然后分析就可以了