#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
vector<string> v(n);
for(int i=0;i<n;i++)
cin>>v[i];
if(m%2==1)
{
cout<<"YES"<<endl;
for(int i=0;i<=m;i++)
{
if(i%2==0)
cout<<1<<" ";
else cout<<2<<" ";
}
cout<<endl;
continue;
}
int a=-1, b=-1;
bool x=0;
for(int i=0;i<n && x==0;i++)
{
for(int j=i+1;j<n;j++)
{
if(v[j][i]==v[i][j])
{
a=i;b=j;x=1;
break;
}
}
}
if(x==1)
{
cout<<"YES"<<endl;
for(int i=0;i<=m;i++)
{
if(i%2==0)
cout<<a+1<<" ";
else cout<<b+1<<" ";
}
cout<<endl;
continue;
}
if(n==2)
{
cout<<"NO"<<endl;
continue;
}
int c;
if(v[0][1] != v[0][2])
{
c=1;
a=2;
b=3;
}
else if(v[1][0]!=v[1][2])
{
c=2;
a=1;
b=3;
}
else{
c=3;
a=1;
b=2;
}
cout<<"YES"<<endl;
if(m%4==2)
cout<<a<<" ";
for(int i=0;i<(m-2)/4;i++)
{
cout<<c<<" "<<a<<" "<<c<<" "<<b<<" ";
}
cout<<c<<" ";
if(m%4==2)cout<<b;
cout<<endl;
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkKewoJaW50IHQ7CgljaW4+PnQ7Cgl3aGlsZSh0LS0pCgl7CgkJaW50IG4sbTsKCQljaW4+Pm4+Pm07CgkJdmVjdG9yPHN0cmluZz4gdihuKTsKCQlmb3IoaW50IGk9MDtpPG47aSsrKQoJCWNpbj4+dltpXTsKCQkKCQlpZihtJTI9PTEpCgkJewoJCQljb3V0PDwiWUVTIjw8ZW5kbDsKCQkJZm9yKGludCBpPTA7aTw9bTtpKyspCgkJCXsKCQkJCWlmKGklMj09MCkKCQkJCWNvdXQ8PDE8PCIgIjsKCQkJCWVsc2UgY291dDw8Mjw8IiAiOy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