Problem:
 Score : 900 points    Problem Statement Let us consider a grid of squares with N rows and N columns. You want to put some domino pieces on this grid.
Each domino piece covers two squares that have a common side. Each square can be covered by at most one piece.  For each row of the grid, let's define its quality as the number of domino pieces that cover at least one square in this row.
We define the quality of each column similarly.  Find a way to put at least one domino piece on the grid so that the quality of every row is equal to the quality of every column,
or determine that such a placement doesn't exist.      Constraints  2 \le N \le 1000         Input Input is given from Standard Input in the following format:  N       Output If the required domino placement doesn't exist, print a single integer -1 .  Otherwise, output your placement as N strings of N characters each.
If a square is not covered, the corresponding character must be . (a dot).
Otherwise, it must contain a lowercase English letter.
Squares covered by the same domino piece must contain the same letter.
If two squares have a common side but belong to different pieces, they must contain different letters.        Sample Input 1 6      Sample Output 1 aabb..
b..zz.
ba....
.a..aa
..a..b
..a..b  The quality of every row and every column is 2.       Sample Input 2 2      Sample Output 2 -1

Solution (Python):
n = int(input())
base = [["aabc", "ddbc", "bcaa", "bcdd"], ["aabba", "bcc.a", "b..cb", "a..cb", "abbaa"], ["aabc..", "ddbc..", "..aabc", "..ddbc", "bc..aa", "bc..dd"], ["aabbcc.", "dd.dd.a", "..d..da", "..d..db", "dd.dd.b", "..d..dc", "..d..dc"]]
if n == 2:
    print(-1)
elif n == 3:
    print(".aa")
    print("a..")
    print("a..")
else:
    div, mod = n // 4 - 1, n % 4 + 4
    for i in range(div):
        for j in base[0]:
            print("." * i * 4 + j + "." * ((div - i - 1) * 4 + mod))
    for i in base[mod - 4]:
        print("." * div * 4 + i)

Solution (Python):
def main():
    import numpy as np
    n = int(input())
    a = np.full((n, n), ".", dtype=str)
    a3 = np.array([[".", "a", "a"], ["b", ".", "."], ["b", ".", "."]], dtype=str)
    a4 = np.array([["a", "a", "b", "c"], ["d", "d", "b", "c"],
                   ["a", "c", "d", "d"], ["a", "c", "b", "b"]], dtype=str)
    a5 = np.array([["c", "c", "d", "d", "e"],
                   ["j", ".", "a", "a", "e"],
                   ["j", "b", ".", ".", "f"],
                   ["i", "b", ".", ".", "f"],
                   ["i", "h", "h", "g", "g"]], dtype=str)
    a7 = np.array([[".", "c", "c", "d", "d", "c", "c"],
                   ["c", ".", "a", "a", ".", "a", "a"],
                   ["c", "b", ".", ".", "b", ".", "."],
                   ["d", "b", ".", ".", "b", ".", "."],
                   ["d", ".", "a", "a", ".", "a", "a"],
                   ["c", "b", ".", ".", "b", ".", "."],
                   ["c", "b", ".", ".", "b", ".", "."]], dtype=str)
    a6 = np.full((6, 6), ".", dtype=str)
    for i in range(2):
        a6[3*i:3*i+3, 3*i:3*i+3] = a3
    a11 = np.full((11, 11), ".", dtype=str)
    a11[:4, :4] = a4
    a11[4:, 4:] = a7

    if n == 2:
        print(-1)
        return
    elif n == 3:
        a = a3
    elif n == 6:
        a = a6
    elif n == 7:
        a = a7
    elif n == 11:
        a = a11
    else:
        for p in range(n):
            q = n-4*p
            if q % 5 == 0:
                q //= 5
                break
        for i in range(p):
            a[4*i:4*i+4, 4*i:4*i+4] = a4
        p = 4*p
        for i in range(q):
            a[p+5*i:p+5*i+5, p+5*i:p+5*i+5] = a5

    a = a.tolist()
    for i in a:
        print("".join(i))


main()

Solution (Python):
n = int(input())
if n==2:
    print(-1)
else:
    a3 = ['aa.', '..a', '..a']
    a4 = ['aabc', 'ddbc', 'bcaa', 'bcdd']
    a5 = ['aabba', 'bcc.a', 'b..cb','a..cb', 'abbaa']
    a6 = ["aabc.." , 'ddbc..','..aabc', '..ddbc', "bc..aa", "bc..dd"]
    a7 = ["aabbcc.", "dd.dd.a", "..d..da", "..d..db", "dd.dd.b", "..d..dc", "..d..dc"]
    
    if n==3:
        for p in a3:
            print(p)
    else:
        a44 = ['.'*(n-4) + x for x in a4]
        if n%4==0:
            lt = []
            for i in range(n//4):
                for j in range(len(a44)):
                    a44[j] = a44[j][(n-4):] + a44[j][:(n-4)]
                    lt.append(a44[j])
            for st in lt:
                print(st)
        else:
            x = n//4 - 1 
            r = n%4 + 4 
            q = []
            if r==5:
                q = ['.'*(n - 5) + m for m in a5]
            elif r==6:
                q = ['.'*(n - 6) + m for m in a6]
            elif r==7:
                q = ['.'*(n - 7) + m for m in a7]
            lt = []
            for i in range(x):
                for j in range(len(a44)):
                    a44[j] = a44[j][(n-4):] + a44[j][:(n-4)]
                    lt.append(a44[j])
            for j in q:
                lt.append(j)
            for st in lt:
                print(st)

Solution (Python):
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline



def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    N = gete(int)

    g = [["."] * N for _ in range(N)]

    d = dict()

    d[(3, 1)] = (".zz", "z..", "z..")
    d[(3, 2)] = ("aab", "b.b", "baa")
    d[(4, 3)] = ("aaba", "ccba", "abcc", "abaa")
    d[(5, 3)] = ("aabbc", "bc..c", "bc..b", "a.ccb", "abbaa")

    def fill(si, sj, b):
        nb = len(b)
        for i in range(nb):
            for j in range(nb):
                g[si + i][sj + j] = b[i][j]

    if N <= 2:
        print(-1)
        return
    elif N == 3:
        fill(0, 0, d[(3, 1)])
    elif N & 1 == 0:
        
        
        n, m = 0, 0
        while 6 * m <= N:
            if (N - 6 * m) % 4 == 0:
                n = (N - 6 * m) // 4
                break
            m += 1
        for k in range(m):
            fill(6 * k, 6 * k, d[(3, 1)])
            fill(6 * k + 3, 6 * k + 3, d[(3, 1)])
            fill(6 * k, 6 * k + 3, d[(3, 2)])
            fill(6 * k + 3, 6 * k, d[(3, 2)])
        for k in range(n):
            fill(6 * m + 4 * k, 6 * m + 4 * k, d[(4, 3)])

    elif N == 7:
        _s = "aabbcc."
        for i in range(N):
            g[i][6] = _s[i]
            g[6][i] = _s[i]
        for k in range(2):
            for l in range(2):
                fill(3 * k, 3 * l, d[(3, 1)])

    elif N == 11:
        fill(0, 0, d[(3, 1)])
        fill(3, 3, d[(3, 1)])
        fill(3, 0, d[(3, 2)])
        fill(0, 3, d[(3, 2)])

        fill(6, 6, d[(5, 3)])

    else:
        
        
        n, m = 0, 0
        while 5 * m <= N:
            if (N - 5 * m) % 4 == 0:
                n = (N - 5 * m) // 4
                break
            m += 1

        for k in range(m):
            fill(5 * k, 5 * k, d[(5, 3)])
        for k in range(n):
            fill(5 * m + 4 * k, 5 * m + 4 * k, d[(4, 3)])

    print(*["".join(g[i]) for i in range(N)], sep="\n")


if __name__ == "__main__":
    main()

Solution (Python):
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline



def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    N = gete(int)

    g = [["."] * N for _ in range(N)]

    d = dict()

    d[(3, 1)] = (".zz", "z..", "z..")
    d[(3, 2)] = ("aab", "b.b", "baa")
    d[(4, 3)] = ("aaba", "ccba", "abcc", "abaa")
    d[(5, 3)] = ("aabbc", "bc..c", "bc..b", "a.ccb", "abbaa")

    if N == 2:
        print(-1)
        return
    elif N == 3:
        for i in range(3):
            for j in range(3):
                g[i][j] = d[(3, 1)][i][j]
    elif N & 1 == 0:
        
        
        n, m = 0, 0
        while 6 * m <= N:
            if (N - 6 * m) % 4 == 0:
                n = (N - 6 * m) // 4
                break
            m += 1
        
        for k in range(m):
            for i in range(3):
                for j in range(3):
                    g[6 * k + i][6 * k + j] = d[(3, 1)][i][j]
                    g[6 * k + 3 + i][6 * k + 3 + j] = d[(3, 1)][i][j]
                    g[6 * k + i][6 * k + 3 + j] = d[(3, 2)][i][j]
                    g[6 * k + 3 + i][6 * k + j] = d[(3, 2)][i][j]
        for k in range(n):
            for i in range(4):
                for j in range(4):
                    g[6 * m + 4 * k + i][6 * m + 4 * k + j] = d[(4, 3)][i][j]

    elif N == 7:
        
        _s = "aabbcc."
        for i in range(N):
            g[i][6] = _s[i]
            g[6][i] = _s[i]
        for k in range(2):
            for l in range(2):
                for i in range(3):
                    for j in range(3):
                        g[3 * k + i][3 * l + j] = d[(3, 1)][i][j]

    elif N == 11:
        
        for k in range(1):
            for i in range(3):
                for j in range(3):
                    g[6 * k + i][6 * k + j] = d[(3, 1)][i][j]
                    g[6 * k + 3 + i][6 * k + 3 + j] = d[(3, 1)][i][j]
                    g[6 * k + i][6 * k + 3 + j] = d[(3, 2)][i][j]
                    g[6 * k + 3 + i][6 * k + j] = d[(3, 2)][i][j]
        for k in range(1):
            for i in range(5):
                for j in range(5):
                    g[6 + i][6 + j] = d[(5, 3)][i][j]

    else:
        
        
        n, m = 0, 0
        while 5 * m <= N:
            if (N - 5 * m) % 4 == 0:
                n = (N - 5 * m) // 4
                break
            m += 1
        
        for k in range(m):
            for i in range(5):
                for j in range(5):
                    g[5 * k + i][5 * k + j] = d[(5, 3)][i][j]
        for k in range(n):
            for i in range(4):
                for j in range(4):
                    g[5 * m + 4 * k + i][5 * m + 4 * k + j] = d[(4, 3)][i][j]

    print(*["".join(g[i]) for i in range(N)], sep="\n")


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())

if N == 2:
    print(-1)
    exit()
if N == 3:
    print('aa.')
    print('..a')
    print('..a')
    exit()

def f(n,m):
    a = ''
    b = ''
    for i in range(n):
        if i == 2*m-2 or i == 2*m-1:
            a += 'a'
            b += 'b'
        elif i == n-2*m:
            a += 'a'
            b += 'a'
        elif i == n-2*m+1:
            a += 'b'
            b += 'b'
        else:
            a += '.'
            b += '.'
    print(a)
    print(b)

def g(n,m):
    a = ''
    b = ''
    for i in range(n):
        if i == 2*m-2:
            a += 'a'
            b += 'a'
        elif i == 2*m-1:
            a += 'b'
            b += 'b'
        elif i == n-2*m or i == n-2*m+1:
            a += 'a'
            b += 'b'
        else:
            a += '.'
            b += '.'
    print(a)
    print(b)

if N % 4 == 0:
    for i in range(N//4 - 1):
        f(N,i+1)
    a = ''
    b = ''
    c = ''
    d = ''
    for i in range(N):
        if i == (N//2) - 2:
            a += 'a'
            b += 'd'
            c += 'c'
            d += 'c'
        elif i == (N//2) - 1:
            a += 'a'
            b += 'd'
            c += 'b'
            d += 'b'
        elif i == N//2:
            a += 'b'
            b += 'b'
            c += 'a'
            d += 'd'
        elif i == (N//2) + 1:
            a += 'c'
            b += 'c'
            c += 'a'
            d += 'd'
        else:
            a += '.'
            b += '.'
            c += '.'
            d += '.'
    print(a)
    print(b)
    print(c)
    print(d)
    for i in range(N//4-1):
        g(N,(N//4)-i-1)

if N % 4 == 1:
    for i in range(N//4 - 1):
        f(N,i+1)
    a = ''
    b = ''
    c = ''
    d = ''
    e = ''
    for i in range(N):
        if i == (N//2) - 2:
            a += 'a'
            b += 'a'
            c += 'b'
            d += 'b'
            e += 'a'
        elif i == (N//2) - 1:
            a += 'b'
            b += 'c'
            c += '.'
            d += '.'
            e += 'a'
        elif i == N//2:
            a += 'b'
            b += 'c'
            c += '.'
            d += '.'
            e += 'b'
        elif i == (N//2) + 1:
            a += 'a'
            b += '.'
            c += 'a'
            d += 'a'
            e += 'b'
        elif i == (N//2) + 2:
            a += 'a'
            b += 'b'
            c += 'b'
            d += 'c'
            e += 'c'
        else:
            a += '.'
            b += '.'
            c += '.'
            d += '.'
            e += '.'
    print(a)
    print(b)
    print(c)
    print(d)
    print(e)
    for i in range(N//4-1):
        g(N,(N//4)-i-1)

if N % 4 == 2:
    for i in range(N//4 - 1):
        f(N,i+1)
    a = ''
    b = ''
    c = ''
    d = ''
    e = ''
    f = ''
    for i in range(N):
        if i == (N//2) - 3:
            a += 'a'
            b += 'a'
            c += 'b'
            d += 'b'
            e += 'a'
            f += 'a'
        elif i == (N//2) - 2:
            a += 'b'
            b += 'b'
            c += 'a'
            d += 'a'
            e += 'b'
            f += 'b'
        elif i == (N//2) - 1:
            a += 'a'
            b += '.'
            c += 'b'
            d += '.'
            e += 'a'
            f += '.'
        elif i == N//2:
            a += 'a'
            b += '.'
            c += 'b'
            d += '.'
            e += 'a'
            f += '.'
        elif i == (N//2) + 1:
            a += '.'
            b += 'b'
            c += '.'
            d += 'a'
            e += '.'
            f += 'b'
        elif i == (N//2) + 2:
            a += '.'
            b += 'b'
            c += '.'
            d += 'a'
            e += '.'
            f += 'b'
        else:
            a += '.'
            b += '.'
            c += '.'
            d += '.'
            e += '.'
            f += '.'
    print(a)
    print(b)
    print(c)
    print(d)
    print(e)
    print(f)
    for i in range(N//4-1):
        g(N,(N//4)-i-1)

if N % 4 == 3:
    for i in range(N//4 - 1):
        f(N,i+1)
    a = ''
    b = ''
    c = ''
    d = ''
    e = ''
    f = ''
    h = ''
    for i in range(N):
        if i == (N//2) - 3:
            a += 'a'
            b += 'b'
            c += 'a'
            d += '.'
            e += '.'
            f += '.'
            h += '.'
        elif i == (N//2) - 2:
            a += 'a'
            b += 'b'
            c += 'a'
            d += '.'
            e += '.'
            f += '.'
            h += '.'
        elif i == (N//2) - 1:
            a += 'b'
            b += 'a'
            c += 'b'
            d += '.'
            e += '.'
            f += '.'
            h += '.'
        elif i == N//2:
            a += 'b'
            b += 'a'
            c += 'b'
            d += '.'
            e += '.'
            f += '.'
            h += '.'
        elif i == (N//2) + 1:
            a += 'c'
            b += 'c'
            c += '.'
            d += 'b'
            e += 'b'
            f += 'a'
            h += 'a'
        elif i == (N//2) + 2:
            a += '.'
            b += '.'
            c += 'c'
            d += 'a'
            e += 'a'
            f += 'b'
            h += 'b'
        elif i == (N//2) + 3:
            a += '.'
            b += '.'
            c += 'c'
            d += 'b'
            e += 'b'
            f += 'a'
            h += 'a'
        else:
            a += '.'
            b += '.'
            c += '.'
            d += '.'
            e += '.'
            f += '.'
            h += '.'
    print(a)
    print(b)
    print(c)
    print(d)
    print(e)
    print(f)
    print(h)
    for i in range(N//4-1):
        g(N,(N//4)-i-1)

Solution (Python):
n=int(input())

if n==2:
  print(-1)
elif n==3:
  print('aab')
  print('d.b')
  print('dcc')
elif n%4==0:
  for i in range(n//4):
    temp=['.'*n]*4
    temp[0]=temp[0][:4*i]+'aabd'+temp[0][(i+1)*4:]
    temp[1]=temp[1][:4*i]+'ccbd'+temp[1][(i+1)*4:]
    temp[2]=temp[2][:4*i]+'efgg'+temp[2][(i+1)*4:]
    temp[3]=temp[3][:4*i]+'efhh'+temp[3][(i+1)*4:]
    print(temp[0])
    print(temp[1])
    print(temp[2])
    print(temp[3])
elif n%4==1:
  temp=['']*5
  temp[0]='aabbc'+'.'*(n-5)
  temp[1]='fg..c'+'.'*(n-5)
  temp[2]='fg..d'+'.'*(n-5)
  temp[3]='h.jjd'+'.'*(n-5)
  temp[4]='hiiee'+'.'*(n-5)
  print(temp[0])
  print(temp[1])
  print(temp[2])
  print(temp[3])
  print(temp[4])
  for i in range(n//4-1):
    temp=['.'*n]*4
    temp[0]=temp[0][:4*i+5]+'aabd'+temp[0][(i+1)*4+5:]
    temp[1]=temp[1][:4*i+5]+'ccbd'+temp[1][(i+1)*4+5:]
    temp[2]=temp[2][:4*i+5]+'efgg'+temp[2][(i+1)*4+5:]
    temp[3]=temp[3][:4*i+5]+'efhh'+temp[3][(i+1)*4+5:]
    print(temp[0])
    print(temp[1])
    print(temp[2])
    print(temp[3])
elif n%4==2:
  temp=['']*6
  temp[0]='a.ccaa'+'.'*(n-6)
  temp[1]='ab.bb.'+'.'*(n-6)
  temp[2]='cb...c'+'.'*(n-6)
  temp[3]='c...bc'+'.'*(n-6)
  temp[4]='.bb.ba'+'.'*(n-6)
  temp[5]='aacc.a'+'.'*(n-6)
  print(temp[0])
  print(temp[1])
  print(temp[2])
  print(temp[3])
  print(temp[4])
  print(temp[5])
  for i in range(n//4-1):
    temp=['.'*n]*4
    temp[0]=temp[0][:4*i+6]+'aabd'+temp[0][(i+1)*4+6:]
    temp[1]=temp[1][:4*i+6]+'ccbd'+temp[1][(i+1)*4+6:]
    temp[2]=temp[2][:4*i+6]+'efgg'+temp[2][(i+1)*4+6:]
    temp[3]=temp[3][:4*i+6]+'efhh'+temp[3][(i+1)*4+6:]
    print(temp[0])
    print(temp[1])
    print(temp[2])
    print(temp[3])
else:
  temp=['']*7
  temp[0]='a.aa.aa'+'.'*(n-7)
  temp[1]='a...bc.'+'.'*(n-7)
  temp[2]='....bcd'+'.'*(n-7)
  temp[3]='a..ee.d'+'.'*(n-7)
  temp[4]='abb..a.'+'.'*(n-7)
  temp[5]='.cc..ab'+'.'*(n-7)
  temp[6]='dd.aa.b'+'.'*(n-7)
  print(temp[0])
  print(temp[1])
  print(temp[2])
  print(temp[3])
  print(temp[4])
  print(temp[5])
  print(temp[6])
  for i in range(n//4-1):
    temp=['.'*n]*4
    temp[0]=temp[0][:4*i+7]+'aabd'+temp[0][(i+1)*4+7:]
    temp[1]=temp[1][:4*i+7]+'ccbd'+temp[1][(i+1)*4+7:]
    temp[2]=temp[2][:4*i+7]+'efgg'+temp[2][(i+1)*4+7:]
    temp[3]=temp[3][:4*i+7]+'efhh'+temp[3][(i+1)*4+7:]
    print(temp[0])
    print(temp[1])
    print(temp[2])
    print(temp[3])

Solution (Python):
N=int(input())
ans=[["." for i in range(N)] for j in range(N)]
if N==2:
    print(-1)
    exit()
elif N%3==0:
    if N%3==0:
        for i in range(N//3):
            ans[3*i][3*i]="a"
            ans[3*i][3*i+1]="a"
            ans[3*i+1][3*i+2]="a"
            ans[3*i+2][3*i+2]="a"
elif N==11:
    i=0;r=0
    ans[5*i+4*r][5*i+4*r:5*i+4*r+5]=["a","a","b","b","c"]
    ans[5*i+4*r+1][5*i+4*r:5*i+4*r+5]=["b","d","d",".","c"]
    ans[5*i+4*r+2][5*i+4*r:5*i+4*r+5]=["b",".",".","e","b"]
    ans[5*i+4*r+3][5*i+4*r:5*i+4*r+5]=["c",".",".","e","b"]
    ans[5*i+4*r+4][5*i+4*r:5*i+4*r+5]=["c","b","b","a","a"]
    ans[5][5:]=["a","a",".","b","b","a"]
    ans[6][5:]=[".",".","a","c",".","a"]
    ans[7][5:]=[".",".","a","c","b","b"]
    ans[8][5:]=["a","b","b","a","a","."]
    ans[9][5:]=["a",".","a",".",".","a"]
    ans[10][5:]=["c","c","a",".",".","a"]
elif N==7:
    ans[0]=[".",".",".","a",".","d","e"]
    ans[1]=[".",".",".","a",".","d","e"]
    ans[2]=[".",".","b","b","c","a","a"]
    ans[3]=["b","b","e",".","c",".","."]
    ans[4]=[".",".","e","d","d","e","e"]
    ans[5]=["b","b","f",".","c",".","."]
    ans[6]=["a","a","f",".","c",".","."]
else:
    r=5-N%5
    if r==5:
        r=0
    for i in range(0,r):
        ans[4*i][4*i]="a"
        ans[4*i][4*i+1]="a"
        ans[4*i][4*i+2]="c"
        ans[4*i][4*i+3]="d"
        ans[4*i+1][4*i]="b"
        ans[4*i+1][4*i+1]="b"
        ans[4*i+1][4*i+2]="c"
        ans[4*i+1][4*i+3]="d"
        ans[4*i+2][4*i]="c"
        ans[4*i+2][4*i+1]="d"
        ans[4*i+2][4*i+2]="a"
        ans[4*i+2][4*i+3]="a"
        ans[4*i+3][4*i]="c"
        ans[4*i+3][4*i+1]="d"
        ans[4*i+3][4*i+2]="b"
        ans[4*i+3][4*i+3]="b"
    for i in range((N-4*r)//5):
        ans[5*i+4*r][5*i+4*r:5*i+4*r+5]=["a","a","b","b","c"]
        ans[5*i+4*r+1][5*i+4*r:5*i+4*r+5]=["b","d","d",".","c"]
        ans[5*i+4*r+2][5*i+4*r:5*i+4*r+5]=["b",".",".","e","b"]
        ans[5*i+4*r+3][5*i+4*r:5*i+4*r+5]=["c",".",".","e","b"]
        ans[5*i+4*r+4][5*i+4*r:5*i+4*r+5]=["c","b","b","a","a"]

for i in range(N):
    print("".join(ans[i]))

Solution (Python):
n = int(input())
s3=["abb","a.d","ccd"]

s = [["abcc", "abdd", "ddba", "ccba"],
["dccdd", "daa.c", "c..bc", "c..bd", "ddccd"],
["abbc..", "a.ac..", "bba.cc", "a..aab", "a..b.b", ".aabaa"],
["aba....","aba....","bab....","bab....","a..bbaa","a..aabb",".aabbaa"]]
if n == 2:
    print(-1)
elif n == 3:
    [print(x) for x in s3]
else:
    d, m = divmod(n, 4)
    d -= 1
    m += 4
    for i in range(d):
        [print("." * 4 * i + x + "." * (4 * (d - i - 1) + m)) for x in s[0]]
    [print("." * 4 * d + x) for x in s[m - 4]]

Solution (Python):
import sys

dominoes = [
    """
    aa.
    ..a
    ..a
    """,
    """
    aabc
    ddbc
    bcaa
    bcdd
    """,
    """
    aabba
    bcc.a
    b..cb
    a..cb
    abbaa
    """,
    """
    aabc..
    ddbc..
    ..aabc
    ..ddbc
    bc..aa
    bc..dd
    """,
    """
    aabbcc.
    dd.dd.a
    ..d..da
    ..d..db
    dd.dd.b
    ..d..dc
    ..d..dc
    """
]


dominoes = [domino.replace(' ', '').strip('\n') for domino in dominoes]

n = int(input())

if n == 2:
    print(-1)
    exit(0)

if n == 3:
    print(dominoes[0])
    exit(0)

dominoes = [dom.split('\n') for dom in dominoes[1:]]


def write(ix, col):
    for j in range(ix + 4):
        for i in range(col):
            sys.stdout.write('.')
        sys.stdout.write(dominoes[ix][j])
        for i in range(n - col - (ix + 4)):
            sys.stdout.write('.')
        sys.stdout.write('\n')


col = 0
write(n % 4, col)
col += 4 + n % 4
rem = n - col

while rem > 0:
    write(0, col)
    col += 4
    rem -= 4

Solution (Python):
n = int(input())
if n == 2:
  print(-1)
if n == 3:
  print("aa.")
  print("..b")
  print("..b")
if n == 4:
  ans = ["aabc","ddbc","bcaa","bcdd"]
  print(*ans,sep="\n")
if n == 5:
  ans = ["aabbc","dde.c","..eab","a..ab","accdd"]
  print(*ans,sep="\n")
if n == 6:
  ans = ["aa.bbc","..de.c","..deff","aabcc.","d.b..a","dcc..a"]
  print(*ans,sep="\n")
if n == 7:
  ans = ["aab.cc.","..bd..e","ff.d..e","..g.hhi","..gj..i","kllj...","k..mmnn"]
  print(*ans,sep="\n")
if n >= 8:
  ans = [["." for i in range(n)] for j in range(n)]
  ch = [list("aabc"),list("ddbc"),list("bcaa"),list("bcdd")]
  x = n//4-1
  y = n%4+4
  for i in range(x):
    for j in range(4):
      for k in range(4):
        ans[i*4+j][i*4+k] = ch[j][k]
  if y == 4:
    for j in range(4):
      for k in range(4):
        ans[x*4+j][x*4+k] = ch[j][k]
  elif y == 5:
    ch2 = ["aabbc","dde.c","..eab","a..ab","accdd"]
    for j in range(5):
      for k in range(5):
        ans[x*4+j][x*4+k] = ch2[j][k]
  elif y == 6:
    ch2 = ["aa.bbc","..de.c","..deff","aabcc.","d.b..a","dcc..a"]
    for j in range(6):
      for k in range(6):
        ans[x*4+j][x*4+k] = ch2[j][k]
  elif y == 7:
    ch2 = ["aab.cc.","..bd..e","ff.d..e","..g.hhi","..gj..i","kllj...","k..mmnn"]
    for j in range(7):
      for k in range(7):
        ans[x*4+j][x*4+k] = ch2[j][k]

  for row in ans:
    print(*row,sep="")

Solution (Python):
import os
import sys
from collections import Counter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7



N = int(sys.stdin.buffer.readline())

ans = np.full((N, N), '.', dtype='U1')


def check():
    qualities = []
    board = np.full((N + 2, N + 2), '.', dtype='U1')
    board[1:-1, 1:-1] = ans
    for row in board[1:-1]:
        q = 0
        for a, b in zip(row, row[1:]):
            q += a != b and b != '.'
        qualities.append(q)
    for col in board.T[1:-1]:
        q = 0
        for a, b in zip(col, col[1:]):
            q += a != b and b != '.'
        qualities.append(q)
    if len(Counter(qualities).keys()) == 1:
        return qualities[0]
    else:
        return -1


def ps(ans, q):
    print(q)
    print('\n'.join(map(lambda r: ''.join(r), ans)))


def dfs(i):
    h = i // N
    w = i % N
    c = chr(ord('a') + i % 26)
    if i == N ** 2:
        q = check()
        if q > 0:
            ps(ans, q)
        return
    if w < N - 1 and ans[h, w] == ans[h, w + 1] == '.':
        ans[h, w] = c
        ans[h, w + 1] = c
        dfs(i + 1)
        ans[h, w] = '.'
        ans[h, w + 1] = '.'
    if h < N - 1 and ans[h, w] == ans[h + 1, w] == '.':
        ans[h, w] = c
        ans[h + 1, w] = c
        dfs(i + 1)
        ans[h, w] = '.'
        ans[h + 1, w] = '.'
    dfs(i + 1)


s3 = '''
aa.
..f
..f
'''.strip()

s4 = '''
abcc
abgg
iikl
mmkl
'''.strip()

s5 = '''
aacce
ffh.e
..hno
p..no
pvvxx
'''.strip()

s6 = '''
a..abb
a..a.f
.hhggf
yzza..
y.xa..
ddx.hh
'''.strip()

s7 = '''
aa.ee.f
d.bb..f
de..cc.
.e..ghh
j.zzg..
jbc....
.bc..kk
'''.strip()

if N <= 2:
    print(-1)
    exit()
if N == 3:
    print(s3)
    exit()


def fill(h, w, rows: str):
    for i, row in enumerate(rows.split('\n')):
        ans[h + i, w:w + len(row)] = list(row)


i = 0
n = N
while n >= 8:
    fill(i, i, s4)
    i += 4
    n -= 4
if n == 7:
    fill(i, i, s7)
if n == 6:
    fill(i, i, s6)
if n == 5:
    fill(i, i, s5)
if n == 4:
    fill(i, i, s4)
print('\n'.join(map(lambda r: ''.join(r), ans)))

Solution (Python):
N = int(input())

A = [[] for _ in range(8)]
a,b,c,d,e,f,g = list("abcdefg")
o = "."
A[3] = [[o,a,a],
        [b,o,o],
        [b,o,o]]
A[4] = [[a,a,b,c],
        [d,d,b,c],
        [b,c,a,a],
        [b,c,d,d]]
A[5] = [[o,o,a,b,c],
        [o,o,a,b,c],
        [a,a,d,d,e],
        [b,b,f,o,e],
        [c,c,f,g,g]]
A[6] = [[o,a,a,c,c,d],
        [b,o,o,e,o,d],
        [b,o,o,e,f,f],
        [c,c,d,o,a,a],
        [e,o,d,b,o,o],
        [e,f,f,b,o,o]]
A[7] = [[o,o,o,o,a,b,a],
        [o,o,o,o,a,b,a],
        [o,o,o,o,b,a,b],
        [o,o,o,o,b,a,b],
        [a,a,b,b,o,c,c],
        [b,b,a,a,d,o,o],
        [a,a,b,b,d,o,o]]


if N == 2:
  print(-1)
  exit()
if N == 3:
  for i in range(3):
    print("".join(A[3][i]))
  exit()

D = [[o] * N for _ in range(N)]
div, mod = divmod(N, 4)

for i in range(div - 1):
  x = i * 4
  for j in range(4):
    for k in range(4):
      D[x + j][x + k] = A[4][j][k]

x = (div - 1) * 4
for i in range(4 + mod):
  for j in range(4 + mod):
    D[x + i][x + j] = A[4 + mod][i][j]

for i in D:
  print("".join(i))

Solution (Python):
N = int(input())
state = [list("."*N) for _ in range(N)]

def fill_block3_1(h, w):
    state[h][w] = "a"
    state[h][w+1] = "a"
    state[h+1][w+2] = "b"
    state[h+2][w+2] = "b"

def fill_block3_2(h, w):
    state[h][w] = "c"
    state[h+1][w] = "c"
    state[h][w+1] = "d"
    state[h][w+2] = "d"
    state[h+2][w] = "e"
    state[h+2][w+1] = "e"
    state[h+1][w+2] = "f"
    state[h+2][w+2] = "f"


def solve_5_6n(start_h, start_w, k, s1, s2):
    cycle = 2*k+1
    size = 3*cycle+2
    num_2 = k
    for h3 in range(cycle):
        for w3 in range(cycle):
            if (h3+w3)%cycle < num_2:
                fill_block3_2(start_h+3*h3+1, start_w+3*w3+1)
            else:
                fill_block3_1(start_h+3*h3+1, start_w+3*w3+1)
    
    for x in range(size-1):
        if x%4 in [0, 1]:
            state[start_h][start_w+x] = s1
            state[start_h+size-2-x][start_w+size-1] = s2
            state[start_h+size-1][start_w+size-1-x] = s1
            state[start_h+1+x][start_w] = s2
        else:
            state[start_h][start_w+x] = s2
            state[start_h+size-2-x][start_w+size-1] = s1
            state[start_h+size-1][start_w+size-1-x] = s2
            state[start_h+1+x][start_w] = s1


def solve_2_6n(start_h, start_w, k, s1, s2):
    cycle = 2*k
    size = 3*cycle+2
    num_2 = k-2
    if k == 1:
        fill_block3_1(start_h+1, start_w+1)
        fill_block3_1(start_h+4, start_w+4)
    else:
        for h3 in range(cycle):
            for w3 in range(cycle):
                if (h3+w3)%cycle < num_2:
                    fill_block3_2(start_h+3*h3+1, start_w+3*w3+1)
                else:
                    fill_block3_1(start_h+3*h3+1, start_w+3*w3+1)
    for x in range(1, size-1):
        if x%4 in [1, 2]:
            state[start_h][start_w+x] = s1
            state[start_h+x][start_w] = s1
            state[start_h+size-1][start_w+x] = s1
            state[start_h+x][start_w+size-1] = s1
        else:
            state[start_h][start_w+x] = s2
            state[start_h+x][start_w] = s2
            state[start_h+size-1][start_w+x] = s2
            state[start_h+x][start_w+size-1] = s2


def solve_1_6n(start_h, start_w, k, s1, s2):
    cycle = 2*k
    size = 3*cycle+1
    for h3 in range(cycle):
        for w3 in range(cycle):
            if (h3+w3)%cycle < k-1:
                fill_block3_2(start_h+3*h3+1, start_w+3*w3+1)
            else:
                fill_block3_1(start_h+3*h3+1, start_w+3*w3+1)
    for x in range(1, size):
        if x%4 in [1, 2]:
            state[start_h][start_w+x] = s1
            state[start_h+x][start_w] = s1
        else:
            state[start_h][start_w+x] = s2
            state[start_h+x][start_w] = s2


def main():
    if N == 2:
        return -1
    if N == 4:
        state = [
            ["a", "a", "c", "d"],
            ["b", "b", "c", "d"],
            ["e", "f", "g", "g"],
            ["e", "f", "h", "h"]
        ]
        return state
    if N%3 == 0:
        l = N//3
        for h in range(l):
            for w in range(l):
                fill_block3_1(3*h, 3*w)
        return
    elif N%6 == 5:
        k = (N-5)//6
        solve_5_6n(0, 0, k, "x", "y")
        return
    elif N%6 == 2:
        k = (N-2)//6
        solve_2_6n(0, 0, k, "x", "y")
        return
    elif N%6 == 1:
        solve_1_6n(0, 0, (N-1)//6, "x", "y")
        return
    else:
        l = (N//2-2)//3
        if l%2 == 1:
            solve_5_6n(0, 0, (l-1)//2, "s", "t")
            solve_5_6n(N//2, 0, (l-1)//2, "u", "v")
            solve_5_6n(0, N//2, (l-1)//2, "w", "x")
            solve_5_6n(N//2, N//2, (l-1)//2, "y", "z")
        else:
            solve_2_6n(0, 0, l//2, "s", "t")
            solve_2_6n(N//2, 0, l//2, "u", "v")
            solve_2_6n(0, N//2, l//2, "w", "x")
            solve_2_6n(N//2, N//2, l//2, "y", "z")
        return


if __name__ == "__main__":
    ret = main()
    if ret == -1:
        print(-1)
    elif not ret is None:
        for h in range(N):
            print("".join(ret[h]))
    else:
        for h in range(N):
            print("".join(state[h]))