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)
    l = len(pieces)
    for piece in pieces:
        piece.checked = 0
    connection[0].connections.remove(connection[1])
    connection[1].connections.remove(connection[0])

    n = DFSCount(connection[0], 1)

    connection[0].connections.append(connection[1])
    connection[1].connections.append(connection[0])

    return n != l

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(n-i-1, j))
    
    graph = []
    for i in range(len(pieces)):
        for j in range(i, len(pieces)):
            if i == j:
                continue
            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:
            if not isBridge(connection, pieces):
                graph.remove(connection)
                removePiece = connection[0] if len(connection[0].connections) == 1 else connection[1]
                clearConnection = connection[1] if len(connection[0].connections) == 1 else connection[0]
                pieces.remove(removePiece)
                clearConnection.connections.remove(removePiece)
                removed = True
                moves.append([removePiece.x + 1, removePiece.y + 1, clearConnection.x + 1, clearConnection.y + 1])
                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]))
        
