#include <bits/stdc++.h>

using namespace std;

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

  int tt;
  cin >> tt;
  while (tt--) {
    int n, m;
    cin >> n >> m;
    vector<string> g(n);
    for (int i = 0; i < n; ++i) {
      cin >> g[i];
    }

    int a = -1, b = -1;
    vector<vector<int>> ga(n);
    vector<vector<int>> gb(n);
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        if (i != j && g[i][j] == g[j][i]) {
          a = i;
          b = j;
        }
        if (g[i][j] == 'a') {
          ga[i].push_back(j);
        }
        if (g[i][j] == 'b') {
          gb[i].push_back(j);
        }
      }
    }

    if (a != -1) {
      cout << "YES" << '\n';
      for (int i = 0; i < m + 1; ++i) {
        cout << (i % 2 == 0 ? (a + 1) : (b + 1)) << ' ';
      }
      cout << '\n';
    } else if (m % 2 == 1) {
      cout << "YES" << '\n';
      for (int i = 0; i < m + 1; ++i) {
        cout << (i % 2) + 1 << ' ';
      }
    } else {
      int c = -1;
      for (int i = 0; i < n && c == -1; ++i) {
        for (int j = 0; j < n && c == -1; ++j) {
          if (i == j) {
            continue;
          }
          if (g[i][j] == 'a' && !ga[j].empty()) {
            a = i;
            b = j;
            c = ga[j].back();
          }
          if (g[i][j] == 'b' && !gb[j].empty()) {
            a = i;
            b = j;
            c = gb[j].back();
          }
        }
      }
      if (c == -1) {
        cout << "NO" << '\n';
      } else {
        assert(a != b && a != c && b != c);
        cout << "YES" << '\n';
        if (m % 4 == 0) {
          array<int, 4> cycle{b, c, b, a};
          for (int i = 0; i < m + 1; ++i) {
            cout << cycle[i % cycle.size()] + 1 << ' ';
          }
        } else {
          array<int, 4> cycle{a, b, c, b};
          for (int i = 0; i < m + 1; ++i) {
            cout << cycle[i % cycle.size()] + 1 << ' ';
          }
        }
        cout << '\n';
      }
    }
  }

  return 0;
}
