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

using ll = long long;

const int maxn=1e3+5;
int tt;
int n,m,a[maxn][2];
char c[maxn][maxn];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> tt;
	while(tt--){
		cin >> n >> m;
		for(int	 i = 1;i <= n;i++) for(int j = 1;j <= n;j++) cin >> c[i][j];
		pair<int,int>cyc={-1,-1};
		for(int i = 1;i <= n;i++){
			for(int j = 1;j <= n;j++){
				if(i != j and c[i][j] == c[j][i]) cyc={i,j};
			}
		}
		if(cyc == make_pair(-1,-1) and m % 2) cyc={1,2}; 
		if(cyc != make_pair(-1,-1)){
			cout<<"YES\n";
			int nw = 0;
			for(int i = 0;i < m + 1;i++){
				if(nw % 2) cout<<cyc.first<<' ';
				else cout<<cyc.second<<' ';
				nw ^= 1;
			}
			cout<<'\n';
			continue;
		}
		for(int i = 1;i <= n;i++){
			a[i][0] = a[i][1] = -1;
			for(int j = 1;j <= n;j++){
				if(i == j) continue;
				if(c[i][j] == 'a') a[i][0] = j;
				else a[i][1] = j;
			}
		}

		int tr = 1,p[3];
		for(int i = 1;i <= n;i++){
			for(int j = 1;j <= n;j++){
				if(i == j) continue;
				if(c[i][j] == 'a' and a[j][0] != -1) tr=0,p[0]=i,p[1]=j,p[2]=a[j][0];
				if(c[i][j] == 'b' and a[j][1] != -1) tr=0,p[0]=i,p[1]=j,p[2]=a[j][1];
			}
		}
		if(tr) cout<<"No\n";
		else {
			cout<<"Yes\n";
			int nw;
			if((m/2) % 2) nw = 0;
			else nw = 1;
			int git = 0;
			for(int i = 0;i < m + 1;i++){
				cout<<p[nw]<<' ';
				
				if(git==0) nw++;
				else nw--;
				
				if(nw == -1) git = 0,nw = 1;
				if(nw == 3) git = 1,nw = 1;
			}
			cout<<'\n';
		}
	}
}