from collections import defaultdict

N, c = input().split()
N = int(N)
lines = [input() for _ in range(N)]

graph = defaultdict(lambda: list())

# Moves
KING = [(0, -1), (-1,-1), (-1, 0), (-1, 1)]
KNIGHT = [(-1, -2), (-2, -1), (-2, 1), (-1, 2)]
QUEEN = [(0, -1), (-1,-1), (-1, 0), (-1, 1)]
ROOK = [(0, -1), (-1, 0)]
BISHOP = [(-1, -1), (-1, 1)]

const_moves = {
    'N': KNIGHT, 'K':  KING
}
var_moves = {
    'R': ROOK, 'Q': QUEEN, 'B': BISHOP
}

# create graph
vertices = set()
for row in range(N):
    for col in range(N):
        if lines[row][col] == '.': continue
        vertices.add((row, col))
        c = lines[row][col]
        if c in const_moves:
            for drow, dcol in const_moves[c]:
                new_row = row + drow
                new_col = col + dcol
                if 0<=new_row<N and 0<=new_col<N and lines[new_row][new_col] != '.':
                    graph[(row, col)].append((new_row, new_col))
                    graph[(new_row, new_col)].append((row, col))
        else:
            for drow, dcol in var_moves[c]:
                new_row = row + drow
                new_col = col + dcol
                while 0<=new_row<N and 0<=new_col<N and lines[new_row][new_col] == '.':
                    new_row += drow
                    new_col += dcol
                if 0<=new_row<N and 0<=new_col<N and lines[new_row][new_col] != '.':
                    graph[(row, col)].append((new_row, new_col))
                    graph[(new_row, new_col)].append((row, col))


# connected
visited = [[False]*N for _ in range(N)]
root = list(vertices)[0]
vis_count = 1

solution = []


def dfs(node: tuple, parent):
    global solution, visited, graph
    if visited[node[0]][node[1]]: return
    visited[node[0]][node[1]] = True
    for next_node in graph[node]:
        dfs(next_node, node)
    if parent is not None:
        solution.append((*node, *parent))


dfs(root, None)


if len(solution) == len(vertices) - 1:
    print("YES")
    for a,b,c,d in solution:
        print(a+1, b+1, c+1, d+1)
else:
    print("NO")
