#include #include int read() { int x=0,flag=1;char c; while((c=getchar())<'0' || c>'9') if(c=='-') flag=-1; while(c>='0' && c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar(); return x*flag; } int T,n,m,ans[55],used[55],mp[2505]; char a[55],b[55]; int main() { T = read(); while(T--) { memset(mp,0,sizeof (mp)); memset(ans,0,sizeof (ans)); memset(used,0,sizeof (used)); n = read();m = read(); for(int t = 1;t <= n;t ++) { scanf("%s %s",a,b); for(int i = 0;i < m;i ++) for(int j = 0;j < m;j ++) if(a[i] == b[j]) mp[i * m + j]++; } for(int i = 0;i < m;i ++) for(int j = 0;j < m;j ++) { if(mp[i * m + j] == n && !ans[i] && !used[j]) { ans[i] = j + 1; used[j] = 1; } } int flag = 0; for(int i = 0;i < m;i ++) if(!ans[i]) flag = 1; if(flag) { puts("-1"); continue ; } for(int i = 0;i < m - 1;i ++) printf("%d ",ans[i]); printf("%d\n",ans[m - 1]); } }