#include <bits/stdc++.h>
using namespace std;
#define lld long long
#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int main()
{
// FASTIO;
int test;
cin>>test;
lld ans = 0;
for(int kase = 1; kase <= test; kase++)
{
int n,m,p;
cin>>n>>m>>p;
string tmp;
vector< string >s(n);
set< string >forbidden;
vector< vector<int> >banned(p, vector<int>(2, 0));
for(int i=0; i<n; i++) cin>>s[i];
for(int i=0; i<m; i++)
{
cin>>tmp;
if(forbidden.find(tmp) == forbidden.end())
{
forbidden.insert(tmp);
}
}
vector< vector< int > >data(p, vector<int>(2,0));
for(int i=0; i<p; i++)
{
for(int j=0; j<n; j++)
{
if(s[j][i] == '0') data[i][1]++;
else data[i][0]++;
}
}
tmp = "";
int ans = 0,tans;
for(int i=0; i<p; i++)
{
if(data[i][0] < data[i][1])
{
tmp+="0";
ans+=data[i][0];
}
else
{
tmp+="1";
ans+=data[i][1];
}
}
set< string >done;
set< pair<int,string> >trails;
trails.insert({ans,tmp});
while(forbidden.find(trails.begin()->second) != forbidden.end())
{
ans = trails.begin()->first;
tmp = trails.begin()->second;
trails.erase(trails.begin());
for(int i=0; i<p; i++)
{
if(tmp[i] == '0')
{
tmp[i] = '1';
tans = ans + (data[i][1] - data[i][0]);
if(done.find(tmp) == done.end())
{
done.insert(tmp);
trails.insert({tans,tmp});
}
tmp[i] = '0';
}
else
{
tmp[i] = '0';
tans = ans + (data[i][0] - data[i][1]);
if(done.find(tmp) == done.end())
{
done.insert(tmp);
trails.insert({tans,tmp});
}
tmp[i] = '1';
}
}
}
cout<<"Case #"<<kase<<": "<<trails.begin()->first<<"\n";
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgbGxkIGxvbmcgbG9uZwojZGVmaW5lIEZBU1RJTyBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApOyBjaW4udGllKDApOyBjb3V0LnRpZSgwKQoKaW50I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