import itertools as it N = int(input()) C = [input() for _ in range(N)] P = 998244353 if C[0][0] != C[-1][-1]: print(0) quit() cs = it.combinations(list(range(2 * (N - 1))), N - 1) ans = 0 for c in cs: y, x = 0, 0 j = 0 s = [] for i in range(N - 2): if i == c[j]: x += 1 j += 1 else: y += 1 s.append(C[y][x]) if N - 2 == c[j]: x += 1 j += 1 else: y += 1 for i in range(N - 2): if j < N - 1 and i + N - 1 == c[j]: x += 1 j += 1 else: y += 1 if C[y][x] != s[-1 - i]: break else: ans = (ans + 1) % P print(ans)