{-# LANGUAGE FlexibleContexts #-}

module Main where

import Debug.Trace
import Data.List
import qualified Data.Set as Set
import qualified Data.Sequence as Seq
import qualified Data.ByteString.Char8 as B
import Data.Int
import Data.Char
import Data.Array
-- import Data.Array.IO
import Data.Maybe
import qualified Data.Map as M
-- import Control.Monad.ST
-- import Data.STRef
import Data.Ord
import Data.Functor
import Control.Applicative
import Control.Monad
import Text.Printf

queen = 'Q'
space = '.'

solve :: Int -> [[Int]] -> Array (Int, Int) Char
solve n lst = toArray $ if n >= 8 then queens else concat $ map (search queens squares) squares where
    search qs ss s
        | length qs >= 7 = (s:qs)
        | otherwise = concat $ map (search (s:qs) next) next where
                    next = filter (acceptable s) ss

    queens = toTupple lst
    squares = iter [(x, y) | x <- [0..7], y <- [0..7]] queens where
        iter ac [] = ac
        iter ac (q:qs) = iter (filter (acceptable q) ac) qs  
    toArray qs = accumArray (\x y-> y) space ((0,0),(7,7)) [(location, queen)| location <- qs]   
    acceptable (r, c) (rq, cq)
        | rq == r || cq == c = False
        | rq + c == cq + r   = False
        | rq + cq == r + c   = False
        | otherwise = True
    toTupple [] = []
    toTupple ([r, c]:xs) = (r, c):toTupple xs

readIntLn:: IO Int
readIntLn = (fst . fromJust . B.readInt) <$> B.getLine

readIntList:: IO [Int]
readIntList = map (fst . fromJust . B.readInt) . B.words <$> B.getLine

print' :: Array (Int, Int) Char -> IO ()
print' ar = mapM_ printRow [0..7] where
    printRow r = do
        mapM_ printSquare [0..7]
        putStrLn "" where
            printSquare c = putStr $ [ar!(r,c)]

main :: IO() 
main = do
    n  <- readIntLn
    l <- replicateM n readIntList
    print' $ solve n l

