N = 8
FREE = 0
NOT_FREE = 1
$row = Array.new(N, FREE)
$col = Array.new(N, FREE)
$dpos = Array.new(2*N-1, FREE)
$dneg = Array.new(2*N-1, FREE)
$board = Array.new(N).map { Array.new(N, 0) }

def putQueen(i)
  if i == N
    printBoard
    return
  end
  N.times do |j|
    next if $col[j] ==NOT_FREE || $dpos[i + j] == NOT_FREE || $dneg[i - j + N - 1] == NOT_FREE
    $row[i] = j
    $col[j] = $dpos[i + j] = $dneg[i - j + N - 1] = NOT_FREE
    putQueen i + 1
    $row[i] = $col[j] = $dpos[i + j] = $dneg[i - j + N - 1] = FREE
  end
end

def printBoard
  N.times do |i|
    N.times do |j|
      return if $board[i][j] == 1 && $row[i] != j
    end
  end
  N.times do |i|
    row = ''
    N.times do |j|
      if $row[i] == j
        row << 'Q'
      else
        row << '.'
      end
    end
    puts row
  end
end

n = gets.to_i
n.times do
  input = gets.split(' ').map(&:to_i)
  $board[input[0]][input[1]] = 1
end
putQueen 0
