#include <stdio.h>
int main() {
char a[21][21];
int m,n,k,s[100],o=0;
for(int i=0;i<100;i++){
s[i]=0;
}
scanf("%d%d%d",&m,&n,&k);
int x=0,y=m-1;
for(int i=0;i<m;i++){
scanf("%s",&a[i]);
}
for(int i=0;i<k;i++){
int z;
scanf("%d",&z);
if(z==0 && y>0){
y=y-1;
printf("%c",a[y][x]);
s[a[y][x]-'A']=s[a[y][x]-'A']+1;
}
else if(z==1 && x<n-1){
x=x+1;
printf("%c",a[y][x]);
s[a[y][x]-'A']=s[a[y][x]-'A']+1;
}
else if(z==2 && y<m-1 && x<n-1){
y=y+1;
x=x+1;
printf("%c",a[y][x]);
s[a[y][x]-'A']=s[a[y][x]-'A']+1;
}
else if(z==3 && y<m-1){
y=y+1;
printf("%c",a[y][x]);
s[a[y][x]-'A']=s[a[y][x]-'A']+1;
}
else if(z==4 && x>0){
x=x-1;
printf("%c",a[y][x]);
s[a[y][x]-'A']=s[a[y][x]-'A']+1;
}
else if(z==5 && y>0 && x>0){
y=y-1;
x=x-1;
printf("%c",a[y][x]);
s[a[y][x]-'A']=s[a[y][x]-'A']+1;
}
else{
printf("%c",a[y][x]);
s[a[y][x]-'A']=s[a[y][x]-'A']+1;
}
}
for(int i=0;i<100;i++){
if(s[i]!=0){
o=o+1;
}
}
printf("\n%d",o);
return 0;
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
o:字母種總數
s[]:每種字母出現次數
z:前進方向