#include <bits/stdc++.h>
using namespace std;

const int N = 1001;
string a[N];
int n, m;

int main()
{
    int t; cin >> t;
    mt19937 rd;
    rd.seed(chrono::high_resolution_clock::now().time_since_epoch().count());
    while (t--) 
    {
        cin >> n >> m;
        for (int i=1; i<=n; ++i) 
        {
            cin >> a[i];
            a[i] = " " + a[i];
        }
        if (m % 2 == 1) 
        {
                cout << "YES\n";
                for (int i=0; i<=m; ++i) 
                {
                    cout << i % 2 + 1 << ' ';
                }
                cout << '\n';
        }
        else 
        {
            bool ok = 0;
            for (int i=1; i<=n; ++i) 
            {
                for (int j=i+1; j<=n; ++j) 
                {
                    if (a[i][j] == a[j][i]) 
                    {
                        ok = 1;
                        cout << "YES\n";
                        for (int iz=0; iz<m; iz += 2) 
                        {
                            cout << i << ' ' << j << ' ';
                        }
                        cout << i << ' ';
                        cout << '\n';
                        break;
                    }
                    if (ok) break;
                }
                if (ok)  break;
            }
            if (!ok) 
            {
                int x, y, z;

                vector< vector < vector< int > > > iy, oy;
                iy = {{}}; oy = {{}};
                for (y = 1; y <= n; ++y) 
                {
                    iy.push_back(vector<vector<int > > (2, vector<int> ()));
                    oy.push_back(vector<vector<int > > (2, vector<int> ()));
                    for (x = 1; x <= n; ++ x) 
                    {
                        if (x != y) 
                        {
                            iy[y][a[x][y] - 'a'].push_back(x);
                            oy[y][a[y][x] - 'a'].push_back(x);
                        }
                    }
                }

                for (y=1; y<=n; ++y)
                {
                    if (iy[y][0].size() && oy[y][0].size()) 
                    {
                        x = iy[y][0][0];
                        z = oy[y][0][0];
                    }
                    else if (iy[y][1].size() && oy[y][1].size()) 
                    {
                        x = iy[y][1][0];
                        z = oy[y][1][0];
                    }
                    else 
                        continue;
                    if (x != y && y != z) 
                    {
                        if (a[x][y] == a[y][z]) 
                        {
                            cout << "YES\n";
                            ok = 1;
                            int cc = (m - 2) / 2;
                            if (cc % 2 == 1) cout << y << ' ';
                            for (int i =cc / 2; i > 0; --i) 
                                cout << x << ' ' << y << ' ';
                            cout << x << ' ' << y << ' ' << z << ' ';
                            for (int i =cc / 2; i > 0; --i) 
                                cout << y << ' ' << z << ' ';
                            if (cc % 2 == 1) 
                                cout << y << '\n';
                            break;
                        }
                    }
                    if (ok) break;
                }
                
            }
            if (!ok) 
            {
                cout << "NO\n";
            }
        }
    }
}