var i,j,r:integer; s,a:array[1..4,1..4] of char; c:string; begin for i:=1 to 4 do begin readln(s[1,i]); readln(s[2,i]); readln(s[3,i]); readln(s[4,i]); end; for j:=1 to 4 do begin read(a[1,j]); read(a[2,j]); read(a[3,j]); read(a[4,j]); end; writeln; for i:=1 to 4 do for j:=1 to 4 do if s[i,j]='X' then c:=c+a[i,j]; for j:=1 to 4 do for i:=4 downto 1 do if s[i,j]='X' then c:=c+a[j,5-i]; for i:=4 downto 1 do for j:=4 downto 1 do if s[i,j]='X' then c:=c+a[5-i,5-j]; for j:=4 downto 1 do for i:=1 to 4 do if s[i,j]='X' then c:=c+a[5-j,i]; write(c); end.