#include #include #include bool bishop(std::pair one, std::pair two) { return ((one.first - one.second)) == ((two.first - two.second)) || ((one.first + one.second)) == ((two.first + two.second)); } bool king(std::pair one, std::pair two) { return (abs(one.first - one.first) < 1) && abs(two.second - two.second) < 1; } bool night(std::pair one, std::pair two) { return (((abs(one.first - two.first) == 2) && (abs(one.second - two.second) == 1)) || ((abs(one.first - two.first) == 1 && (abs(one.second - two.second) == 2)))); } bool rook(std::pair one, std::pair two) { return one.first == two.first || one.second == two.second; } bool queen(std::pair one, std::pair two) { return bishop(one, two) || rook(one, two); } void dfs(std::vector>& graph, std::vector>& result, std::vector& visited, int node) { visited[node] = true; for (int x : graph[node]) { if (!visited[x]) { // tree[node].push_back(x); dfs(graph, result, visited, x); result.push_back(std::make_pair(x, node)); } } } int main() { int w; char f; std::cin >> w >> f; std::vector> cords; std::vector board(w); for (int x = 0; x < w; x++) { std::string k; std::cin >> k; for (int y = 0; y < w; y++) { if (k[y] != '.') { cords.push_back(std::make_pair(x, y)); } } } int n = cords.size(); std::vector> graph(n); for (int x = 0; x < n; x++) { for (int y = x + 1; y < n; y++) { if (f == 'B' && bishop(cords[x], cords[y])) { graph[x].push_back(y); graph[y].push_back(x); } if (f == 'K' && king(cords[x], cords[y])) { graph[x].push_back(y); graph[y].push_back(x); } if (f == 'N' && night(cords[x], cords[y])) { graph[x].push_back(y); graph[y].push_back(x); } if (f == 'R' && rook(cords[x], cords[y])) { graph[x].push_back(y); graph[y].push_back(x); } if (f == 'Q' && queen(cords[x], cords[y])) { graph[x].push_back(y); graph[y].push_back(x); } } } std::vector> result; std::vector visited(n); dfs(graph, result, visited, 0); for (bool x : visited) { if (!x) { std::cout << "NO" << std::endl; return 0; } } std::cout << "YES" << std::endl; for (std::pair p : result) { std::cout << cords[p.first].first + 1 << " " << cords[p.first].second + 1 << " " << cords[p.second].first + 1 << " " << cords[p.second].second + 1 << std::endl; } std::cout << std::endl; return 0; }