#include #include const int _m = 50 + 10; int T, n, m; char s[_m], t[_m]; int match[_m], flag[_m]; int ans[_m]; int z[_m][_m]; bool find(int u) { for (int v = 1; v <= m; v++) { if (z[u][v]) { if (! flag[v]) { flag[v] = true; if (match[v] == -1 || find(match[v])) { match[v] = u; ans[u] = v; return true; } } } } return false; } int hungary() { memset(match, -1, sizeof(match)); int ans = 0; for (int i = m; i >= 1; i--) { memset(flag, 0, sizeof(flag)); ans += find(i); } return ans; } int main() { scanf("%d", &T); while (T--) { scanf("%d%d", &n, &m); for (int i = 1; i <= m; i++) { for (int j = 1; j <= m; j++) { z[i][j] = 1; } } for (int i = 1; i <= n; i++) { scanf("%s", s + 1); scanf("%s", t + 1); for (int j = 1; j <= m; j++) { for (int k = 1; k <= m; k++) { if (s[j] != t[k]) { z[j][k] = 0; } } } } if (hungary() == m) { for (int i = 1; i < m; i++) { printf("%d ", ans[i]); } printf("%d\n", ans[m]); } else { puts("-1"); } } return 0; }