#include int n, m; char s1[55], s2[55]; int a[105][105]; int p[105]; bool check[105]; bool dfs(int x) { for(int i = 1; i <= 2 * m; i++) if (a[x][i]) { if (!check[i]) { check[i] = true; if (p[i] == 0 || dfs(p[i])) { p[i] = x; p[x] = i; return true; } } } return false; } int main() { int T; scanf("%d", &T); while(T--) { scanf("%d%d", &n, &m); memset(a, 0, sizeof(a)); for(int j = 1; j <= m; j++) for(int k = 1; k <= m; k++) a[j][m + k] = a[m + k][j] = 1; for(int i = 1; i <= n; i++) { scanf("%s", s1); scanf("%s", s2); for(int j = 0; j < m; j++) for(int k = 0; k < m; k++) if (s1[j] != s2[k]) a[j + 1][m + k + 1] = a[m + k + 1][j + 1] = 0; } //hungary int ans = 0; memset(p, 0, sizeof(p)); for(int i = m; i >= 1; i--) { if (!p[i]) { memset(check, false, sizeof(check)); if (dfs(i)) ans++; } } if (ans < m) printf("-1"); else { printf("%d", p[1] - m); for(int i = 2; i <= m; i++) printf(" %d", p[i] - m); } printf("\n"); } return 0; }