object Main {
    def queens(n: Int, fixed: List[(Int, Int)]): List[List[(Int, Int)]] = {
        def placeQueens(k: Int): List[List[(Int, Int)]] = {
            if(k == -1) List(List())
            else
                for {
                    queens <- placeQueens(k - 1)
                    col <- 0 to n - 1
                    queen = (k, col)
                    if isSafe(queen, queens)
                } yield queen :: queens
        }
         placeQueens(n - 1).filter(qs => check(fixed, qs))
    }

    def isSafe(queen: (Int, Int), queens: List[(Int, Int)]) = {
        queens.forall(q => !inCheck(queen, q))
    }

    def inCheck(q1: (Int, Int), q2: (Int, Int)) = {
        q1._1 == q2._1 ||
        q1._2 == q2._2 ||
        (q1._1 - q2._1).abs == (q1._2 - q2._2).abs
    }

    def check(fixed: List[(Int, Int)], queens: List[(Int, Int)]) =
        fixed.forall(q => queens.contains(q))

    def main(args:Array[String]) = {
        val sc = new java.util.Scanner(System.in)
        val n = sc.nextInt
        val fixed = List.fill(n)(sc.nextInt, sc.nextInt)
        for(qs <- queens(8, fixed)) {
            for(y <- 0 to 7) {
                for(x <- 0 to 7) {
                    print(if(qs.contains((y, x))) "Q" else ".")
                }
                println
            }
        }
    }
}