#include <bits/stdc++.h>
using namespace std;
 
#define fastIO ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define endl '\n'
#define lli long long int
#define ld long double
#define p_b push_back
#define m_p make_pair
#define fs first
#define sc second
#define sz(x) ((lli)x.size())
#define all(x) x.begin(),x.end()
const lli mod = 1e9 + 7;
const lli N = 1e6 + 5;
/*****************************************************/
lli t,n,m,a[N]={0};
string s[1005];
int main()
{
    fastIO
    lli i,j,k,x,y,z;
    cin>>t;
    while(t--)
    {
        cin>>n>>m;
        for(i=0;i<n;i++)
            cin>>s[i];
        if(m%2!=0)
        {
            cout<<"YES\n";
            for(i=1;i<=m+1;i++)
                cout<<((i-1)%2)+1<<" ";
            cout<<endl;
            continue;
        }
        x=-1; y=-1;
        for(i=0;i<n;i++)
        {
            for(j=0;j<n;j++)
            {
                if(i==j)
                    continue;
                if(s[i][j]==s[j][i])
                    x=i, y=j;
            }
        }
        if(x!=-1 && y!=-1)
        {
            x++; y++;
            cout<<"YES\n";
            for(i=1;i<=m+1;i++)
                cout<<((i%2)?x:y)<<" ";
            cout<<endl;
            continue;
        }
        if(n==2)
        {
            cout<<"NO\n";
            continue;
        }
        cout<<"YES\n";
        vector<lli> v={0,1,2};
        do
        {
            x=v[0]; y=v[1]; z=v[2];
            if(s[x][y]!=s[y][z])
                continue;
            x++; y++; z++;
            if(m%4!=0)
            {
                for(i=1;i<=m/2;i++)
                    cout<<((i%2)?x:y)<<" ";
                cout<<y<<" ";
                for(i=1;i<=m/2;i++)
                    cout<<((i%2)?z:y)<<" ";
            }
            else
            {
                for(i=1;i<=m/2;i++)
                    cout<<((i%2)?y:z)<<" ";
                cout<<y<<" ";
                for(i=1;i<=m/2;i++)
                    cout<<((i%2)?x:y)<<" ";
            }
            break;

        }while(next_permutation(all(v)));
    }
    // cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
    return 0;
}