open System

//------------------------------------------------
let inputs = stdin.ReadLine().Split(' ')
//
let N = inputs.[0] |> int

//------------------------------------------------
[<Literal>]
let T_S = 0       // skip.
[<Literal>]
let T_H = 1       // horizon
[<Literal>]
let T_V = 2       // vertical

let n2c = "zabcdefghijklmnopqrstuvwxyz"
let num2char n =
    if n = 0 then '.'
    else
        n2c.[n%n2c.Length]

//------------------------------------------------

let sub_pos x y t =
    match t with
    | T_H -> (x+1,y)
    | T_V -> (x,y+1)
    | _   -> (x  ,y)

//------------------------------------------------

type Board(n) = 
    let WIDTH = n
    let SIZE  = n*n
        
    member this.pos2idx x y = ((y-1)*WIDTH)+(x-1)
    member this.idx2pos idx = ((idx%WIDTH)+1, (idx/WIDTH)+1)

    member this.printX n ox (brd:int array) =
       for y in 1..WIDTH do
           let line1 = String.replicate ox "."
           let posX2char x = (num2char brd.[this.pos2idx x y]) |> string
           let line2 = 
               [1..WIDTH]
               |> List.map posX2char
               |> String.concat ""
           let line3 = String.replicate (max 0 (n-ox-WIDTH)) "."
           printfn "%s%s%s" line1 line2 line3

    member this.print (brd:int array) =
        if brd.Length <= 0 then
            printfn "-1"
        else
            this.printX WIDTH 0 brd

    member this.board_H y (brd:int array) =
        [|1..WIDTH|] |> Array.map (fun n -> brd.[this.pos2idx n y])
    member this.board_V x (brd:int array) =
        [|1..WIDTH|] |> Array.map (fun n -> brd.[this.pos2idx x n])

    member this.count_quality idxs brd =
        brd |> idxs |> Array.filter (fun n -> n <> 0) |> Array.distinct |> Array.length
    member this.count_quality_H y brd = brd |> this.count_quality (this.board_H y)
    member this.count_quality_V x brd = brd |> this.count_quality (this.board_V x)

    member this.is_complete (brd:int array) =
        let a1 = 
            [|1..WIDTH|]
            |> Array.map (fun y -> this.count_quality_H y brd)
            |> Array.distinct
        let a2 =
            [|1..WIDTH|] 
            |> Array.map (fun x -> this.count_quality_V x brd)
            |> Array.distinct
        if (a1.[0] > 0 && a1.Length = 1 && a2.Length = 1 && a1.[0] = a2.[0]) then
            a1.[0]
        else
            -1

    member this.put_tile x y t p (brd:int array) =
        if t = T_S then
            brd
        else
            let (x2,y2) = sub_pos x y t
            let valid x y = (x >= 1 && x <= WIDTH && y >= 1 && y <= WIDTH)
            if not (valid x y) || not (valid x2 y2) then
                [| |]
            else
                let idx1 = this.pos2idx x y
                let idx2 = this.pos2idx x2 y2
                if brd.[idx1] <> 0 || brd.[idx2] <> 0 then
                    [| |]
                else
                    let brd2 = Array.copy brd
                    brd2.[idx1] <- p
                    brd2.[idx2] <- p
                    brd2

    member this.try_solve =
        let rec solve idx t p (brd:int array) =
            let (x,y) = this.idx2pos idx
            let brd2 = this.put_tile x y t p brd
            //
            let rec idx_next i2 =
                if i2 < brd2.Length then
                    if brd2.[i2] = 0 then i2 else idx_next (i2+1)
                else
                    i2
            let idx2 = idx_next (idx+1)
            if idx2 >= SIZE || brd2.Length <= 1 then
                if brd2.Length >= 1 && this.is_complete brd2 >= 0 then
                    brd2
                else
                    [| |]
            else
                let (nx,ny) = this.idx2pos idx2
                let p2 = p + (if t = T_S then 0 else 1)
                let rec next2 (tlist:int array) i = 
                    if i < tlist.Length then
                        let b2 = brd2 |> solve idx2 tlist.[i] p2
                        if b2.Length > 0 then b2
                        else next2 tlist (i+1)
                    else
                        [| |]
                let next tlist = next2 tlist 0
                //
                let cx = this.count_quality_V nx brd2
                let cy = this.count_quality_H ny brd2
                let tlist x y =
                    let lst = [| -1; -1; T_S |]
                    lst.[0] <- if cx<3 && cy<3 && x < WIDTH then T_H else -1
                    lst.[1] <- if cx<3 && cy<3 && y < WIDTH then T_V else -1
                    lst |> Array.distinct |> Array.filter (fun n -> n >= 0) 
                next (tlist nx ny)
        let board = [| for i in 0..SIZE -> 0 |]
        solve 0 T_V 1 board

//------------------------------------------------

let SolveBoard n =
    let brd = Board n
    (brd, brd.try_solve)

let main =
    let n = N - 4
    let m = N % 4
    if N < 4 then
        let brd = Board N
        let ret = brd.try_solve
        brd.print ret
    else
        let brd4 = SolveBoard 4
        let brdM = SolveBoard (4+m)
        let printB (brd:Board, ret) n ox = brd.printX n ox ret
        //
        let e = n/4
        for i in 1..e do
            let ox = (i-1) * 4
            printB brd4 N ox
        //
        printB brdM N (e*4)


Measured memory_bytes: 22332