#include using namespace std; using LL = long long; #define FOR(i, x, y) for (decay::type i = (x), _##i = (y); i < _##i; ++i) #define FORD(i, x, y) for (decay::type i = (x), _##i = (y); i > _##i; --i) #ifdef zerol #define dbg(x...) do { cerr << "\033[32;1m" << #x << " -> "; err(x); } while (0) #else #define dbg(...) #endif // zerol void err() { cerr << "\033[39;0m" << endl; } template void err(T a, A... x) { cerr << a << ' '; err(x...); } // ---------------------------------------------------------------------------------------- const int N = 25, M = 55; int tr[M][M], vis[M], ans[M]; char s[M], t[M]; int main() { int T; scanf("%d", &T); while(T--) { int n, m; scanf("%d%d", &n, &m); FOR(i, 0, m) FOR(j, 0, m) tr[i][j] = 1; FOR(i, 0, m) vis[i] = 0; FOR(i, 0, n) { scanf("%s%s", s, t); FOR(j, 0, m) FOR(k, 0, m) if(s[j] != t[k]) tr[j][k] = 0; } bool ok = true; FOR(i, 0, m) { bool found = false; FOR(j, 0, m) if(!vis[j] && tr[i][j]) { vis[j] = 1; ans[i] = j; found = true; break; } if(!found) { ok = false; break; } } if(ok) { FOR(i, 0, m) printf("%d%c", ans[i]+1, i+1==m?'\n':' '); } else puts("-1"); } return 0; }