#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define nline cout<<"\n"
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define ain(A, B, C) assert(IN(A, B, C))
#define ull unsigned long long int
#define ll long long int
#define pii pair<int,int>
#define MAXX 1009
#define fr(a,b,i) for(int i=a;i<b;i++)
vector<int>G[MAXX];
char mat[MAXX][MAXX];
int n,cnt=0;
string s="";
string final;
void backtrack(int x,int y)
{
if(x>n-1 or y>n-1 or x<0 or y<0)return ;
s+=mat[x][y];
if(s.size()==4)
{
if(s==final)
cnt++;
return ;
}
backtrack(x-1,y-1);
backtrack(x+1,y+1);
backtrack(x+1,y-1);
backtrack(x-1,y+1);
}
int main()
{
fast;
cin>>n;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
cin>>mat[i][j];
cin>>final;
backtrack(0,0);
cout<<cnt<<endl;
return 0;
}
ICAgICAgICAgICAgI2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KCQkJdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCQkJI2RlZmluZSBwYiBwdXNoX2JhY2sKCQkJI2RlZmluZSBtcCBtYWtlX3BhaXIKCQkJI2RlZmluZSBubGluZSBjb3V0PDwiXG4iCgkJCSNkZWZpbmUgZmFzdCBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKSxjaW4udGllKDApCgkJCSNkZWZpbmUgYWluKEEsIEIsIEMpIGFzc2VydChJTihBLCBCLCBDKSkKCQkJI2RlZmluZSB1bGwgdW5zaWduZWQgbG9uZyBsb25nIGludAoJCQkjZGVmaW5lIGxsIGxvbmcgbG9uZyBpbnQKCQkJI2RlZmluZSBwaWkgcGFpcjxpbnQsaW50PgoJCQkjZGVmaW5lIE1BWFggMTAwOQoJCQkjZGVmaW5lIGZyKGEsYixpKSBmb3IoaW50IGk9YTtpPGI7aSsrKQoJCQl2ZWN0b3I8aW50PkdbTUFYWF07CgkJCWNoYXIgbWF0W01BWFhdW01BWFhdOwo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