/* #include using namespace std; const int maxn = 60; int n , m; int ans[maxn]; char in[22][maxn] , out[22][maxn]; vector p[30]; bool flag; struct node { char in[maxn] , out[maxn]; int mx; bool can; void init() { int a[30] , b[30]; scanf("%s%s",in,out); for( int i = 0; i < 26; i++ ) a[i] = b[i] = 0; for( int i = 0; i < m; i++ ){ a[ in[i]-'a' ]++ , b[ out[i]-'a' ]++; } mx = 0 , can = true; for( int i = 0; i < 26; i++ ) { mx = max(mx,a[i]); if ( a[i] != b[i] ){ can = false; break; } } } bool operator<(const node& rhs) const { return mx < rhs.mx; } }x[30]; void dfs( int now ) { if ( flag ) return; if ( now >= m ) { return } } int solve() { for( int i = 1; i <= n; i++ ) if ( !x[i].can ) return -1; sort(x+1,x+1+n); for( int i = 0; i < 26; i++ ) p[i].clear(); for( int i = 0; i < m; i++ ) p[ x[1].out[i]-'a' ].push_back(i); flag = false; dfs( 1 ); } int main() { int T; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); for( int i = 1; i <= n; i++ ) x[i].init(); printf("%d\n",solve() ); } return 0; }*/ #include #include #include #include using namespace std; bool a[50][50]; int main() { int T; scanf("%d", &T); while (T--) { int N, M; char in[60], out[60]; scanf("%d%d", &N, &M); memset(a, 0, sizeof(a)); for (int k = 0; k < N; k++) { scanf("%s%s", in, out); for (int i = 0; i < M; i++) { for (int j = 0; j < M; j++) { if (in[i] != out[j]) { a[i][j] = 1; } } } } int ret[50]; bool flag = 0; for (int i = 0; i < M; i++) { int j = 0; for (j = 0; j < M; j++) { if (a[i][j] == 0) { ret[i] = j; for (int k = i+1; k < M; k++) { a[k][j] = 1; } break; } } if (j == M) flag = 1; } if (flag) { printf("-1\n"); } else { //puts("ans"); for (int i = 0; i < M-1; i++) { printf("%d ", ret[i]+1); } printf("%d\n", ret[M-1]+1); } } return 0; }