#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<set<ll> > v1(100005), v2(100005);
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin >> t;
    while(t--)  {
        ll n, m;
        cin >> n >> m;
        char arr[n][n];
        for(int i = 0; i < n; i++)  {
            for(int j = 0; j  < n; j++) {
                cin >> arr[i][j];
            }
        }
        if(m%2 == 1)    {
            cout << "YES" << "\n";
            for(int i = 0; i <= m/2; i++)   {
                cout << "1 2 ";
            }
            cout << "\n";
            continue;
        }
        pair<ll, ll> p = {-1, -1}, p2 = {-1, -1}, p3 = {-1, -1};
        for(int i = 0; i < n; i++)  {
            ll flag1 = -1, flag2 = -1;
            for(int j = 0; j < n; j++)  {
                if(i == j)  {
                    continue;
                }
                if(arr[i][j] == arr[j][i])  {
                    p = {i, j};
                    //break;
                }
                if(arr[i][j] == 'a' && arr[j][i] == 'b' && flag1 == -1)   {
                    flag1 = j;
                }
                if(arr[i][j] == 'b' && arr[j][i] == 'a' && flag2 == -1) {
                    flag2 = j;
                }
            }
            if(flag1 != -1 && flag2 != -1)  {
                p2 = {i, flag1};
                p3 = {i, flag2};
            }
        }
        if(p.first != -1)   {
            cout << "YES" << "\n";
            for(int i = 0; i < m/2; i++)    {
                cout <<  p.first+1 << " "  << p.second+1 << " ";
            }
            cout << p.first+1 <<  " ";
            cout << "\n";
        }
        else if(n < 3)  {
            cout << "NO" << "\n";
        }
        else    {
            if(m%4 == 0)    {
                if(p2.first != -1)  {
                    cout << "YES" << "\n";
                    for(int i = 0; i < m/4; i++)    {
                        cout << p2.first+1 << " " << p2.second+1 << " ";
                    }
                    cout << p2.first +1  << " ";
                    for(int i = 0; i < m/4; i++)    {
                        cout << p3.second+1 << " " << p3.first+1 << " ";
                    }
                    //cout << p2.first +1  << " ";
                    cout << "\n";
                    
                } 
                else    {
                    cout << "NO"  << "\n";
                        }
            }
            else    {
                cout << "YES" << "\n";
                cout << p2.second+1 << " ";
                for(int i = 0; i < m/4; i++)  {
                    cout << p2.first+1 << " " << p3.second+1 << " " << p3.first+1 << " " << p2.second+1 << " ";
                }
                cout << p2.first + 1 << " "  << p3.second+1 << "\n";
            }
        }
        
    }
}