#include using namespace std; const int maxn = 25; const int maxm = 55; int n, m; char s[maxn][maxm], t[maxn][maxm]; bool imp[maxm][maxm]; int match[maxm], mr[maxm]; bool vis[maxm]; bool check(int u) { for (int i = 1; i <= m; ++i) { if (imp[u][i]) continue; if (!vis[i]) { vis[i] = true; if (match[i] == -1 || check(match[i])) { match[i] = u; mr[u] = i; return true; } } } return false; } int main() { int T; for (scanf("%d", &T); T--; ) { memset(imp, 0, sizeof imp); scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) { scanf("%s%s", s[i] + 1, t[i] + 1); for (int j = 1; j <= m; ++j) for (int k = 1; k <= m; ++k) { if (s[i][j] != t[i][k]) imp[j][k] = true; } } int ans = 0; memset(match, -1, sizeof match); for (int i = m; i >= 1; --i) { memset(vis, 0, sizeof vis); if (check(i)) ++ans; } if (ans < m) puts("-1"); else { for (int i = 1; i <= m; ++i) { printf("%d%c", mr[i], " \n"[i == m]); } } } return 0; }