n = int(eval(input()))

s = [list(ord(e) - ord("a") for e in eval(input())) for _ in range(n)]



ans = 0

for b in range(n):

    t = [[-1] * n for _ in range(n)]

    for hi in range(n):

        for wi in range(n):

            nh = hi

            nw = (wi + b) % n

            t[nh][nw] = s[hi][wi]



    bl = True

    for i in range(n):

        for j in range(n):

            if t[i][j] != t[j][i]:

                bl = False



    ans += bl



ans *= n

print(ans)

import numpy as np



n = int(eval(input()))

s = np.array([list(ord(e) - ord("a") for e in eval(input())) for _ in range(n)], np.int8)

s = np.hstack((s, s))



ans = 0

for b in range(n):

    t = s[:, b:b+n]

    if (t == t.T).all():

        ans += 1



ans *= n

print(ans)

n = int(eval(input()))
s = [list(ord(e) - ord("a") for e in eval(input())) for _ in range(n)]
ans = 0
for b in range(n):
    t = [[-1] * n for _ in range(n)]
    for hi in range(n):
        for wi in range(n):
            nh = hi
            nw = (wi + b) % n
            t[nh][nw] = s[hi][wi]
    bl = True
    for i in range(n):
        for j in range(n):
            if t[i][j] != t[j][i]:
                bl = False
    ans += bl
ans *= n
print(ans)

import numpy as np

n = int(eval(input()))
s = np.array(
    [list(ord(e) - ord("a") for e in eval(input())) for _ in range(n)], np.int8
)
s = np.hstack((s, s))
ans = 0
for b in range(n):
    t = s[:, b : b + n]
    if (t == t.T).all():
        ans += 1
ans *= n
print(ans)

+import numpy as np + -s = [list(ord(e) - ord("a") for e in eval(input())) for _ in range(n)] +s = np.array( +    [list(ord(e) - ord("a") for e in eval(input())) for _ in range(n)], np.int8 +) +s = np.hstack((s, s)) -    t = [[-1] * n for _ in range(n)] -    for hi in range(n): -        for wi in range(n): -            nh = hi -            nw = (wi + b) % n -            t[nh][nw] = s[hi][wi] -    bl = True -    for i in range(n): -        for j in range(n): -            if t[i][j] != t[j][i]: -                bl = False -    ans += bl +    t = s[:, b : b + n] +    if (t == t.T).all(): +        ans += 1