# バックトラック法
#   http://sevendays-study.com/algorithm/ex-day4.html

class Queen

  N = 8
  EMPTY = '-'
  FULL = '.'
  QUEEN = 'Q'

  def initialize
    @board = Array.new(N){ Array.new(N){ EMPTY } } # 盤面情報
    @rows = Array.new(N){ EMPTY } # 各行が埋まっているかどうか
    @cols = Array.new(N){ EMPTY } # 各列が埋まっているかどうか
    @history = [] # バックトラック用の履歴
  end

  def put(x, y)
    # return 置ける場合はtrue, 置けない場合はfalse

    return false if @board[x][y] != EMPTY

    save(x, y)

    #
    @rows[y] = FULL
    @cols[x] = FULL

    # 行列方向
    0.upto(N-1) do | a |
      @board[x][a] = FULL
      @board[a][y] = FULL
    end

    # Queen
    @board[x][y] = QUEEN

    # 斜め方向
    [[1,1], [1,-1], [-1,1], [-1,-1]].each do | direction_x, direction_y |
      _x, _y = x + direction_x, y + direction_y
      while 0<=_x && _x<=7 && 0<=_y && _y<=7
        @board[_x][_y] = FULL
        _x, _y = _x + direction_x, _y + direction_y
      end
    end
    return true
  end

  def solve(x_start, y_start)
    x_start.upto(N-1) do | x |
      if @cols[x] == EMPTY
        could = false # 該当行に置けたか
        y_start.upto(N-1) do | y |
          if put(x, y)
            could = true
            break
          end
        end
        y_start = 0
        unless could
          x, y = rollback
          solve(x, y+1)
        end
      end
    end
  end

  def print
    @board.each{|r| puts r.join('').gsub('-', '.')}
  end

  def debug_print
    puts '----'
    p @history
    @board.each{|r| puts r.join('').gsub('-', '.')}
  end

  private
  def save(x, y)
    @history << [deep_copy, @rows.clone, @cols.clone, x, y]
  end
  def rollback
    @board, @rows, @cols, x, y = @history.pop
    return x, y
  end
  def deep_copy
    new_board = Array.new(N){ Array.new(N){ EMPTY } }
    0.upto(N-1) do | x |
      0.upto(N-1) do | y |
        new_board[x][y] = @board[x][y]
      end
    end
    return new_board
  end
end

q = Queen.new

n = gets.to_i
n.times do
  x, y = gets.split.map(&:to_i)
  q.put(x, y)
end
q.solve(0, 0)
q.print

