#include<iostream>
#include<stdio.h>
#include<cstdio>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<vector>
#include <unordered_map>
#include<climits>
#include<set>
#include <iomanip>
#include<numeric>
#include<queue>
#include<stack>

using namespace std;

#define ff              first
#define ss              second
#define ll              long long
#define ld              long double
#define pb              push_back
#define mp              make_pair
#define mt              make_tuple
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define mii             map<ll,ll>
#define pqb             priority_queue<ll>
#define pqs             priority_queue<ll,vi,greater<ll> >
#define mod             1000000007
#define inf             1e18
#define all(v)          (v).begin(),(v).end()
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl            "\n"

int main(){

    FIO ;
    int t ;
    t =1  ;
    cin >> t ;

    while(t--){
      ll n,m ;
      cin >> n >> m ;
      string arr[n] ; 
      for(int i = 0 ; i <n ; i++){
          cin >> arr[i] ; 
      } 
      bool ab = false ; 
      ll k1 = -1 ; 
      ll k2 = -1 ; 
      for(int i = 0 ; i < n ; i++){
          for(int j = 0 ; j < n ; j++){
              if(i == j){
                  continue ; 
              }
              if(arr[i][j] == arr[j][i]){
                  ab = true ; 
                  k1 = i +1 ; 
                  k2 = j+1 ; 
                  break ; 
              }
          }
          if(ab){
              break ; 
          }
      }
      if(ab){
          cout << "YES" << endl ; 
          for(int i = 0 ; i <= m ; i++){
              if(i%2){
                  cout << k1 << " " ; 
              }
              else{
                  cout << k2 << " "; 
              }
          }
          cout << endl ; 
          continue ; 
      }

      if(m%2){
          cout << "YES" << endl ; 
          for(int i = 0 ; i <= m ; i++){
              if(i%2){
                  cout << 1 << " " ; 
              }
              else{
                  cout << 2 << " " ; 
              }
          }
          cout << endl ; 
      }
      else{
          vi v1[n] ; 
          vi v2[n] ; 

          for(int i = 0 ; i < n ; i++){
              for(int j = 0 ; j < n ; j++){
                  if(i == j){
                      continue ; 
                  }
                  if(arr[i][j] == 'a'){
                      v1[i].pb(j) ; 
                  }
                  else{
                      v2[i].pb(j) ; 
                  }
              }
          }
          ll k3 = 0 ; 

          for(int i = 0 ; i < n ; i++){
              for(int j = 0 ; j < n ; j++){
                  if(i == j){
                      continue ; 
                  }

                  if(arr[i][j] == 'a'){
                      if(v1[j].size() > 0){
                          k1 = i + 1 ; 
                          k2 = j +1; 
                          k3 = v1[j][0] + 1 ; 
                          ab =true; 
                          break ; 
                      }
                  }
                  else{
                      if(v2[j].size() > 0){
                          k1 = i +1; 
                          k2 = j+1; 
                          k3 = v2[j][0]+1 ; 
                          ab =true; 
                          break ; 
                      }
                  }

              }
              if(ab){
                  break ; 
              }
          }

          if(!ab){
              cout << "NO" <<endl ; 
          }
          else{
              cout << "YES" << endl ;
              if((m/2)%2){
                  ll p = -1 ; 
                  for(int i = 0 ; i <= m ; i++){

                      if(p == -1){
                          cout << k1 << " " ; 
                          p =1 ; 
                      }
                      else if(p==1 || p== 0){
                          cout << k2 << " " ; 
                          if(p == 1){
                              p = 2 ; 
                          }
                          else{
                              p = -1 ; 
                          }
                          
                      }
                      else{
                          cout << k3 << " " ; 
                          p = 0 ; 
                      } 
                      
                  }

              }
              else{
                  ll p = 1 ; 
                  for(int i = 0 ; i <= m ; i++){
                      if(p == -1){
                          cout << k1 << " " ; 
                          p =1 ; 
                      }
                      else if(p==1 || p== 0){
                          cout << k2 << " " ; 
                          if(p == 1){
                              p = 2 ; 
                          }
                          else{
                              p = -1 ; 
                          }
                          
                      }
                      else{
                          cout << k3 << " " ; 
                          p = 0 ; 
                      } 

                  }


              } 
          }

      }






    }
    return 0 ;

}
