#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define rrep(i,n) for(int i = int(n)-1; i >= 0; i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
template<class T> bool chmax(T &a, const T &b) {if(a < b) {a = b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b) {if(b < a) {a = b; return true;} return false;}
int dx[] = {1, 0,-1, 0, 1, 1,-1,-1};
int dy[] = {0, 1, 0,-1, 1,-1, 1,-1};
ll mod = 998244353;
ll MOD = 1000000007;
ll inf = 1001001001;
ll INF = 1001001001001001001;
char dist[1005][1005];
int main() {
    int t;
    cin >> t;
    while (t--) {
        int n,m;
        cin >> n >> m;
        rep(i,n) {
            string s;
            cin >> s;
            rep(j,n) {
                dist[i][j] = s[j];
            }
        }
        int x = -1,y = -1;
        rep(i,n) {
            rep(j,n) {
                if(i == j) {
                    continue;
                }
                if(dist[i][j] == dist[j][i]) {
                    x = i;y = j;
                }
            }
        }
        if(x != -1) {
            cout << "YES" << endl;
            rep(i,m+1) {
                cout << ((i%2)?x+1:y+1) << ((i == m)?"\n":" ");
            }
        }
        else {
            if(m%2 == 1) {
                cout << "YES" << endl;
                rep(i,m+1) {
                    cout << ((i%2)?1:2) << ((i == m+1)?"\n":" ");
                }
            }
            else {
                if(n == 2) {
                    cout << "NO" << endl;
                }
                else {
                    cout << "YES" << endl;
                    int X = -1,Y = -1,Z = -1;
                    rep(i,3) {
                        rep(j,3) {
                            rep(k,3) {
                                if(i != j && j != k && i != k) {
                                    if(dist[i][j] == dist[j][k]) {
                                        X = i+1;Y = j+1;Z = k+1;
                                    }
                                }
                            }
                        }
                    }
                    if(m%4 == 0) {
                        cout << Y;
                        rep(i,m) {
                            cout << " ";
                            if(i%4 == 0) {
                                cout << X;
                            }
                            if(i%4 == 1) {
                                cout << Y;
                            }
                            if(i%4 == 2) {
                                cout << Z;
                            }
                            if(i%4 == 3) {
                                cout << Y;
                            }
                        }
                        cout << endl;
                    }
                    else {
                        cout << Z << " " << Y;
                        rep(i,m-1) {
                            cout << " ";
                            if(i%4 == 0) {
                                cout << X;
                            }
                            if(i%4 == 1) {
                                cout << Y;
                            }
                            if(i%4 == 2) {
                                cout << Z;
                            }
                            if(i%4 == 3) {
                                cout << Y;
                            }
                        }
                        cout << endl;
                    }
                }
            }
        }
    }
}
