from itertools import product from functools import cache try: import pypyjit pypyjit.set_param('max_unroll_recursion=-1') except ModuleNotFoundError: pass MOD = 998244353 N = int(input()) S = [] for i in range(N): S.append(input()) @cache def f(r1, c1, r2, c2) -> int: if r1 == r2 and c1 == c2: return 1 if r1 == r2 and c1+1 == c2: return 1 if S[r1][c1] == S[r2][c2] else 0 if r1+1 == r2 and c1 == c2: return 1 if S[r1][c1] == S[r2][c2] else 0 if S[r1][c1] != S[r2][c2]: return 0 res = 0 for (dr1, dc1), (dr2, dc2) in product([(0, 1), (1, 0)], [(0, -1), (-1, 0)]): nr1 = r1 + dr1 nc1 = c1 + dc1 nr2 = r2 + dr2 nc2 = c2 + dc2 if nr1 > nr2: continue if nc1 > nc2: continue res += f(nr1, nc1, nr2, nc2) res %= MOD return res ans = f(0, 0, N-1, N-1) print(ans)