#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const int inf=1000000010;
const ll INF=1000000000000001000LL;
const int mod=1000000007;
const int MAXN=1010, LOG=20;

int n, m, k, u, v, x, y, t, a, b, ans;
char A[MAXN][MAXN], curr;
int deg[MAXN], P[MAXN], mark[MAXN];
vector<int> path;

bool dfs(int node){
	if (mark[node]==2) return 0;
	if (mark[node]==1){
//		debugv(path)
//		debug(node)
		mark[node]=2;
		reverse(all(path));
		while (path.back()!=node) path.pop_back();
		reverse(all(path));
		return 1;
	}
	mark[node]=1;
	path.pb(node);
	for (int v=1; v<=n; v++) if (A[node][v]==curr && dfs(v)) return 1;
	mark[node]=2;
	path.pop_back();
	return 0;
}

int Solve(){
	cin>>n>>m;
	for (int i=1; i<=n; i++) deg[i]=0, P[i]=i;
	for (int i=1; i<=n; i++) for (int j=1; j<=n; j++){
		cin>>A[i][j];
		if (A[i][j]=='a') deg[j]++;
	}
	for (char ch:"ab"){
		path.clear();
		for (int i=1; i<=n; i++) mark[i]=0;
		curr=ch;
		for (int i=1; i<=n; i++) if (dfs(i)){
			int sz=path.size();
			cout<<"YES\n";
			for (int j=0; j<=m; j++) cout<<path[j%sz]<<" ";
			cout<<"\n";
			return 0;
		}
	}
	sort(P+1, P+n+1, [](int i, int j){
		return deg[i]<deg[j];
	});
//	for (int i=1; i<=n; i++) debug2(i, deg[i])
//	for (int i=1; i<=n; i++) debug2(i, P[i])
	for (int i=1; i<=n; i++) for (int j=i+1; j<=n; j++){
		assert(A[P[i]][P[j]]=='a');
		assert(A[P[j]][P[i]]=='b');
	}
	if (m<n){
		cout<<"YES\n";
		for (int i=1; i<=m+1; i++) cout<<P[i]<<" ";cout<<"\n";
		return 0;
	}
	if (m&1){
		cout<<"YES\n";
		for (int i=1; i<=m+1; i++) cout<<1+(i&1)<<" ";cout<<"\n";
		return 0;
	}
	if (n<=2) kill("NO")
	m>>=1;
	if (m&1){
		cout<<"YES\n";
		for (int i=0; i<=m; i++) cout<<P[1+(i&1)]<<" ";
		for (int i=1; i<=m; i++) cout<<P[2+(i&1)]<<" ";
		cout<<"\n";
		return 0;
	}
	cout<<"YES\n";
	for (int i=0; i<=m; i++) cout<<P[2+(i&1)]<<" ";
	for (int i=0; i<m; i++) cout<<P[1+(i&1)]<<" ";
	cout<<"\n";
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int T;
	cin>>T;
	while (T--) Solve();
	
	return 0;
}
/*
1
3 6
*aa
b*a
bb*

1
3 8
*aa
b*a
bb*


1
4 6
*aaa
b*ba
ab*a
bba*

*/
