#include <iostream>
#include <cstring>
#define fast ios::sync_with_stdio(false);cin.tie(0);

using namespace std;
int t, n, m;
char g[1002][1002];
int mp[1002][2];

int main()
{
    cin >> t;
    while(t --)
    {
        memset(mp, -1, sizeof mp);
        cin >> n >> m;
        for (int i = 1; i <= n; i ++)
            for (int j = 1; j <= n; j ++)
                cin >> g[i][j];

        if (m % 2 == 1)
        {
            puts("YES");
            for (int i = 0; i <= m; i ++)
                cout << i % 2 + 1 << ' ';
            puts("");
        }
        else
        {
            int success = 0;
            for (int i = 1; i <= n && !success; i ++)
                for (int j = 1; j <= n; j ++)
                {
                    if (i == j) continue;
                    if (g[i][j] == g[j][i])
                    {
                        success = 1;
                        puts("YES");
                        for (int k = 0; k <= m; k ++)
                            if (k % 2 == 0) cout << i << ' ';
                            else cout << j << ' ';
                        puts("");
                        break;
                    }
                    mp[i][g[i][j] - 'a'] = j;
                }
            if (!success && n >= 3)
            {
                for (int i = 1; i <= n && !success; i ++)
                    for (int j = 1; j <= n; j ++)
                    {
                        if (i == j) continue;
                        if (mp[j][g[i][j] - 'a'] != -1)
                        {
                            puts("YES");
                            int c = mp[j][g[i][j] - 'a'];
                            success = 1;
                            if (m % 4 == 0)
                            {
                                for (int k = 0; k <= m / 2; k ++)
                                    if (k % 2 == 0) cout << j << ' ';
                                    else cout << i <<  ' ';
                                for (int k = 0; k < m / 2; k ++)
                                    if (k % 2 == 0) cout << c << ' ';
                                    else cout << j << ' ';
                                puts("");
                            }
                            else
                            {
                                for (int k = 0; k <= m; k ++)
                                    if (k % 4 == 0) cout << i << ' ';
                                    else if (k % 4 == 2)    cout << c << ' ';
                                    else cout << j << ' ';
                                puts("");
                            }
                            break;
                        }
                    }
            }
            else if (!success)
                puts("NO");
        }
    }
    return 0;
}
