#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define REP(i, a, b) for(int i = a; i >= b; i--)

using namespace std;

#define x first 
#define y second

typedef long long i64;
typedef pair <int, int> ii;

const int N = 5e3 + 5;
const i64 inf = 2e18;

int m, n;
char s[N][N];
int f[N][N];

void solve() {
    cin >> n >> m;
    FOR(i, 1, n) cin >> s[i] + 1;
    FOR(i, 1, n)
        FOR(j, 0, 25) f[i][j] = -1;
    FOR(i, 1, n) 
        FOR(j, 1, n) {
            if(i == j) continue;
            f[i][s[i][j] - 'a'] = j;
            if(s[i][j] == s[j][i]) {
                cout << "YES" << '\n';
                FOR(k, 1, m + 1)
                    if(k & 1) cout << i << ' ';
                    else cout << j << ' ';
                cout << '\n';
                return; 
            }
        }
    
    if(m & 1) {
        cout << "YES" << '\n';
        FOR(i, 1, m + 1)
            if(i & 1) cout << 1 << ' ';
            else cout << 2 << ' ';
        cout << '\n';
        return;
    }

    int u = 0, v = 0, w = 0;
    FOR(i, 1, n) {
        FOR(j, 1, n) {
            if(i == j) continue;
            if(f[i][s[j][i] - 'a'] != -1) {
                u = j;
                v = i;
                w = f[i][s[j][i] - 'a'];
            }
        }
    }

    if(u == 0 || v == 0 || w == 0) {
        cout << "NO" << '\n';
        return;
    }

    cout << "YES" << '\n';

    if((m / 2) % 2) {
        FOR(i, 1, m + 1) {
            if(i % 4 == 1) cout << u << ' ';
            else if(i % 4 == 3) cout << w << ' ';
            else cout << v << ' ';
        }
        cout << '\n';
    } else {
        FOR(i, 1, m + 1) {
            if(i <= m / 2) {
                if(i & 1) cout << v << ' ';
                else cout << u << ' ';
            } else {
                if(i & 1) cout << v << ' ';
                else cout << w << ' ';
            }
        }
        cout << '\n';
    }
}

int main() {
    //freopen(".inp", "r", stdin);

    int ntest;
    cin >> ntest;
    while(ntest--) solve();
}