#include <iostream>

int main() {
    int t; std::cin >> t;
    while (t--) {
        int n, m; std::cin >> n >> m;
        char edges[3][3];
        for (int i = 0; i != n; ++i) {
            for (int j = 0; j != n; ++j) {
                char ch; std::cin >> ch;
                if (i < 3 && j < 3) { edges[i][j] = ch; }
            }
        }

        if (m % 2 == 1) {
            std::cout << "YES\n";
            for (int i = 0; i != m + 1; ++i) {
                std::cout << (i % 2) + 1 << (i == m ? '\n' : ' ');
            }
            continue;
        }

        if (n == 2) {
            if (edges[0][1] == edges[1][0]) {
                std::cout << "YES\n";
                for (int i = 0; i != m; i += 2) {
                    std::cout << 1 << ' ' << 2 << ' ';
                }
                std::cout << "1\n";
            }
            else { std::cout << "NO\n"; }
            continue;
        }

        std::cout << "YES\n";
        int u = -1, v = -1, w = -1;

        if (edges[0][1] == edges[1][0]) { u = 1; v = 2; }
        else if (edges[0][2] == edges[2][0]) { u = 1; v = 3; }
        else if (edges[1][2] == edges[2][1]) { u = 2; v = 3; }
        if (u > 0) {
            for (int i = 0; i != m; i += 2) {
                std::cout << u << ' ' << v << ' ';
            }
            std::cout << u << '\n';
            continue;
        }

        if (m % 4 == 0) {
            if (edges[0][1] != edges[0][2]) { u = 1; }
            else if (edges[1][0] != edges[1][2]) { u = 2; }
            else { u = 3; }
            v = (u % 3) + 1;
            w = (v % 3) + 1;
            for (int i = 0; i != m; i += 4) {
                std::cout << u << ' ' << v << ' ' << u << ' ' << w << ' ';
            }
            std::cout << u << '\n';
        } else {
            if (edges[2][0] == edges[0][1]) { u = 1; }
            else if (edges[0][1] == edges[1][2]) { u = 2; }
            else { u = 3; }
            v = (u % 3) + 1;
            w = (v % 3) + 1;
            for (int i = 2; i != m; i += 4) {
                std::cout << w << ' ' << u << ' ' << v << ' ' << u << ' ';
            }
            std::cout << w << ' ' << u << ' ' << v << '\n';
        }
    }
}
