#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; const int INF = 0x3f3f3f3f; const int MAXN=510; const int mod=5201314; LL dp[2][MAXN][MAXN]; char mapp[MAXN][MAXN]; int n,m; bool check(int x) { return x>=1&&x<=n; } int main() { int t; scanf("%d",&t); while(t--) { scanf("%d",&n); for(int i=1; i<=n; i++) scanf("%s",mapp[i]+1); int k=0; m=n; memset(dp,0,sizeof(dp)); for(int step=(n+m)/2; step>0; step--) { k^=1; for(int c1=1; c1<=m; c1++) { for(int c2=c1; c2<=m; c2++) { int r1=step-c1+1; int r2=n+m-step-c2+1; if(!(check(r1)&&check(r2)&&r1<=r2)) continue; if(mapp[r1][c1]==mapp[r2][c2]) { if(r1==r2&&c1==c2)dp[k][c1][c2]=1; else if(r1==r2&&c1+1==c2)dp[k][c1][c2]=1; else if(r1+1==r2&&c1==c2)dp[k][c1][c2]=1; else dp[k][c1][c2]=(dp[k^1][c1+1][c2]+dp[k^1][c1+1][c2-1]+dp[k^1][c1][c2-1]+dp[k^1][c1][c2])%mod; } else dp[k][c1][c2]=0; } } } printf("%I64d\n",dp[k][1][m]%mod); } return 0; }