#include using namespace std; #define ll long long const int N = 22, M = 55; int T, n, m, vis[M], ans[M]; char a[N][M], b[N][M]; int main() { scanf("%d", &T); while(T--){ scanf("%d%d", &n, &m); for(int i=1; i<=n; ++i) scanf("%s%s", a[i]+1, b[i]+1); memset(vis, 0, sizeof vis); for(int i=1; i<=m; ++i){ ans[i]=0; for(int j=1; j<=m; ++j) if(!vis[j]){ bool f=1; for(int k=1; k<=n; ++k) f&=a[k][i]==b[k][j]; if(f){ vis[j]=1, ans[i]=j; break; } } if(!ans[i]){ puts("-1"); goto nxt; } } for(int i=1; i<=m; ++i) printf("%d%c", ans[i], " \n"[i==m]); nxt:; } return 0; }