{
Written by Fyodor Menshikov 16.02.2005
15:25-15:37,+5min idea correction
}
const
   di:array[1..8]of integer=( 1, 1, 1, 0,-1,-1,-1, 0);
   dj:array[1..8]of integer=( 1, 0,-1,-1,-1, 0, 1, 1);
var
   a:array[0..21,0..21]of char;
   ah,aw:integer;
   words:array[1..100]of string[20];
   found:array[1..100]of boolean;
   wcnt:integer;
   i,j,k,l,ii,jj:integer;
   s:string;
begin
   assign(input,ParamStr(1));
   reset(input);
   assign(output,ParamStr(2));
   rewrite(output);
   readln(ah,aw);
   for i:=0 to ah+1 do
      for j:=0 to aw+1 do
         a[i,j]:='#';
   for i:=1 to ah do begin
      for j:=1 to aw do begin
         if eoln then
            halt(1);
         read(a[i,j]);
      end;
      if not eoln then
         halt(1);
      readln;
   end;
   wcnt:=0;
   for i:=1 to ah do begin
      for j:=1 to aw do begin
         if a[i,j]<>'#' then begin
            if (a[i-1,j]='#') and (a[i+1,j]<>'#') then begin
               s:='';
               ii:=i;
               while a[ii,j]<>'#' do begin
                  s:=s+a[ii,j];
                  inc(ii);
               end;
               inc(wcnt);
               words[wcnt]:=s;
               found[wcnt]:=false;
            end;
            if (a[i,j-1]='#') and (a[i,j+1]<>'#') then begin
               s:='';
               jj:=j;
               while a[i,jj]<>'#' do begin
                  s:=s+a[i,jj];
                  inc(jj);
               end;
               inc(wcnt);
               words[wcnt]:=s;
            end;
         end;
      end;
   end;
   readln(ah,aw);
   for i:=0 to ah+1 do
      for j:=0 to aw+1 do
         a[i,j]:='#';
   for i:=1 to ah do begin
      for j:=1 to aw do begin
         if eoln then
            halt(1);
         read(a[i,j]);
      end;
      if not eoln then
         halt(1);
      readln;
   end;
   for i:=1 to ah do begin
      for j:=1 to aw do begin
         for k:=1 to 8 do begin
            ii:=i;
            jj:=j;
            s:='';
            while a[ii,jj]<>'#' do begin
               s:=s+a[ii,jj];
               ii:=ii+di[k];
               jj:=jj+dj[k];
               for l:=1 to wcnt do
                  if words[l]=s then
                     found[l]:=true;
            end;
         end;
      end;
   end;
   for i:=1 to wcnt do
      if not found[i] then
         writeln(words[i]);
end.