{-# LANGUAGE
  ScopedTypeVariables, BangPatterns, TupleSections, ExplicitForAll,
  LambdaCase, MultiWayIf, Unsafe, RecordWildCards, FlexibleContexts, CPP,
  NoMonomorphismRestriction, GADTs, PatternGuards, MagicHash, UnboxedTuples,
  RankNTypes, EmptyDataDecls, EmptyCase, ViewPatterns, PolyKinds,
  TypeFamilies, OverloadedStrings, FlexibleInstances, UndecidableInstances,
  DefaultSignatures, GeneralizedNewtypeDeriving, StandaloneDeriving,
  DeriveGeneric, DeriveFunctor, DeriveDataTypeable, DeriveFoldable,
  DeriveTraversable, DeriveDataTypeable, FlexibleInstances,
  MultiParamTypeClasses #-}
{-# OPTIONS_GHC -O2 #-}

import Prelude
import Data.Bits
import Data.List
import Data.Maybe
import Data.Tuple
import Data.Ord
import Data.Int
import Data.Word
import Data.Char
import Data.Ratio
import Data.Function
import Data.STRef
import Data.IORef
import Data.Monoid
import Data.Functor
import Data.Data
import Data.Typeable
import GHC.Generics
import System.IO
import           System.Exit                    ( exitSuccess )
import Control.Arrow
import Control.Applicative
import Control.Monad
import Control.Monad.Primitive
import Control.Monad.State.Strict
import Control.Monad.ST
import Control.Monad.ST.Lazy (strictToLazyST, lazyToStrictST)
import qualified Control.Monad.ST.Lazy as STL
-- import Control.Monad.ST.Safe
import Control.DeepSeq
import Data.Coerce
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BSL
import qualified Data.ByteString.Builder as BSB
import Data.IntMap (IntMap)
import qualified Data.IntMap.Strict as IMS
import qualified Data.IntMap.Lazy as IML
import Data.IntSet (IntSet)
import qualified Data.IntSet as IS
import qualified Data.Sequence as Seq
import Data.Sequence (Seq)
import qualified Data.Array.IArray as A
import qualified Data.Array.MArray.Safe as A
import qualified Data.Array.MArray as A
import Data.Array (Array)
import Data.Array.Unboxed (UArray)
import Data.Array.IArray (IArray)
import Data.Array.MArray.Safe (MArray)
import Data.Array.IO.Safe (IOArray, IOUArray)
import Data.Array.ST.Safe (STArray, STUArray, runSTArray, runSTUArray)
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.Vector.Storable as VS
import qualified Data.Vector.Storable.Mutable as VSM
import qualified Data.Vector.Primitive as VP
import qualified Data.Vector.Primitive.Mutable as VPM
import qualified Data.Vector.Generic as VG
import qualified Data.Vector.Generic.Mutable as VGM
import qualified Data.Vector.Fusion.Bundle.Monadic as VFBM
import qualified Data.Vector.Fusion.Bundle as VFB
import qualified Data.Vector.Fusion.Stream.Monadic as VFSM
import qualified Data.Vector.Fusion.Bundle.Size as VFBS
import qualified Data.Vector.Fusion.Util as VFU
import qualified Data.Attoparsec.ByteString.Char8 as Atto
import Debug.Trace
import GHC.Exts (build, Int(..), Int#, Addr#, Ptr(..),
                 (+#), (*#), (-#), (<#), (>=#), (==#), quotRemInt#,
                 remInt#, uncheckedIShiftRL#, andI#, orI#,
                isTrue#)
import Foreign.ForeignPtr
import System.IO.Unsafe
import qualified Data.ByteString.Unsafe as BSU
import qualified Data.ByteString.Internal as BSU

main :: IO ()
main = do
  n <- read <$> getLine :: IO Int
  if | n <= 2 -> putStrLn "-1"
     | n == 3 -> BS.putStr res3
     | otherwise -> do
         let q = n `shiftR` 2
             r = n .&. 3
         mem <- VS.unsafeThaw
           $ VS.update_ (VS.replicate (7*(n+1)) dot)
                        (VS.enumFromStepN (2*n-4-r) (n+1) 4 VS.++
                         VS.enumFromStepN (5*n+4) (n+1) 3)
                        (VS.replicate 7 nl)
         V.zipWithM_
           (\ protoRow off -> VS.unsafeCopy (VSM.slice off 4 mem) protoRow)
           (proto 0) $ V.enumFromStepN (n-4-r) (n+1) 4
         VU.forM_ (VU.enumFromStepN (n-4-r) (-4) (q-1)) $ \ !off -> do
           BS.putStr . svecToBS . VS.slice off (4*(n+1))
             =<< VS.unsafeFreeze mem
           VU.forM_ (VU.enumFromStepN (off+n) (n+1) 4) $ \ !i -> do
             VSM.unsafeWrite mem  i    dot
             VSM.unsafeWrite mem (i-4) nl
         when (r /= 0) 
           $ V.zipWithM_
             (\ protoRow off ->
                VS.unsafeCopy (VSM.slice off (4+r) mem) protoRow)
             (proto r) $ V.enumFromStepN (n-4-r) (n+1) (4+r)
         BS.putStr . svecToBS . VS.take ((4+r)*(n+1))
           =<< VS.unsafeFreeze mem

dot :: Word8
dot = fromIntegral $ fromEnum '.'
nl :: Word8
nl = fromIntegral $ fromEnum '\n'

res3 :: BS.ByteString
res3
  = unsafeDupablePerformIO $ BSU.unsafePackAddressLen (3*4)
    "aa.\n\\
    \..b\n\\
    \..b\n"#

{-# INLINE proto #-}
proto :: Int -> V.Vector (VS.Vector Word8)
proto n = (\(# l, addr #) -> addrMat l addr) (case n of
  0 -> (# 4, "aaca\\
             \bbca\\
             \cabb\\
             \cacc"# #)
  1 -> (# 5, "aabbc\\
             \bcc.c\\
             \b..ca\\
             \c..ca\\
             \caabb"# #)
  2 -> (# 6, "aaca..\\
             \bbca..\\
             \..bbab\\
             \..ccab\\
             \bc..cc\\
             \bc..aa"# #)
  3 -> (# 7, "..bac..\\
             \..bac..\\
             \aa.bbaa\\
             \bba..cc\\
             \cca..bb\\
             \..bca..\\
             \..bca.."# #))

{-# INLINE addrMat #-}
addrMat :: Int -> Addr# -> V.Vector (VS.Vector Word8)
addrMat n addr = linToMat n n $ unsafeAddrToSVec (n*n) addr

{-# INLINE linToMat #-}
linToMat :: (VG.Vector v a) => Int -> Int -> v a -> V.Vector (v a)
linToMat h w lvec = V.generate h (\i -> VG.slice (i*w) w lvec)

{-# INLINE unsafeAddrToSVec #-}
unsafeAddrToSVec :: Int -> Addr# -> VS.Vector Word8
unsafeAddrToSVec n addr
  = (`VS.unsafeFromForeignPtr0` n)
    $ unsafeDupablePerformIO
    $ newForeignPtr_ $ Ptr addr

{-# INLINE svecToBS #-}
svecToBS :: VS.Vector Word8 -> BS.ByteString
svecToBS vec = BSU.fromForeignPtr ptr 0 len
  where (ptr, len) = VS.unsafeToForeignPtr0 vec


Measured memory_bytes: 1660