#include<iostream>
using namespace std;

int graph[1003][1003];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T;
	cin>>T;
	int n,m;
	while(T--){
		cin>>n>>m;
		char c;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				cin>>c;
				graph[i][j] = c=='a';
			}
		}
		if(m %2){
			cout<<"YES\n";
			for(int i=0;i<=m/2;i++){
				cout<<1<<' '<<2<<' ';
			}
			cout<<'\n';
		}
		else if(n == 2){
			if(graph[1][2] == graph[2][1]){
				cout<<"YES\n";
				for(int i=0;i<m/2;i++){
					cout<<1<<' '<<2<<' ';
				}
				cout<<1<<'\n';
			}
			else{
				cout<<"NO\n";
			}
		}
		else{
			cout<<"YES\n";
			bool flag = false;
			for(int i=1;i<=n;i++){
				for(int j=i+1;j<=n;j++){
					if(graph[i][j] == graph[j][i]){
						cout<<i<<" ";
						for(int k=0;k<m/2;k++){
							cout<<j<<" "<<i<<" ";
						}
						cout<<'\n';
						flag = true;
						break;
					}
				}
				if(flag){
					break;
				}
			}
			if(flag){
				continue;
			}
			int k = 0;
			if(graph[2][1] != graph[3][1]){
				k = 0;
			}
			else if(graph[1][2] != graph[3][2]){
				k = 1;
			}
			else{
				k = 2;
			}
			if( m %4 == 0){
				cout<<k+1<<" ";
				for(int i=0;i<m/4;i++){
					cout<<(k+1)%3+1<<" "<<k+1<<" "<<(k+2)%3+1<<" "<<k+1<<" ";
				}
				cout<<'\n';
			}
			else{
				cout<<(k+1)%3+1<<" "<<k+1<<" ";
				for(int i=0;i<m/4;i++){
					cout<<(k+1)%3+1<<" "<<k+1<<" "<<(k+2)%3+1<<" "<<k+1<<" ";
				}
				cout<<(k+2)%3+1<<'\n';
			}
		}
	}
	return 0;
}
