#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define ll long long
#define per(i, b, a) for(int i = b; i >= a; --i)
using namespace std;
const int maxn = 1145;
int ed[maxn][maxn];
int n, m;
void solve()
{
    if(n == 2)
    {
        if((m & 1) || ed[1][2] == ed[2][1])
        {
            cout << "YES" << endl;
            rep(i, 1, m + 1) cout << (i % 2 + 1) << " ";
            cout << endl;
            return;
        }
        cout << "NO" << endl;
        return;
    }
    cout << "YES" << endl;
    int node[3] = {1, 2, 3};// u -> v -> w -> u
    while(ed[node[0]][node[1]] != ed[node[1]][node[2]]) swap(node[0], node[1]), swap(node[1], node[2]);
    int base = m % 3;
    rep(i, 1, m + 1)
        cout << node[(i + base) % 3] << " ";
    cout << endl;
}
int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    int T; cin >> T;
    rep(kase, 1, T)
    {
        cin >> n >> m;
        rep(i, 1, n)
        {
            string s; cin >> s;
            rep(j, 1, n)
                (ed[i][j] = (s[j - 1] == 'a' ? 1 : 0));
        }
        solve();
    }
    return 0;
}

				 	 	   	 	 	  		  	  					