$N = 8
$row = Array.new(8, 0)
$col = Array.new(8, 0)
$dpos = Array.new(15, 0)
$dneg = Array.new(15, 0)
$board = Array.new(8){ Array.new(8, ".") }
$flag = true
def printBoard
  $board.each{|b| puts b.join("")}
end

def putQueen(i)
  if i == $N
    printBoard if $flag
    $flag = false
    return
  end
  if $row[i] == 1
    putQueen(i+1)
  else
    $N.times{|j|
      next if $col[j] == 1 || $dpos[i+j] == 1 || $dneg[i-j+$N-1] == 1
      $row[i] = j
      $col[j] = $dpos[i+j] = $dneg[i-j+$N-1] = 1
      $board[i][j] = "Q"
      putQueen(i+1)
      $row[i] = $col[j] = $dpos[i+j] = $dneg[i-j+$N-1] = 0
      $board[i][j] = "."
    }
  end
end

n = gets.to_i
n.times{
  i,j = gets.split.map(&:to_i)
  $board[i][j] = "Q"
  $row[i] = $col[j] = $dpos[i+j] = $dneg[i-j+$N-1] = 1
}
putQueen(0)
