#include using namespace std; #define ll long long #define debug(args...) \ cout << "#" << __LINE__ << ": "; \ __dbg(__split(#args, ',').begin(), args); vector __split(const string& s, char c) { vector v; stringstream ss(s); string x; while (getline(ss, x, c)) if (x!="") v.emplace_back(x); return move(v); } template inline string __to_str(T x) { stringstream ss; ss << "["; for (auto it = x.begin(); it != x.end(); it++) { if (it != x.begin()) ss << " "; ss << (*it); } ss << "]"; return ss.str(); } template inline string __to_str(stack x) { stringstream ss; ss << "["; bool first = 1; while (!x.empty()) { if (!first) ss << " "; ss << x.top(); x.pop(); first = 0; } ss << "]"; return ss.str(); } template ostream &operator<<(ostream &ostr, const pair p) { ostr << "(" << p.first << "," << p.second << ")"; return ostr; } template inline void __dbg_var(vector x) { cout << __to_str(x); } template inline void __dbg_var(list x) { cout << __to_str(x); } template inline void __dbg_var(set x) { cout << __to_str(x); } template inline void __dbg_var(unordered_set x) { cout << __to_str(x); } template inline void __dbg_var(stack x) { cout << __to_str(x); } template inline void __dbg_var(T val) { cout << val; } inline void __dbg(vector::iterator it) { cout << endl; } template inline void __dbg(vector::iterator it, T a, Args... args) { cout << it->substr((*it)[0] == ' ', it->length()) << "="; __dbg_var(a); cout << " "; __dbg(++it, args...); } const int MOD = 1e9+7; // x^n mod m ll _modpow(ll x, ll n, ll m = MOD) { if (n == 0) return 1 % m; ll u = _modpow(x,n/2,m); u = (u*u)%m; if (n & 1) u = (u*x)%m; return u; } auto speedup=[](){ std::ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); return nullptr; }(); //----------------the actual program starts here---------------- const int MAX_N = 100; char grid[MAX_N][MAX_N]; vector> R_moves = { {0,-2}, {0,-1}, {1,0}, {0,1}, {-1,0}, {-2,0} }; vector> Q_moves = { {0,-2}, {0,-1}, {1,-1}, {1,0}, {1,1}, {0,1}, {-1,1}, {-1,0}, {-2,0}, {-2,-2}, {-1,-1} }; vector> B_moves = { {1,-1}, {1,1}, {-1,1}, {-2,-2}, {-1,-1} }; vector> N_moves = { {-2,1}, {-2,-1}, {-1,-2}, {1,-2} }; vector> K_moves = { {-1,-1}, {0,-1}, {1,-1}, {1,0}, {1,1}, {0,1}, {-1,1}, {-1,0} }; int N; char t; bool done = false; vector> *type; vector> dir; list, pair>> path; void solve(int y, int x, int left) { if (left == 0) { done = true; return; } for (int i = 0; i < dir.size(); i++) { int yy = y + dir[i][0]; int xx = x + dir[i][1]; if (yy >= 0 && xx >= 0 && yy < N && xx < N && grid[yy][xx] != '.') { char tmp = grid[yy][xx]; grid[yy][xx] = '.'; path.push_back({{y+1,x+1},{yy+1,xx+1}}); solve(yy, xx, left - 1); if (done) return; path.pop_back(); grid[yy][xx] = tmp; } } } int main() { cin >> N >> t; if (t=='K') { type = &K_moves; } else if (t=='N') { type = &N_moves; } else if (t=='B') { type = &B_moves; } else if (t=='Q') { type = &Q_moves; } else if (t=='R') { type = &R_moves; } dir = *type; // debug(N, t); int total_count = 0; int sy = 0; int sx = 0; for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) { cin >> grid[i][j]; if (grid[i][j] != '.') { total_count++; if (j > sx) { sx = j; sy = i; } } } //int sy = pos[pos.size()-1] / N; //int sx = pos[pos.size()-1] % N; grid[sy][sx] = '.'; // debug(sx, sy); solve(sy, sx, total_count-1); if (!done) { cout << "NO"; } else { int count=0; cout << "YES"; if (path.size() > 0) cout << '\n'; for (auto &p : path) { cout << p.first.first << " " << p.first.second << " " << p.second.first << " " << p.second.second; if (count < path.size()) cout << '\n'; count++; } } return 0; }