#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>

using namespace std;

const int N = 1010;

int T, n, m, has[N][2];
char s[N][N];

void solve()
{
    if (m & 1) {
        printf("YES\n");
        for (int i = 1; i <= (m + 1) / 2; i++) {
            printf("1 2");
            printf(i == (m + 1) / 2 ? "\n" : " ");
        }
        return;
    }
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            if (s[i][j] == s[j][i]) {
                printf("YES\n");
                for (int k = 1; k <= m + 1; k++) {
                    if (k & 1) printf("%d", i);
                    else printf("%d", j);
                    printf(k == m + 1 ? "\n" : " ");
                }
                return;
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (i == j) continue;
            if (-1 == has[j][s[i][j] - 'a']) continue;
            printf("YES\n");
            int nex = has[j][s[i][j] - 'a'];
            if ((m / 2) & 1) {
                printf("%d", i);
                for (int k = 1; k <= m / 2; k++) {
                    if (k & 1) printf(" %d %d", j, nex);
                    else printf(" %d %d", j, i);
                }
                printf("\n");
                return;
            }
            else {
                printf("%d", j);
                for (int k = 1; k <= m / 2; k++) {
                    if (k & 1) printf(" %d %d", nex, j);
                    else printf(" %d %d", i, j);
                }
                printf("\n");
            }
            return;
        }
    }
    printf("NO\n");
    return;
}

int main()
{
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    scanf("%d", &T);
    while (T--) {
        scanf("%d%d", &n, &m);
        for (int i = 1; i <= n; i++) has[i][0] = has[i][1] = -1;
        for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if (i == j) continue;
                has[i][s[i][j] - 'a'] = j;
            }
        }
        solve();
    }
    return 0;
}