#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <iomanip>
 
using namespace std;
 
typedef long long LL;
typedef double DB;
 
const int MAXN = 1e3 + 15;
 
int a[MAXN][MAXN];
char ch[MAXN];
 
inline int read(){
	int r = 0, z = 1; char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-') z = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9'){r = r * 10 + ch - '0'; ch = getchar();}
	return r * z;
}
 
int main(){
	int T = read();
	while(T --){
		int n = read(), m = read();
		for(int i = 1; i <= n; i ++){
			scanf("%s", ch + 1);
			for(int j = 1; j <= n; j ++){
				if(i == j) continue;
				a[i][j] = ch[j] == 'a' ? 1 : 0;
			}
		}
		if(m % 2){
			puts("YES");
			for(int i = 1; i <= m + 1; i ++) printf("%d ", i % 2 ? 1 : 2);
			puts("");
			continue;
		}
		bool flag = 0; int x, y;
		for(int i = 1; i <= n; i ++){
			for(int j = i + 1; j <= n; j ++){
				if(a[i][j] == a[j][i]){flag = 1; x = i, y = j; break;}
			}
			if(flag) break;
		}
		if(flag){
			puts("YES");
			for(int i = 1; i <= m + 1; i ++) printf("%d ", i % 2 ? x : y);
			puts("");
			continue;
		}
		flag = 0; int z;
		for(int i = 1; i <= n; i ++){
			int aa = 0, bb = 0;
			for(int j = 1; j <= n; j ++){
				if(i == j) continue;
				if(a[i][j]) aa = j;
				else bb = j;
			}
			if(aa && bb){flag = 1; x = i, y = aa, z = bb; break;}
		}
		if(!flag){puts("NO"); continue;}
		puts("YES");
		if(m % 4 == 0){
			for(int i = 1; i <= m / 4; i ++) printf("%d %d %d %d ", x, y, x, z);
			printf("%d\n", x);
		}
		else {
			for(int i = 1; i <= m / 4; i ++) printf("%d %d %d %d ", y, x, z, x);
			printf("%d %d %d\n", y, x, z);
		}
	}
	return 0;
}
 		     	  		  					 	 			 	