#define _USE_MATH_DEFINES #include #ifdef LOC #include "debuglib.h" #else #define deb(...) #define DBP(...) #endif using namespace std; using ll = long long; using Vi = vector; using Pii = pair; #define pb push_back #define mp make_pair #define x first #define y second #define rep(i, b, e) for (int i = (b); i < (e); i++) #define each(a, x) for (auto& a : (x)) #define all(x) (x).begin(), (x).end() #define sz(x) int((x).size()) #define endl "\n" int uplg(int n) { return 32-__builtin_clz(n); } int uplg(ll n) { return 64-__builtin_clzll(n); } struct Move { int x1, y1, x2, y2; }; int n; char k; vector grid; vector> vis; vector res; bool check(int x, int y) { return 0 <= x && x < n && 0 <= y && y < n && !vis[x][y] && grid[x][y] != '.'; } void dfs(int x, int y) { vis[x][y] = true; if (k == 'R' || k == 'Q') { for (int i = 0; i < n; i++) { if (check(i, y)) { dfs(i, y); res.pb({i, y, x, y}); } if (check(x, i)) { dfs(x, i); res.pb({x, i, x, y}); } } } if (k == 'B' || k == 'Q') { for (int i = -n; i <= n; i++) { if (check(x+i, y+i)) { dfs(x+i, y+i); res.pb({x+i, y+i, x, y}); } } } if (k == 'N') { for (int i = -2; i <= 2; i += 4) { for (int j = -1; j <= 1; j += 2) { if (check(x+i, y+j)) { dfs(x+i, y+j); res.pb({x+i, y+j, x, y}); } } } for (int i = -1; i <= 1; i += 2) { for (int j = -2; j <= 2; j += 4) { if (check(x+i, y+j)) { dfs(x+i, y+j); res.pb({x+i, y+j, x, y}); } } } } if (k == 'K') { for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { if (check(x+i, y+j)) { dfs(x+i, y+j); res.pb({x+i, y+j, x, y}); } } } } } void run() { cin >> n >> k; grid.resize(n); vis.resize(n, vector(n)); for (int i = 0; i < n; i++) { cin >> grid[i]; } bool flag = false; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (check(i, j)) { if (flag) { cout << "NO" << endl; return; } flag = true; dfs(i, j); } } } cout << "YES" << endl; for (auto m : res) { cout << m.x1 + 1 << " " << m.y1 + 1<< " " << m.x2 + 1 << " " << m.y2 + 1 << endl; } } int main() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(18); run(); return 0; }