#include using namespace std; int T, n, m, ans[55]; bool to[55][55], chk[55], flag; char st[55], ed[55]; int main() { scanf("%d", &T); while (T--) { scanf("%d%d", &n, &m); memset(to, true, sizeof to); for (int i = 1; i <= n; i++) { scanf("%s", st + 1); scanf("%s", ed + 1); for (int j = 1; j <= m; j++) for (int k = 1; k <= m; k++) if (st[j] != ed[k]) to[j][k] = false; } memset(chk, false, sizeof chk); memset(ans, 0, sizeof ans); for (int i = 1; i <= m; i++) for (int j = 1; j <= m; j++) if (to[i][j] && !chk[j]) { chk[j] = true; ans[i] = j; break; } flag = true; for (int i = 1; i <= m; i++) if (ans[i] == 0) { flag = false; break; } if (!flag) puts("-1"); else for (int i = 1; i <= m; i++) printf("%d%c", ans[i], i == m? '\n' : ' '); } }