#include #include #include using namespace std; char in[30][60], out[30][60]; int T, N, M, ans[60], cnt[30]; bool used[60], flag; bool dfs(int x) { if (x > M) return 1; for (int i = 1; i <= M; ++i) if (!used[i]) { bool flag = 1; for (int j = 1; j <= N; ++j) if (in[j][x] != out[j][i]) { flag = 0; break; } if (flag) { used[i] = 1; ans[x] = i; if (dfs(x + 1)) { used[i] = 0; return 1; } used[i] = 0; } } return 0; } int main() { scanf("%d", &T); while (T--) { scanf("%d%d", &N, &M); flag = 1; for (int i = 1; i <= N; ++i) { scanf("%s%s", in[i] + 1, out[i] + 1); memset(cnt, 0, sizeof(cnt)); for (int j = 1; j <= M; ++j) { ++cnt[in[i][j] - 'a']; --cnt[out[i][j] - 'a']; } for (int j = 0; j < 26; ++j) if (cnt[j] != 0) { flag = 0; break; } } if (flag && dfs(1)) { printf("%d", ans[1]); for (int i = 2; i <= M; ++i) printf(" %d", ans[i]); printf("\n"); } else printf("-1\n"); } return 0; }