import Data.List
import Debug.Trace
import Data.Monoid

data Status = Safe | Danger | Queen deriving (Show, Eq)
type Position = (Int, Int)
type Cell = (Position, Status)
type Board = [Cell]

-- Prepare empty board
emptyBoard :: Board
emptyBoard = sortBy xtoy [((x,y), Safe) | x <- [0..7], y <- [0..7]]
  where xtoy ((x1, y1), _) ((x2, y2), _) = mappend (compare y1 y2) (compare x1 x2)


-- Board functions
getStatus :: Cell -> Status
getStatus (position, status) = status

getPosition :: Cell -> Position
getPosition (position, status) = position

setStatus :: Status -> Cell -> Board -> Board
setStatus status (position, _) board = former ++ [(position, status)] ++ latter
  where (former, target:latter) = break ((==) position . getPosition) board

getQueens :: Board -> [Position]
getQueens board = map fst $ filter ((==) Queen . getStatus) board

getSafes :: Board -> [Position]
getSafes board = map fst $ filter ((==) Safe . getStatus) board

findDangers :: Position -> Board -> [Cell]
findDangers (px,py) board = dangerRow ++ dangerCol ++ dangerSP ++ dangerSM
  where dangerRow = filter ((==) px . fst . getPosition) board
        dangerCol = filter ((==) py . snd . getPosition) board
        dangerSP  = filter (flip elem sp . getPosition) board
        dangerSM  = filter (flip elem sm . getPosition) board
        sp        = [(x,y) | x <- [0..7], y <- [0..7], y == -x+(py+px)]
        sm        = [(x,y) | x <- [0..7], y <- [0..7], y == x+(py-px)]

putQueen :: Position -> Board -> Board
putQueen position board = setStatus Queen (position, Safe) updatedBoard
  where updatedBoard    = foldr (setStatus Danger) board (findDangers position board)


-- Queen problem solver
solveQueens :: Int -> Board -> [Board]
solveQueens 0 board = [board]
solveQueens n board = do
  position <- getSafes board
  let newBoard = putQueen position board
  solveQueens (n-1) newBoard

format :: Board -> [String]
format []    = []
format board = let (row, remain) = splitAt 8 board
                   line          = concat . map (\x -> if getStatus x == Queen then "Q" else ".") $ row
               in line : (format remain)

main = do
  n <- fmap read getLine
  inputs <- fmap (map words . lines) getContents
  let positions = map (\[y, x] -> (read x, read y)) inputs
  let initialBoard = foldr putQueen emptyBoard positions
  mapM_ putStrLn . format . head . solveQueens (8-n) $ initialBoard