#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
const int N = 1e6 + 10;
const int M = 5e5 + 10;
const int INF = 0x3f3f3f3f;
const double eps = 1e-4;
const int MOD = 1e9+7;
typedef long long ll;
typedef pair<int, int> PII;
char mp[1005][1005];
int main() {
    int T; 
	cin >> T;
	while (T--) 
	{
        int n, m;
		cin >> n >> m;
        for (int i = 1; i <= n; i++) cin >> mp[i] + 1;
        if (m & 1) 
		{
            cout << "YES" << endl;
            for (int i = 1; i <= m+1; i++) cout << i % 2 + 1 << " ";
            cout << endl;
            continue;
        }
        if (n == 2) 
		{
            if (mp[1][2] == mp[2][1]) 
			{
                cout << "YES" << endl;
                for (int i = 1; i <= m+1; i++) cout << i % 2 + 1 << " ";
                cout << endl;
            }
			else cout << "NO" << endl;
        } 
		else 
		{
            cout << "YES" << endl;
            int flag;
            if (mp[1][2] == mp[2][3]) flag = 1;
            else if (mp[3][1] == mp[1][2]) flag = 0;
            else flag = 2;
            for (int i = 0; i <= m; i++) cout << (flag + i + m) % 3 + 1 << " ";
            cout << endl;
        }
    }
}



