N = int(eval(input()))

S=[]

for i in range(N):

    s =list(eval(input()))

    S.append(s)

num=0

for a in range(N):

    t =1

    #flag = True

    for i in range(N):

        #if not flag:

           # break

        for j in range(N):

            if i==j:

                continue

            #x = (i+a)%N

            #y=j

            if S[(j+a)%N][i]!=S[(i+a)%N][j]:

                t=0

                #flag=False

                #break

    if t:

        num+=1

print((N*num))



N = int(eval(input()))

S=[]

for i in range(N):

    s =list(eval(input()))

    S.append(s)

num=0

for a in range(N):

    t =1

    flag = True

    for i in range(N):

        if not flag:

            break

        for j in range(N):

            if i==j:

                continue

            #x = (i+a)%N

            #y=j

            if S[(j+a)%N][i]!=S[(i+a)%N][j]:

                t=0

                flag=False

                break

    if t:

        num+=1

print((N*num))



N = int(eval(input()))
S = []
for i in range(N):
    s = list(eval(input()))
    S.append(s)
num = 0
for a in range(N):
    t = 1
    # flag = True
    for i in range(N):
        # if not flag:
        # break
        for j in range(N):
            if i == j:
                continue
            # x = (i+a)%N
            # y=j
            if S[(j + a) % N][i] != S[(i + a) % N][j]:
                t = 0
                # flag=False
                # break
    if t:
        num += 1
print((N * num))

N = int(eval(input()))
S = []
for i in range(N):
    s = list(eval(input()))
    S.append(s)
num = 0
for a in range(N):
    t = 1
    flag = True
    for i in range(N):
        if not flag:
            break
        for j in range(N):
            if i == j:
                continue
            # x = (i+a)%N
            # y=j
            if S[(j + a) % N][i] != S[(i + a) % N][j]:
                t = 0
                flag = False
                break
    if t:
        num += 1
print((N * num))

-    # flag = True +    flag = True -        # if not flag: -        # break +        if not flag: +            break -                # flag=False -                # break +                flag = False +                break