#include <iostream>

using namespace std;

char board[1000][1000];

struct Node {
  bool ai, bi, ao, bo;
};

Node ab[1000];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int t;
  cin >> t;

  while(t --) {
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; ++ i) {
      for(int j = 0; j < n; ++ j) {
	cin >> board[i][j];
      }
    }

    if(m == 1) {
      cout << "YES\n1 2\n";
      goto done;
    }
    
    for(int i = 0; i < n; ++ i) {
      for(int j = i + 1; j < n; ++ j) {
	if(board[i][j] == board[j][i]) {
	  cout << "YES\n";
	  for(int mi = 0; mi <= m; ++ mi) {
	    cout << (mi % 2 ? i + 1 : j + 1) << ' ';
	  }
	  cout << '\n';
	  goto done;
	}
      }
    }

    if(m % 2 == 1) {
      cout << "YES\n";
      for(int mi = 0; mi <= m; ++ mi) {
	cout << (mi % 2 ? 1 : 2) << ' ';
      }
      cout << '\n';
      goto done;
    }

    for(int i = 0; i < n; ++ i) {
      ab[i].ai = ab[i].bi = ab[i].ao = ab[i].bo = false;
    }

    for(int i = 0; i < n; ++ i) {
      for(int j = 0; j < n; ++ j) {
	if(i != j) {
	  if(board[i][j] == 'a') {
	    ab[i].ao = true;
	    ab[j].ai = true;
	  } else {
	    ab[i].bo = true;
	    ab[j].bi = true;
	  }
	}
      }
    }

    for(int i = 0; i < n; ++ i) {
      char ch = '-';
      if(ab[i].ao && ab[i].ai) {
        ch = 'a';
      } else if(ab[i].bo && ab[i].bi) {
	ch = 'b';
      }

      if(ch != '-') {
	int in, out;
	for(int j = 0; j < n; ++ j) {
	  if(board[i][j] == ch) {
	    out = j;
	  }
	}
	for(int j = 0; j < n; ++ j) {
	  if(board[j][i] == ch) {
	    in = j;
	  }
	}

	cout << "YES\n";
	bool c = m % 4 == 0;
	for(int mi = 0; mi < m / 2; ++ mi) {
	  cout << (c ? i + 1 : in + 1) << ' ';
	  c = !c;
	}
	c = !c;
	cout << (i + 1) << ' ';
	for(int mi = 0; mi < m / 2; ++ mi) {
	  cout << (c ? i + 1 : out + 1) << ' ';
	  c = !c;
	}
	cout << '\n';
	goto done;
      }
    }
    
    cout << "NO\n";
  done:;
  }
}
