#include using namespace std; #define reg register typedef long long ll; #define rep(i,a,b) for(reg int i=a,i##end=b;i<=i##end;++i) #define drep(i,a,b) for(reg int i=a,i##end=b;i>=i##end;--i) char IO; int rd(){ int s=0,f=0; while(!isdigit(IO=getchar())) if(IO=='-') f=1; do s=(s<<1)+(s<<3)+(IO^'0'); while(isdigit(IO=getchar())); return f?-s:s; } const int N=110; int n,m; int a[N]; char s1[N],s2[N]; int can[N][N]; int main(){ rep(kase,1,rd()) { n=rd();m=rd(); rep(i,1,m) rep(j,1,m) can[i][j]=1; rep(t,1,n) { scanf("%s%s",s1+1,s2+1); rep(i,1,m) rep(j,1,m) if(s1[i]!=s2[j]) can[i][j]=0; } int fl=1; rep(i,1,m) { a[i]=-1; rep(j,1,m) if(can[i][j]) { a[i]=j; break; } if(a[i]==-1) { fl=0; break; } rep(j,1,m) can[j][a[i]]=0; } if(fl) { rep(i,1,m) printf("%d%c",a[i],i==m?'\n':' '); } else puts("-1"); } }