#include using namespace std; const int inf = 0x3f3f3f3f; int T, n, m, link[55]; bool g[55][55], nvis[55], del[55]; char s[55], t[55]; bool dfs(int u) { for (int v = 1; v <= m; ++v) { if (!g[u][v] || !nvis[v] || del[v]) continue; nvis[v] = false; if (!link[v] || dfs(link[v])) { link[v] = u; return true; } } return false; } int solve(int bg) { int ret = 0; for (int i = 1; i <= m; ++i) link[i] = 0; for (int i = bg; i <= m; ++i) { for (int j = 1; j <= m; ++j) nvis[j] = true; if (dfs(i)) ++ret; } return ret; } 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) g[i][j] = true; for (int i = 1; i <= n; ++i) { scanf("%s%s", s + 1, t + 1); for (int i = 1; i <= m; ++i) for (int j = 1; j <= m; ++j) if (t[j] != s[i]) g[i][j] = false; } for (int i = 1; i <= m; ++i) del[i] = false; if (solve(1) != m) { puts("-1"); continue; } for (int i = 1; i <= m; ++i) for (int j = 1; j <= m; ++j) if (g[i][j] && !del[j]) { del[j] = true; if (solve(i + 1) == m - i) { printf("%d%c", j, " \n"[i == m]); break; } del[j] = false; } } return 0; }