#include using namespace std; int f[55][55]; int p[55]; char a[60], b[60]; bool vis[55]; int main() { int T, n, m; scanf("%d", &T); while (T--) { memset(f, 0, sizeof(f)); scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) { scanf(" %s %s", a + 1, b + 1); for (int j = 1; j <= m; j++) { for (int k = 1; k <= m; k++) { if (a[j] == b[k]) { f[j][k]++; } } } } memset(vis, false, sizeof(vis)); bool check = true; for (int i = 1; i <= m; i++) { p[i] = -1; for (int j = 1; j <= m; j++) { if (vis[j]) continue; if (f[i][j] == n) { p[i] = j; vis[j] = true; break; } } if (p[i] == -1) check = false; } if (!check) printf("-1\n"); else { printf("%d", p[1]); for (int i = 2; i <= m; i++) printf(" %d", p[i]); printf("\n"); } } return 0; }