from queue import PriorityQueue, Queue


moves = (
    (-1, -1), (-1, 0), (-1, 1),
    ( 0, -1),          ( 0, 1),
    ( 1, -1), ( 1, 0), ( 1, 1),
)


NOT_VISITED = -1
OBSTACLE = -2


class Node:

    def __init__(self, row, column):
        self.row = row
        self.column = column
        self.distance = NOT_VISITED

    def __lt__(self, other):
        # return self.distance < other.distance  # Dijkstra
        return self.distance + self.heuristic < other.distance + other.heuristic  # A*

    @property
    def heuristic(self):
        # distance ignoring obstacles
        return max(abs(self.row - target[0]), abs(self.column - target[1]))

    def __repr__(self):
        return f"Node({self.row}, {self.column})"


class ChessBoard:
    """
    self.board = contains the distances to the cells
        -1 = not visited
        -2 = obstacle
    """

    def __init__(self, N=8):
        self.N = N
        self.board = [[Node(r, c) for c in range(N)] for r in range(N)]

        self.visited = 0
        self.visit_order = [[0 for c in range(N)] for r in range(N)]

    def add_obstacle(self, row, column):
        self.board[row][column].distance = OBSTACLE

    def get_node(self, row, column):
        return self.board[row][column]

    def set_distance(self, node, distance):
        node.distance = distance

    def set_visited(self, node):
        self.visited += 1
        self.visit_order[node.row][node.column] = self.visited
        
    def get_neighbors(self, node):
        for x, y in moves:
            new_row = node.row + x
            new_column = node.column + y
            if 0 <= new_row < self.N and \
               0 <= new_column < self.N and \
               self.get_node(new_row, new_column).distance != OBSTACLE:
                yield self.get_node(new_row, new_column)

    def print(self):
        for row in range(self.N):
            for column in range(self.N):
                print(f"{self.get_node(row, column).distance:>3}", end="")
            print()

    def print_heuristic(self):
        for row in range(self.N):
            for column in range(self.N):
                print(f"{self.get_node(row, column).heuristic:>3}", end="")
            print()
    
    def print_distance_heuristic(self):
        for row in range(self.N):
            for column in range(self.N):
                node = self.get_node(row, column)
                print(f"{node.distance + node.heuristic:>3}", end="")
            print()

    def print_visit_order(self):
        for row in range(self.N):
            for column in range(self.N):
                print(f"{self.visit_order[row][column]:>3}", end="")
            print()

    def bfs(self, start_row, start_column):

        start = self.get_node(start_row, start_column)
        
        self.set_distance(start, 0)

        # q = Queue()  # BFS
        q = PriorityQueue() # Dijkstra / A*
        q.put(start)
        
        while not q.empty():

            u = q.get()
            self.set_visited(u)
            # print(u)
            dist = u.distance

            for v in self.get_neighbors(u):
                if v.distance == NOT_VISITED:
                    self.set_distance(v, dist + 1)
                    q.put(v)
                elif v.distance > dist + 1:
                    self.set_distance(v, dist + 1)


if __name__ == '__main__':

    G = ChessBoard()
    
    O = int(input())
    for _ in range(O):
        row, col = [int(i) - 1 for i in input().split()]
        G.add_obstacle(row, col)


    king = [int(i) - 1 for i in input().split()]
    target = [int(i) - 1 for i in input().split()]

    # G.print()
    # print("King:", *king)
    # print("Target:", target_row, target_column)

    G.bfs(*king)

    G.print()
    print()
    # G.print_heuristic()
    # print()
    # G.print_distance_heuristic()
    # print()

    print(G.get_node(*target).distance)  # distance to the target position

    G.print_visit_order()
