import java.io.*;
import java.util.*;
class Graf{
	ArrayList<Integer>[]E;
	int n;
	Graf(int n){
		this.n=n;
		E=new ArrayList[n];
		for(int i=0;i<n;i++) {
			E[i]=new ArrayList<Integer>();
		}
	}
	@Override
	public String toString() {
		StringBuilder sb=new StringBuilder("");
		for(int i=0;i<n;i++) {
			sb.append(i+": ");
			for(int j:E[i]) {
				sb.append(j+",");
			}
			sb.append("\n");
		}
		return sb.toString();
	}
	public void solve(HashMap<Integer,tocka> decode) {
		PrintWriter out=new PrintWriter(System.out);
		boolean[]done=new boolean[n];
		ArrayList<Integer> s=new ArrayList<Integer>();
		ArrayList<Integer> d=new ArrayList<Integer>();
		Queue<Integer> bfs =new LinkedList<Integer>();
		bfs.add(0);
		done[0]=true;
		while(!bfs.isEmpty()) {
			int t=bfs.poll();
			for(int e:E[t]) {
				if(done[e]) {
					continue;
				}
				done[e]=true;
				bfs.add(e);
				s.add(t);
				d.add(e);
			}
		}
		boolean ok=true;
		for(boolean b:done) {
			if(!b) {
				ok=false;
			}
		}
		out.println(ok?"YES":"NO");
		if(ok) {
			for(int i=s.size()-1;i>=0;i--) {
				int pr=d.get(i);
				tocka r=decode.get(pr);
				int pl=s.get(i);
				tocka l=decode.get(pl);
				int ry=r.y+1;
				int rx=r.x+1;
				int ly=l.y+1;
				int lx=l.x+1;
				out.println(ry+" "+rx+" "+ly+" "+lx);
			}
		}
		out.close();
	}
}
class tocka{
	int x,y;

	public tocka(int x,int y){
		this.x=x;
		this.y=y;
	}
	public tocka mult(int a) {
		return new tocka(x*a,y*a);
	}
	@Override public int hashCode(){
		return Objects.hash(x,y);
	}
	@Override public boolean equals(Object obj){
		if(this==obj)
			return true;
		if(obj==null)
			return false;
		if(getClass()!=obj.getClass())
			return false;
		tocka other=(tocka)obj;
		return x==other.x&&y==other.y;
	}
	@Override public String toString(){
		return "("+x+", "+y+")";
	}
}
public class n1{
	static char c;
	static int lim;
	static tocka[]moves;
	public static void print(boolean[][]q) {
		for(int y=0;y<q.length;y++) {
			for(int x=0;x<q.length;x++) {
				System.out.print(q[x][y]?c:".");
			}
			System.out.println();
		}
		System.out.println();
	}
	public static void main(String[] args) throws Exception{
		int n=I.readInt();
		c=I.readString().charAt(0);
		boolean[][]q=new boolean[n][n];
		for(int y=0;y<n;y++) {
			String s=I.readLine();
			for(int x=0;x<n;x++) {
				q[x][y]=s.charAt(x)==c;
			}
		}
		int V=0;
		HashMap<tocka,Integer> hm=new HashMap<tocka, Integer>();
		HashMap<Integer,tocka> hmi=new HashMap<Integer,tocka>();
		for(int x=0;x<n;x++) {
			for(int y=0;y<n;y++) {
				if(q[x][y]) {
					hm.put(new tocka(x,y),V);
					hmi.put(V,new tocka(x,y));
					V++;
				}
			}
		}
		if(c=='K'||c=='N') {
			lim=1;
		}else {
			lim=n;
		}
		gen_moves(c);
//		print(q);
		Graf g=new Graf(V);
		for(tocka t:hm.keySet()) {
			int x=t.x;
			int y=t.y;
			for(tocka move:moves) {
				for(int i=1;i<=lim;i++) {
					tocka next=move.mult(i);
					int x2=x+next.x;
					int y2=y+next.y;
					if(hm.containsKey(new tocka(x2, y2))) {
						g.E[hm.get(t)].add(hm.get(new tocka(x2, y2)));
					}
				}
			}
		}
//		System.out.println(hm);
//		System.out.println(g);
		g.solve(hmi);
	}
	private static void gen_moves(char c2){
		if(c=='R') {
			moves= new tocka[]{new tocka(1,0), new tocka(-1,0), new tocka(0,1), new tocka(0, -1)};
		}else if(c=='Q'||c=='K') {
			moves= new tocka[]{new tocka(1,0), new tocka(-1,0), new tocka(0,1), new tocka(0, -1),
					new tocka(1,1), new tocka(-1,1), new tocka(1,-1), new tocka(-1, -1)};
		}else if(c=='B') {
			moves= new tocka[]{new tocka(1,1), new tocka(-1,1), new tocka(1,-1), new tocka(-1, -1)};
		}else if(c=='N') {
			moves=new tocka[]{new tocka(1,2), new tocka(2,1), new tocka(2,-1), new tocka(1, -2),
					new tocka(-1,-2), new tocka(-2,-1), new tocka(-2,1), new tocka(-1, 2)};
		}
	}

}

class I{
	static BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer st;

	public static String nextToken() throws Exception{
		while(st==null||!st.hasMoreTokens()){
			st=new StringTokenizer(in.readLine(),"[ ,:]");
		}
		return st.nextToken();
	}

	public static int readInt() throws Exception{
		return Integer.parseInt(nextToken());
	}

	public static long readLong() throws Exception{
		return Long.parseLong(nextToken());
	}

	public static double readDouble() throws Exception{
		return Double.parseDouble(nextToken());
	}

	public static String readString() throws Exception{
		return nextToken();
	}

	public static String readLine() throws Exception{
		return in.readLine();
	}
}
