import sys

input = sys.stdin.readline



N = int(eval(input()))

S = [list(input().rstrip()) for _ in range(N)]

row = [[0] * 26 for _ in range(N)]

col = [[0] * 26 for _ in range(N)]

for i in range(N):

    for j in range(N):

        c = ord(S[i][j]) - ord('a')

        row[i][c] += 1

        col[j][c] += 1

ans = 0

same = [[row[i] == col[j] for j in range(N)] for i in range(N)]

for i in range(N):

    for j in range(N):

        if all(same[(i+k) % N][(j+k) % N] for k in range(N)):

            ans += 1

print(ans)
N=int(eval(input()))

X=list(range(N))

S=[eval(input())for _ in X]

print((sum(all(S[(i+k)%N][j]==S[(j+k)%N][i]for i in X for j in X)for k in X)*N))
import sys

input = sys.stdin.readline
N = int(eval(input()))
S = [list(input().rstrip()) for _ in range(N)]
row = [[0] * 26 for _ in range(N)]
col = [[0] * 26 for _ in range(N)]
for i in range(N):
    for j in range(N):
        c = ord(S[i][j]) - ord("a")
        row[i][c] += 1
        col[j][c] += 1
ans = 0
same = [[row[i] == col[j] for j in range(N)] for i in range(N)]
for i in range(N):
    for j in range(N):
        if all(same[(i + k) % N][(j + k) % N] for k in range(N)):
            ans += 1
print(ans)

N = int(eval(input()))
X = list(range(N))
S = [eval(input()) for _ in X]
print(
    (
        sum(
            all(S[(i + k) % N][j] == S[(j + k) % N][i] for i in X for j in X) for k in X
        )
        * N
    )
)

-import sys - -input = sys.stdin.readline -S = [list(input().rstrip()) for _ in range(N)] -row = [[0] * 26 for _ in range(N)] -col = [[0] * 26 for _ in range(N)] -for i in range(N): -    for j in range(N): -        c = ord(S[i][j]) - ord("a") -        row[i][c] += 1 -        col[j][c] += 1 -ans = 0 -same = [[row[i] == col[j] for j in range(N)] for i in range(N)] -for i in range(N): -    for j in range(N): -        if all(same[(i + k) % N][(j + k) % N] for k in range(N)): -            ans += 1 -print(ans) +X = list(range(N)) +S = [eval(input()) for _ in X] +print( +    ( +        sum( +            all(S[(i + k) % N][j] == S[(j + k) % N][i] for i in X for j in X) for k in X +        ) +        * N +    ) +)