//#pragma GCC optimize("O3") //#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include using namespace std; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // namespace debug { template struct rge { c b, e; }; template rge range(c i, c j) { return rge{i, j}; } template char elo(...); template auto elo(c* a) -> decltype(cerr << *a, 0); struct stream { ~stream() { cerr << endl; } template typename enable_if (0) != 1, stream&>::type operator<<(c i) { cerr << boolalpha << i; return *this; } template typename enable_if (0) == 1, stream&>::type operator<<(c i) { return *this << range(begin(i), end(i)); } template stream& operator<<(pair p) { return *this << "(" << p.first << ", " << p.second << ")"; } template stream& operator<<(rge d) { *this << "["; for (auto it=d.b; it!=d.e; it++) *this << ", " + 2 * (it == d.b) << *it; return *this << "]"; } stream& _dbg(const string& s, int i, int b) { return *this; } template stream& _dbg(const string& s, int i, int b, c arg, cs ... args) { if (i == s.size()) return (*this << ": " << arg << ""); b += (s[i] == '(') + (s[i] == '[') + (s[i] == '{'); b -= (s[i] == ')') + (s[i] == ']') + (s[i] == '}'); if (s[i] == ',' && b == 0) return (*this << ": " << arg << " ")._dbg(s, i+1, b, args...); return (s[i] == ' ' ? *this : *this << s[i])._dbg(s, i+1, b, arg, args...); } };} #define dout debug::stream() #define dbg(...) ((dout << ">> ")._dbg(#__VA_ARGS__, 0, 0, __VA_ARGS__)) // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // #define f first #define s second #define sc scanf #define pr printf #define mp make_pair #define pb push_back #define all(x) x.begin(),x.end() #define ss(x) ((int)((x).size())) #define rep0(i, b) for(int (i)=(0);i<(b);(i)++) #define rep1(i, b) for(int (i)=(1);i<=(b);(i)++) #define rep(i, a, b) for(int (i)=(a);i<=(b);(i)++) #define per(i, a, b) for(int (i)=(b);i>=(a);(i)--) #define lowb(v, x) (lower_bound(all(v),(x))-(v).begin()) #define uppb(v, x) (upper_bound(all(v),(x))-(v).begin()) #define upgrade ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define erase_duplicates(x) {sort(all(x));(x).resize(distance((x).begin(), unique(all(x))));} template pair operator-(pair a, pair b) { return mp(a.f-b.f, a.s-b.s); } template pair operator+(pair a, pair b) { return mp(a.f+b.f, a.s+b.s); } template void umin(p& a, const q& b) { if (a > b) a = b; } template void umax(p& a, const q& b) { if (a < b) a = b; } using lf=long double; using ll=long long; using cll=const ll; using cint=const int; using pll=pair; using pii=pair; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // const int N = 105; int n; char tmp [5]; char t [N][N]; bool vis [N][N]; int cnt = 0; char c; vector < pair < pair , pair > > vec; void dfs (int y, int x){ vis[y][x] = true; cnt += 1; auto relax = [&] (int yy, int xx){ if (yy < 1 || yy > n) return; if (xx < 1 || xx > n) return; if (vis[yy][xx] == true) return; if (t[yy][xx] != c) return; dfs(yy, xx); vec.pb({{yy, xx}, {y, x}}); }; if (t[y][x] == 'R'){ rep(i, 1, n){ relax(i, x); relax(y, i); } } if (t[y][x] == 'B'){ rep(i, -n, n){ relax(y - i, x - i); relax(y - i, x + i); } } if (t[y][x] == 'Q'){ rep(i, 1, n){ relax(i, x); relax(y, i); } rep(i, -n, n){ relax(y - i, x - i); relax(y - i, x + i); } } if (t[y][x] == 'N'){ relax(y - 2, x - 1); relax(y - 2, x + 1); relax(y - 1, x - 2); relax(y - 1, x + 2); relax(y + 1, x - 2); relax(y + 1, x + 2); relax(y + 2, x - 1); relax(y + 2, x + 1); } if (t[y][x] == 'K'){ relax(y - 1, x - 1); relax(y - 1, x); relax(y - 1, x + 1); relax(y, x - 1); relax(y, x + 1); relax(y + 1, x - 1); relax(y + 1, x); relax(y + 1, x + 1); } } int main (){ scanf ("%d%s", &n, tmp); c = tmp[0]; rep(y, 1, n){ scanf ("%s", t[y] + 1); } int all = 0; rep(y, 1, n){ rep(x, 1, n){ if (t[y][x] == c) all += 1; } } assert(all >= 1); rep(y, 1, n){ rep(x, 1, n){ if (t[y][x] == c){ dfs(y, x); if (cnt == all){ printf ("YES\n"); assert(vec.size() == cnt - 1); for (auto p : vec) printf ("%d %d %d %d\n", p.f.f, p.f.s, p.s.f, p.s.s); } else { printf ("NO\n"); } return 0; } } } return 0; }