fun main(args: Array<String>) = p17()

fun p17() {
    data class Rc(val row: Int, val column: Int)

    val k = readLine()!!.toInt()
    val inputs = Array(k) {
        val (r, c) = readLine()!!.split(' ').map { it.toInt() }
        Rc(r, c)
    }

    fun isValid(perm: List<Int>): Boolean {
        val leftToUp = mutableSetOf<Int>()
        val leftToDown = mutableSetOf<Int>()
        perm.forEachIndexed { row, column ->
            if (!leftToUp.add(row + column)) return false
            if (!leftToDown.add((7 - row) + column)) return false
        }
        return true
    }

    permutations((0..7).toList()).forEach { perm ->
        if (inputs.any { perm[it.row] != it.column } || !isValid(perm)) return@forEach
        
        val grid = Array(8) { CharArray(8) { '.' } }
        perm.forEachIndexed { index, i -> grid[index][i] = 'Q' }
        return println(grid.joinToString(System.lineSeparator()) { it.joinToString("") })
    }

    error("なんで？")
}

private fun permutations(src: List<Int>): List<List<Int>> {
    if (src.size == 1) return listOf(src)
    val perms = mutableListOf<List<Int>>()
    val insertElement = src[0]
    permutations(src.drop(1)).forEach { perm ->
        for (i in 0..perm.size) {
            val newPerm = perm.toMutableList()
            newPerm.add(i, insertElement)
            perms.add(newPerm.toList())
        }
    }
    return perms
}

