import numpy as np

def legal(p1, p2, typ):
    dx = abs(p1.x - p2.x)
    dy = abs(p1.y - p2.y)
    if typ == 'K':
        return abs(p1.x - p2.x) <= 1 and abs(p1.x - p2.x) <= 1
    elif typ == 'R':
        return p1.x == p2.x or p1.y == p2.y
    elif typ == 'B':
        return dx == dy
    elif typ == 'Q':
        return p1.x == p2.x or p1.y == p2.y or dx == dy
    elif typ == 'N':
        return (dx == 1 and dy == 2) or (dx == 2 and dy == 1)

def DFSCount(piece, cnt):
    for conn in piece.connections:
        if not conn.checked:
            conn.checked = 1
            return DFSCount(conn, cnt + 1)
    return cnt

def isBridge(connection, pieces):
    # if len(connection[0].connections) == 1 or len(connection[1].connections) == 1:
    #     return False # spremenjeno, to bomo odstranili (premaknili not)
    if len(pieces) == 2:
        return (False, pieces[0], pieces[1])

    l = len(pieces)
    connection[0].connections.remove(connection[1])
    connection[1].connections.remove(connection[0])

    for piece in pieces:
        piece.checked = 0
    n0 = DFSCount(connection[0], 1)
    for piece in pieces:
        piece.checked = 0
    n1 = DFSCount(connection[1], 1)

    connection[0].connections.append(connection[1])
    connection[1].connections.append(connection[0])

    bridge = True
    removePiece = None
    clearConnection = None
    if n0 == n1 == l:
        bridge = False
        removePiece = connection[0]
        clearConnection = connection[1]
    elif n0 == 1:
        bridge = False
        removePiece = connection[0]
        clearConnection = connection[1]
    elif n1 == 1:
        bridge = False
        removePiece = connection[1]
        clearConnection = connection[0]

    return (bridge, removePiece, clearConnection)
    

class Piece:
    def __init__(self, x, y):
        self.x = x
        self.y = y
        self.connections = []
        self.checked = 0

if __name__ == "__main__":
    n, typ = input().split()
    n = int(n)

    pieces = []
    p = 0
    for i in range(n):
        row = input()
        for j in range(n):
            if row[j] != '.':
                pieces.append(Piece(i+1, j+1))
    
    graph = []
    for i in range(len(pieces)):
        for j in range(i+1, len(pieces)):
            if legal(pieces[i], pieces[j], typ):
                graph.append([pieces[i], pieces[j]])
                pieces[i].connections.append(pieces[j])
                pieces[j].connections.append(pieces[i])
    
    moves = []

    while len(pieces) > 1:
        removed = False
        for connection in graph:
            bridge, removePiece, clearConnection = isBridge(connection, pieces)
            if not bridge:
                graph = [con for con in graph if con[0] != removePiece and con[1] != removePiece]
                # for con in graph:
                #     if con[0] == removePiece or con[1] == removePiece:
                #         graph.remove(con)
                for piece in pieces:
                    for con in piece.connections:
                        if con == removePiece:
                            piece.connections.remove(con)
                pieces.remove(removePiece)
                #clearConnection.connections.remove(removePiece)
                removed = True
                moves.append([removePiece.x, removePiece.y, clearConnection.x, clearConnection.y])
                break
        if removed == False and len(pieces) > 1:
            print('NO')
            quit(0)
    
    print('YES')
    for move in moves:
        print('{} {} {} {}'.format(move[0], move[1], move[2], move[3]))
        
