from itertools import product

class Board(object):
    def __init__(self):
        self.queen_pos = []  # ???????????????????????????????????? (y, x)????????????
        self.status = []  # ????´??????????????????¶??? 'Q'??????????????????'.'???????????????
        for i in range(8):
            self.status.append(['.'] * 8)
        self.situation = []  # ????????????????????±?????????????§£??????????????? 'Q'??????????????????'x'????????????????????±????????????'.'???????????????
        for i in range(8):
            self.situation.append(['.'] * 8)

    def clear(self):
        # print('clear: {0}'.format(self.queen_pos))
        temp = self.queen_pos[:]
        for q in temp:
            # print('removing {0}'.format(q))
            self.remove_queen(q)

    def show_status(self):
        for r in self.status:
            print('{0}'.format(''.join(r)))

    def show_situation(self):
        print(' | 01234567')
        print('-----------')
        for i, r in enumerate(self.situation):
            print('{0}| {1}'.format(i, ''.join(r)))

    def put_queen(self, pos):
        if pos not in self.queen_pos:
            y, x = pos
            # print('put_queen: {0}, {1}'.format(y, x))
            if self.situation[y][x] != '.':
                return False
            self.status[y][x] = 'Q'
            self.queen_pos.append(pos)
            self.update_situation()
            return True
        else:
            # print('put failed')
            return False

    def remove_queen(self, pos):
        if pos in self.queen_pos:
            y, x = pos
            self.status[y][x] = '.'
            self.queen_pos.remove(pos)
            self.update_situation()
            return True
        else:
            # print('remove failed')
            return False

    def update_status(self):
        self.status = []  # ????´??????????????????¶??? 'Q'??????????????????'.'???????????????
        for i in range(8):
            self.status.append(['.'] * 8)
        for y, x in self.queen_pos:
            self.status[y][x] = 'Q'


    def update_situation(self):
        self.situation = []  # ????????????????????±?????????????§£??????????????? 'Q'??????????????????'x'????????????????????±????????????'.'???????????????
        for i in range(8):
            self.situation.append(['.'] * 8)
        # ????????????????????±???????§£???
        for y, x in self.queen_pos:
            # self.situation[y][x] = 'x'
            for i in range(8):  # ?¨?
                self.situation[y][i] = 'x'
            for i in range(8):  # ???
                self.situation[i][x] = 'x'
            i = 1
            while y - i >= 0 and x - i >=0:  # ??????
                self.situation[y - i][x - i] = 'x'
                i += 1
            i = 1
            while y + i <= 7 and x + i <= 7:  # ??????
                self.situation[y + i][x + i] = 'x'
                i += 1
            i = 1
            while y + i <= 7 and x - i >= 0:  # ??????
                self.situation[y + i][x - i] = 'x'
                i += 1
            i = 1
            while y - i >= 0 and x + i <= 7:  # ??????
                self.situation[y - i][x + i] = 'x'
                i += 1
        # ??????????????????????????????
        for y, x in self.queen_pos:
            self.situation[y][x] = 'Q'

    def is_available(self, pos):
        y, x = pos
        if self.situation[y][x] == '.':
            return True
        else:
            return False

    def get_availability(self):
        # ????????????????????????????????§??????????????????????????¨?????????????????¢??§??????
        results = []  # ??¨?????????????§£?????????
        for y in range(8):
            available = []  # ???????????§???????????????????????±
            for x in range(8):
                if self.situation[y][x] == '.':
                    available.append((y, x))
            if available:  # ????????´????????????????????????(itertools.product?????????????????????????????§)
                results.append(available)
        return results

    def get_empty_row(self):
        available = list(range(0, 8))
        for y, x in self.queen_pos:
            available.remove(y)
        return available

    def get_empty_col(self):
        available = list(range(0, 8))
        for y, x in self.queen_pos:
            available.remove(x)
        return available



if __name__ == '__main__':
    # ??????????????\???
    b = Board()
    init_pos = []
    num = int(input())
    for i in range(num):
        init_pos.append([int(x) for x in input().split(' ')])
    for y, x in init_pos:
        b.put_queen((y, x))

    results = b.get_availability()
    combi = product(*results)
    for p in combi:
        found = True
        for pos in p:
            result = b.put_queen(pos)
            if result == False:
                found = False
                b.clear()
                for p in init_pos:
                    b.put_queen(p)
                break
        if found is True:
            b.update_status()
            b.show_status()

Measured memory_bytes: 7948