#include using namespace std; #define rep(i, a, n) for (int i = a; i < n; i++) #define per(i, n, a) for (int i = n - 1; i >= a; i--) #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define srtv(x) sort(all(x)) #define len(a) a.size() #define fi first #define se second #define lb lower_bound #define ub upper_bound typedef double db; typedef long long int ll; //#define int ll typedef vector vi; typedef vector vvi; typedef vector vvvi; typedef vector vvvvi; typedef queue qi; typedef pair pii; inline void solve() { } int n; char type; int board[100][100]; vector> neighbors(int x, int y){ vector> neighs; if (type == 'R' || type == 'Q'){ // w górę for (int i = x - 1; i >=0; i--){ if (board[i][y]){ neighs.pb(mp(i, y)); } } // w dół for (int i = x + 1; i < n; i++){ if (board[i][y]){ neighs.pb(mp(i, y)); } } // w lewo for (int i = y - 1; i >= 0; i--){ if (board[x][i]){ neighs.pb(mp(x, i)); } } // w prawo for (int i = y + 1; i < n; i++){ if (board[x][i]){ neighs.pb(mp(x, i)); } } } if (type == 'B' || type == 'Q'){ // góra-prawo for (int i = x, j = y; i >= 0 && j < n; i--, j++){ if (board[i][j]){ neighs.pb(mp(i, j)); } } // góra-lewo for (int i = x, j = y; i >= 0 && j >= 0; i--, j--){ if (board[i][j]){ neighs.pb(mp(i, j)); } } // dół-prawo for (int i = x, j = y; i < n && j < n; i++, j++){ if (board[i][j]){ neighs.pb(mp(i, j)); } } // dół-lewo for (int i = x, j = y; i < n && j >= 0; i++, j--){ if (board[i][j]){ neighs.pb(mp(i, j)); } } } if (type == 'N'){ int xs[] = {-2, -1, 1, 2, -2, -1, 1, 2}; int ys[] = {-1, -2, -2, -1, 1, 2, 2, 1}; rep(k,0,8){ int i = x + xs[k]; int j = y + ys[k]; if (0 <= i && i < n && 0 <= j && j < n){ if (board[i][j]){ neighs.pb(mp(i,j)); } } } } if (type == 'K'){ int xs[] = {-1, -1, -1, 0, 0, 1, 1, 1}; int ys[] = {-1, 0, 1, -1, 1, -1, 0, 1}; rep(k,0,8){ int i = x + xs[k]; int j = y + ys[k]; if (0 <= i && i < n && 0 <= j && j < n){ if (board[i][j]){ neighs.pb(mp(i,j)); } } } } return neighs; } int vis[100][100]; vector, pair>> moves; int start_x, start_y; int exc_cnt = 0; int vis_cnt = 0; void dfs (int x, int y){ vis[x][y] = 1; vis_cnt ++; for (auto p: neighbors(x, y)){ int xx = p.first; int yy = p.second; if (!vis[xx][yy]){ dfs(xx, yy); moves.pb(mp(mp(xx,yy), mp(x, y))); } } } int main() { cin >> n >> type; rep(i,0,n){ string s; cin>>s; rep(j,0,n){ if (s[j] == type){ board[i][j] = 1; start_x = i; start_y = j; exc_cnt++; } else board[i][j] = 0; } } rep(i,0,n){ rep(j,0,n){ vis[i][j] = 0; } } dfs(start_x, start_y); if (exc_cnt == vis_cnt){ cout<<"YES\n"; for (auto p: moves){ printf("%d %d %d %d\n", p.first.first + 1, p.first.second + 1, p.second.first + 1, p.second.second + 1); } } else{ cout<<"NO\n"; // for (auto p: moves){ // printf("%d %d %d %d\n", p.first.first, p.first.second, p.second.first, p.second.second); // } } return 0; }