#include #include #include using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using pii = pair; using pll = pair; using vi = vector; using vb = vector; using vc = vector; using vvc = vector; using vvi = vector; using vvb = vector; using vpii = vector; using vpll = vector; using vll = vector; using vull = vector; using vvll = vector; using namespace __gnu_pbds; template using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; #define f first #define s second #define pb emplace_back #define rep(i, begin, end) for(auto i = (begin); i <= (end); ++i) #define repr(i, begin, end) for(auto i = (begin); i >= (end); --i) #define bend(X) X.begin(), X.end() #ifdef LOCAL #define deb(...) cout << #__VA_ARGS__ << " = " << __VA_ARGS__ << endl #define say(...) cout << __VA_ARGS__ << endl #else #define deb(x) #define say(x) #define endl '\n' #endif constexpr int INF = 1e9+1e7; constexpr ll INFl = INF; constexpr ll INFll = 1e18+1e16; void print() { cout << '\n'; } template void print(T x, Args... args) { cout << x << ' '; print(args...); } template ostream& operator<<(ostream& os, pair x) { os << x.f << ' ' << x.s; return os; } template istream& operator>>(istream& is, pair& x) { is >> x.f >> x.s; return is; } template ostream& operator<<(basic_ostream& os, T x) { for(auto i : x) os << i << ' '; return os; } template istream& operator>>(istream& is, vector& x) { for(T& i : x) is >> i; return is; } template pair operator+(const pair& A, const pair& B) { return {A.f+B.f, A.s+B.s}; } template pair operator-(const pair& A, const pair& B) { return {A.f-B.f, A.s-B.s}; } template pair& operator+=(pair& A, const pair& B) { A.f += B.f; A.s += B.s; return A; } template pair& operator-=(pair& A, const pair& B) { A.f -= B.f; A.s -= B.s; return A; } template pair operator-(const pair& A) { return {-A.f, -A.s}; } template pair operator*(const T& A, const pair& B) { return {A*B.f, A*B.s}; } template bool maxe(T1& A, const T2& B) { if(B>A) { A=B; return 1; } return 0; } template bool mine(T1& A, const T2& B) { if(B Nic operator<<(Nic, T) { return nic; } Nic operator<<(ostream&, Nic) { return nic; } ////////////////////////////////////////////////// vpii rookDir{{1,0},{-1,0},{0,1},{0,-1}}; vpii bishDir{{1,1},{1,-1},{-1,1},{-1,-1}}; vpii knigMov{{1,2},{2,1},{2,-1},{1,-2},{-1,-2},{-2,-1},{-2,1},{-1,2}}; vpii kingMov{{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1},{-1,0},{-1,1}}; struct vertex { vector e; bool active = 0, vis = 0; pii pos; int deg() { return e.size(); } void emplace(vertex* u) { e.pb(u); } }; constexpr int maxN = 100; int n; vertex G[maxN+5][maxN+5]; vector> R; inline vertex* g(pii x) { return &G[x.f][x.s]; } inline bool inside(pii x) { return x.f > 0 && x.f <= n && x.s > 0 && x.s <= n; } inline bool active(pii x) { return inside(x) && g(x)->active; } void addDir(pii x, const vpii& dirs) { for (auto dir : dirs) for (int s = 1; inside(x+s*dir); s++) { pii y = x+s*dir; if (g(y)->active) g(x)->emplace(g(y)); } } void dfs(vertex* v, vertex* p) { v->vis = 1; for (auto u : v->e) if (u != p && !u->vis) dfs(u, v); if (p != nullptr) R.pb(v->pos, p->pos); } void odpal() { rep (i, 1, n) rep (j, 1, n) if (G[i][j].active) { dfs(&G[i][j], nullptr); return; } } auto solve() { char type; cin >> n >> type; rep (i, 1, n) { rep (j, 1, n) { char c; cin >> c; if (c != '.') { G[i][j].active = 1; } } } rep (i, 1, n) { rep (j, 1, n) { pii x{i,j}; g(x)->pos = x; if (!g(x)->active) continue; G[n+1][n+1].emplace(g(x)); switch (type) { case 'R': addDir(x, rookDir); break; case 'Q': addDir(x, rookDir); addDir(x, bishDir); break; case 'B': addDir(x, bishDir); break; case 'N': for (pii y : knigMov) if (active(x+y)) g(x)->emplace(g(x+y)); break; case 'K': for (pii y : kingMov) if (active(x+y)) g(x)->emplace(g(x+y)); break; } } } odpal(); rep (i, 1, n) rep (j, 1, n) if (G[i][j].active && !G[i][j].vis) { cout << "NO" << endl; return nic; } cout << "YES" << endl; for (auto i : R) cout << i << endl; return nic; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int noOfTests = 1; //cin >> noOfTests; while(noOfTests --> 0) cout << solve() << '\n'; return 0; }