#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
int D_RECUR_DEPTH = 0;
#define deb(x) {++D_RECUR_DEPTH; auto x2=x; --D_RECUR_DEPTH; cerr<<string(D_RECUR_DEPTH, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x2<<"\e[39m"<<endl;}
template<typename O, typename C> typename enable_if<is_same<O,ostream>::value, O&>::type operator<<(O& ost,  const C& v){if(&ost == &cout) {cerr<<"Warning, printing debugs on cout!"<<endl;} ost<<"["; bool firstIter = true; for(auto& x:v){ if(firstIter) firstIter = false; else ost<<", "; ost<<x;} return ost<<"]";}
template<typename Ostream, typename ...Ts>Ostream& operator<<(Ostream& ost,  const pair<Ts...>& p){if(&ost == &cout) {cerr<<"Warning, printing debugs [pair] on cout!"<<endl;}return ost<<"{"<<p.first<<", "<<p.second<<"}";}
#else
#define deb(x)
#endif

template<class C> C reversed(C c) {reverse(c.begin(),c.end()); return c;}
#define mp make_pair
#define st first
#define nd second
typedef long long ll;
typedef pair<int,int> pii;

const vector<pii> D = {{-1,0}, {1,0}, {0,1}, {0,-1}};
const vector<pii> D2 = {{-1,-1}, {1,1}, {-1,1}, {1,-1}};
const vector<pii> KN = {{2,1}, {2,-1}, {-2,1}, {-2,-1}, {1,2}, {1,-2}, {-1,2}, {-1,-2}};

vector<vector<vector<pair<int,int> > > > graf;
vector<vector<int> > visited;
vector<vector<int> > moves;

void dfs(int i, int j) {
    visited[i][j] = 1;
    for(auto a:graf[i][j]) {
        int i2 = a.st, j2 = a.nd;
        if(!visited[i2][j2]) {
            dfs(i2,j2);
            moves.push_back({i2,j2,i,j});
        }
    }
}

int32_t main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    char c;
    cin >> c;
    vector<string> tab(n);
    graf.resize(n,vector<vector<pii>>(n));
    visited.resize(n,vector<int>(n));
    
    for(int i=0;i<n;i++)
        cin >> tab[i];

    auto inn = [&](int i, int j) {
        return i >=0 && j >=0 && i < n && j < n;
    };

    pii last = {-1,-1};
    int cnt = 0;
    for(int i=0;i<n;i++) {
        for(int j=0;j<n;j++) {
            if(tab[i][j] != c)
                continue;
            last = {i,j};
            cnt++;
            if(c == 'N') {
                for(auto a:KN) {
                    int i2 = i+a.st, j2 = j+a.nd;
                    if(inn(i2,j2) && tab[i2][j2] == c) {
                        graf[i][j].push_back({i2,j2});
                    }
                }
            }
            else if(c == 'K') {
                for(auto a:D) {
                    int i2 = i+a.st, j2 = j+a.nd;
                    if(inn(i2,j2) && tab[i2][j2] == c) {
                        graf[i][j].push_back({i2,j2});
                    }
                }
            }
            else {
                if(c == 'R' || c == 'Q') {
                    for(int s=0;s<=n;s++) {
                        for(auto a:D) {
                            int i2 = i+s*a.st, j2 = j+s*a.nd;
                            if(inn(i2,j2) && tab[i2][j2] == c)
                                graf[i][j].push_back({i2,j2});
                        }
                    }
                }
                if(c == 'B' || c == 'Q') {
                    for(int s=0;s<=n;s++) {
                        for(auto a:D2) {
                            int i2 = i+s*a.st, j2 = j+s*a.nd;
                            if(inn(i2,j2) && tab[i2][j2] == c)
                                graf[i][j].push_back({i2,j2});
                        }
                    }
                }
            }
        }
    }
    dfs(0,0);
    if(moves.size()+1 != cnt)
        cout<<"NO\n";
    else {
        cout<<"YES\n";
        for(auto a:moves)
            cout<<a[0]+1<<" "<<a[1]+1<<" "<<a[2]+1<<" "<<a[3]+1<<"\n";
    }
}