#include using namespace std; int t, p[123], vis[123], n, m; char a[123][123], b[123][123]; bool chk() { for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) if (p[j] && a[i][j] != b[i][p[j]]) return 0; return 1; } int main() { scanf("%d", &t); while (t--) { scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) { scanf("%s%s", a[i] + 1, b[i] + 1); } for (int i = 1; i <= m; ++i) vis[i] = p[i] = 0; bool fd = 1; for (int i = 1; i <= m; ++i) { for (int j = 1; j <= m; ++j) if (!vis[j]) { p[i] = j; if (chk()) { vis[j] = 1; break; } p[i] = 0; } if (!p[i]) { fd = 0; break; } } if (!fd) printf("-1\n"); else { for (int i = 1; i <= m; ++i) printf("%d%c", p[i], " \n"[i == m]); } } }