#include #include #include using namespace std; #define N 205 int n,m,k,l,t,s,T; char s1[N][N],s2[N][N]; int flag[N],f[N],a[N][N],ans[N]; int find(int u){ for (int v=1;v<=n;v++) if(a[u][v]&&!flag[v]){ flag[v]=1; if(f[v]==0||find(f[v])){ f[v]=u; return 1; } } return 0; } int main(){ scanf("%d",&T); while(T--){ s=0; memset(f,0,sizeof(f)); memset(a,0,sizeof(a)); scanf("%d%d",&m,&n); for (int i=1;i<=m;i++)scanf("%s%s",s1[i]+1,s2[i]+1); for (int i=1;i<=n;i++) for (int j=1;j<=n;j++){ int p=1; for (int k=1;k<=m;k++)if(s1[k][i]!=s2[k][j])p=0; if(p)a[i][j]=1; } for (int i=n;i;i--){ memset(flag,0,sizeof(flag)); s+=find(i); } if(s