#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
void solve( ) {
int n, m, k;
cin >> n>> m>> k;
vector< vector< int >> a( n, vector< int > ( m) ) ;
FOR( i, n) {
FOR( j, m) {
cin >> a[ i] [ j] ;
}
}
unordered_map< int ,int > mp;
FOR( i, n) {
int hash= 0 ;
FOR( b, m) {
if ( a[ i] [ b] == 1 ) hash | = ( 1 << b) ;
}
mp[ hash] ++ ;
}
int res= 0 ;
FOR( i, n) {
int hash= 0 ;
FOR( b, m) {
if ( a[ i] [ b] == 1 ) hash | = ( 1 << b) ;
}
int pair= ( ~( hash) & ( ( 1 << m) - 1 ) ) ;
res= max( res, mp[ hash] + min( k, mp[ pair] ) ) ;
}
cout << res << endl;
}
int main( ) {
int t= 1 ;
cin >> t;
while ( t-- ) {
solve( ) ;
}
return 0 ;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIEZPUihpLCBuKSBmb3IgKGludCBpID0gMDsgaSA8IChuKTsgaSsrKQoKdHlwZWRlZiBsb25nIGxvbmcgbGw7Cgp2b2lkIHNvbHZlKCl7CiAgICBpbnQgbiwgbSwgazsKICAgIGNpbj4+bj4+bT4+azsKICAgIHZlY3Rvcjx2ZWN0b3I8aW50Pj4gYShuLCB2ZWN0b3I8aW50PihtKSk7CiAgICBGT1IoaSwgbil7CiAgICAgICAgRk9SKGosIG0pewogICAgICAgICAgICBjaW4+PmFbaV1bal07CiAgICAgICAgfQogICAgfQogICAgdW5vcmRlcmVkX21hcDxpbnQsaW50PiBtcDsKICAgIEZPUihpLCBuKXsKICAgICAgICBpbnQgaGFzaD0wOwogICAgICAgIEZPUihiLCBtKXsKICAgICAgICAgICAgaWYgKGFbaV1bYl09PTEpIGhhc2ggfD0gKDE8PGIpOwogICAgICAgIH0KICAgICAgICBtcFtoYXNoXSsrOwogICAgfQogICAgaW50IHJlcz0wOwogICAgRk9SKGksIG4pewogICAgICAgIGludCBoYXNoPTA7CiAgICAgICAgRk9SKGIsIG0pewogICAgICAgICAgICBpZiAoYVtpXVtiXT09MSkgaGFzaCB8PSAoMTw8Yik7CiAgICAgICAgfQogICAgICAgIGludCBwYWlyPSh+KGhhc2gpJigoMTw8bSktMSkpOwogICAgICAgIHJlcz1tYXgocmVzLCBtcFtoYXNoXSttaW4oaywgbXBbcGFpcl0pKTsKICAgIH0KICAgIGNvdXQgPDwgcmVzIDw8IGVuZGw7Cn0KCmludCBtYWluKCl7CiAgICBpbnQgdD0xOwogICAgY2luPj50OwogICAgd2hpbGUodC0tKXsKICAgICAgICBzb2x2ZSgpOwogICAgfQogICAgcmV0dXJuIDA7Cn0=