#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll t = 1,n,m,a[1009][1009],cnt[1009][2],c,u,v,x,y,z;
string s;
int main(){cin>>t;
while (t --){
	cin>>n>>m; ll f = 0;
	for (ll i = 1;i <= n;i += 1){
		cin>>s,cnt[i][0] = cnt[i][1] = 0;
		for (ll j = 1;j <= n;j += 1) if (i ^ j) a[i][j] = s[j - 1] - 'a',cnt[i][a[i][j]] += 1;
	}
	for (ll i = 1;i <= n && !f;i += 1) for (ll j = i + 1;j <= n;j += 1){
		if (a[i][j] == a[j][i]){
			cout<<"YES"<<endl;
			for (ll k = 0;k < m + 1;k += 1){if (k & 1) cout<<i<<' '; else cout<<j<<' ';} cout<<endl; f = 1; break;
		}
	}
	if (!f){
		if (m & 1){
			cout<<"YES"<<endl;
			for (ll k = 0;k < m + 1;k += 1){if (k & 1) cout<<1<<' '; else cout<<2<<' ';} cout<<endl; f = 1;
		}
	}
	if (!f){
		m /= 2;
		if (m & 1){
			for (ll i = 1;i <= n && !f;i += 1) for (ll j = 1;j <= n;j += 1) if (i ^ j){
				if ((a[i][j] == 0 && cnt[j][0]) || (a[i][j] == 1 && cnt[j][1])){
					cout<<"YES"<<endl;
					for (ll k = 0;k < (m + 1) / 2;k += 1) cout<<i<<' '<<j<<' ';
					for (ll l = 1;l <= n;l += 1) if ((j ^ l) && ((a[i][j] == 0 && cnt[j][0]) ? a[j][l] == 0 : a[j][l] == 1)){
						for (ll k = 0;k < m / 2;k += 1) cout<<l<<' '<<j<<' ';
						cout<<l;
						break;
					}
					cout<<endl;
					f = 1;
					break;
				}
			}
		}
		else{
			for (ll i = 1;i <= n;i += 1){
				if (cnt[i][0] && cnt[i][1]){
					cout<<"YES"<<endl<<i<<' ';
					for (ll j = 1;j <= n;j += 1) if ((i ^ j) && a[i][j] == 0){
						for (ll k = 0;k < m / 2;k += 1) cout<<j<<' '<<i<<' ';
						break;
					}
					for (ll j = 1;j <= n;j += 1) if ((i ^ j) && a[i][j] == 1){
						for (ll k = 0;k < m / 2;k += 1) cout<<j<<' '<<i<<' ';
						break;
					}
					cout<<endl;
					f = 1;
					break;
				}
			}
		}
	}
	if (!f) cout<<"NO"<<endl;
}
	return 0;
}