#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int tc;
  cin >> tc;
  while (tc--) {
    int n, m;
    cin >> n >> m;
    vector<string> v(n);
    for (int i = 0; i < n; i++) {
      cin >> v[i];
    }
    bool has = false;
    int a = 1, b = 2;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (i == j) {
          continue;
        } else {
          if (v[i][j] == v[j][i]) {
            has = true;
            a = i + 1, b = j + 1;
          }
        }
      }
    }
    if (has || (m % 2 == 1)) {
      cout << "YES\n";
      for (int i = 0; i <= m; i++) {
        cout << ((i % 2 == 0) ? a : b) << " ";
      }
      cout << "\n";
    } else {
      int p[n][2];
      memset(p, -1, sizeof p);
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
          if (i == j) {
            continue;
          } else {
            p[i][v[i][j] - 'a'] = j;
          }
        }
      }
      vector<int> ans;
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
          if (i == j) {
            continue;
          }
          if (p[j][v[i][j] - 'a'] != -1) {
            ans.push_back(i);
            ans.push_back(j);
            ans.push_back(p[j][v[i][j] - 'a']);
            break;
          }
        }
        if (ans.size()) {
          break;
        }
      }
      if (ans.size()) {
        cout << "YES\n";
        if (m % 4 == 2) {
          ans.push_back(ans[1]);
          for (int i = 0; i <= m; i++) {
            cout << ans[i % 4] + 1 << " ";
          }
          cout << "\n";
        } else {
          ans.push_back(ans[1]);
          reverse(ans.begin(), ans.end());
          for (int i = 0; i <= m; i++) {
            cout << ans[i % 4] + 1 << " ";
          }
          cout << "\n";
        }
      } else {
        cout << "NO\n";
      }
    }
  }
  return 0;
}