#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
#include<set>
#include<cstring>
#include<string>
#include<algorithm>
#define fi first
#define se second
//#include<stdlib.h>
//#include <time.h>
//srand((unsigned)time(NULL));
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
using namespace std;
const int N = 1e5 + 10;
char a[1010][1010];
int cnt_r[1010][2];
int cnt_c[1010][2];
int n, m;
int x, y, z;
bool get(int status) {
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j < i; j++) {
            if (status == 1) {
                if (a[i][j] == a[j][i]) {
                    x = i; y = j;
                    return true;
                }
            }
            else {
                if (a[i][j] != a[j][i]) {
                    x = i; y = j;
                    return true;
                }
            }
        }
    }
    return false;
}
int ans[2] = {0};
void print(int st, int cnt) {
    int pos = st;
    for (int i = 1; i <= cnt; i++) {
        printf("%d ", ans[pos]);
        pos ^= 1;
    }
}
int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
        scanf("%d%d", &n, &m);
        for (int i = 1; i <= n; i++) {
            scanf("%s", a[i] + 1);
            cnt_r[i][0] = cnt_r[i][1] = 0;
            cnt_c[i][0] = cnt_c[i][1] = 0;
        }
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if (a[i][j] == 'a') {
                    cnt_r[i][0]++;
                    cnt_c[j][0]++;
                }
                else if (a[i][j] == 'b'){
                    cnt_r[i][1]++;
                    cnt_c[j][1]++;
                }
            }
//            printf("%d %d\n", cnt_r[i][0], cnt_r[i][1]);
        }
        if (m & 1) {
            if (get(1)) ans[0] = x, ans[1] = y;
            else if (get(0)) ans[0] = x, ans[1] = y;
        }
        else {
            if (get(1)) ans[0] = x, ans[1] = y;
            else {
                int half = m / 2;
                if (!(half & 1)) { //偶数
                    bool f = false;
                    int r = -1;
                    for (int i = 1; i <= n && !f; i++) {
                        if (cnt_r[i][0] == 0 || cnt_r[i][1] == 0)
                            continue;
                        r = i; f = true;
                    }
                    if (f) {
                        for (int j = 1; j <= n; j++) {
                            if (a[r][j] != '*') {
                                x = r, y = j;
                                break;
                            }
                        }
                        for (int j = y + 1; j <= n; j++) {
                            if (j != r && a[r][j] != a[x][y]) {
                                z = j;
                                break;
                            }
                        }
                        printf("YES\n");
                        ans[0] = x; ans[1] = y;
                        print(0, m / 2);
                        ans[1] = z;
                        print(0, m / 2 + 1);
                        printf("\n");
                        continue;
                    }
                    else {
                        printf("NO\n");
                        continue;
                    }
                }
                else { //奇数
//                    printf("----\n");
                    bool f = false;
                    for (int i = 1; i <= n && !f; i++) {
                        for (int j = 1; j <= n && !f; j++) {
                            if (i == j) continue;
                            int s = a[i][j] - 'a';
                            if (cnt_r[j][s] != 0) {
                                f = true;
                                x = i, y = j;
                                for (int k = 1; k <= n; k++) {
                                    if (a[j][k] == a[x][y]) {
                                        z = k;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    if (f) {
                        printf("YES\n");
//                        cout << x << y << z << "\n";
                        ans[0] = x, ans[1] = y;
                        print(0, m / 2);
                        ans[0] = y; ans[1] = z;
                        print(0, m / 2 + 1);
                        printf("\n");
                    }
                    else printf("NO\n");
                    continue;
                }
            }
        }
        printf("YES\n");
        print(0, m + 1);
        printf("\n");
    }
    return 0;
}

