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


if len(vertices) == 0:
    print("NO")
    exit(0)

root = list(vertices)[0]
vis_count = 1

solution = []


def dfs():
    visited = [[False] * N for _ in range(N)]
    stack = []
    stack.append((root, None))
    visited[root[0]][root[1]] = True

    while len(stack):
        node, parent = stack[-1]
        if parent is not None:
            solution.append((*node, *parent))
        stack.pop()
        for next in graph[node]:
            if not visited[next[0]][next[1]]:
                visited[next[0]][next[1]] = True
                stack.append((next, node))


dfs()


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")
