#define _CRT_SECURE_NO_WARNINGS #include #include #include #include using namespace std; const int mx = 109; char grid[mx][mx]; typedef pair ii; map mp; vector nodes; vector adj[mx * mx]; bool vis[mx * mx]; map>movements = { {'K',{ {-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1} }}, {'N',{ {-2,-1},{-2,1},{-1,-2},{-1,2},{1,-2},{1,2},{2,-1},{2,1}}} }; int n; vector > results; int processItem(int x, int y) { auto it = mp.find({ x,y }); if (it == mp.end()) { int sz = mp.size(); mp[{x, y}] = sz; nodes.push_back({ x+1,y+1 }); return sz; } return it->second; } bool valid(int x, int y) { return x >= 0 && x < n && y >= 0 && y < n; } void processConnection(int idx, int x, int y) { if (valid(x, y) && grid[x][y] != '.') { int idx2 = processItem(x, y); adj[idx].push_back(idx2); adj[idx2].push_back(idx); } } void dfs(int x, int p) { vis[x] = true; for (auto& k : adj[x]) { if (k != p && !vis[k]) { dfs(k, x); } } if (p != -1) { results.push_back({ nodes[x],nodes[p] }); } } int main() { char type; cin >> n >> type; for (int i = 0; i < n; ++i) { cin >> grid[i]; } for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { char c = grid[i][j]; if (c != '.') { int idx = processItem(i, j); if (type == 'K' || type == 'N') { auto mvs = movements[type]; for (auto mv : mvs) { int x = i + mv.first; int y = j + mv.second; processConnection(idx, x, y); } } if (type == 'R' || type == 'Q') { for (int d = 0; d < 100; ++d) { processConnection(idx, i + d, j); processConnection(idx, i, j + d); processConnection(idx, i - d, j); processConnection(idx, i, j - d); } } if (type == 'B' || type == 'Q') { for (int d = 0; d < 100; ++d) { processConnection(idx, i + d, j + d); processConnection(idx, i - d, j - d); processConnection(idx, i + d, j - d); processConnection(idx, i - d, j + d); } } } } } dfs(0, -1); if (results.size() == mp.size() - 1) { cout << "YES\n"; for (auto& res : results) { cout << res.first.first << " " << res.first.second << " " << res.second.first << " " << res.second.second << endl; } } else { cout << "NO\n"; } }