program cast;

const nic = '.';
      tecka = 'X';
      kostka = '*';
      zpractecka = '-';
      zprackostka = '0';

var width, height: integer;
    Bod: array[1..500,1..500] of char;
    radek: string[500];
    i,j: integer;

procedure ProjdiTEcku(x,y: integer);
var konec: boolean;
begin
  (*
  konec := false;
  repeat
    {ln('zpracovavam od bodu ',x,',',y);}
    repeat
      Bod[x,y] := zpractecka;
      inc(y);
      
      while (x>1) and (Bod[x-1,y] = tecka) do begin
        dec(x);
	while(y>1) and (Bod[x,y-1] = tecka) do dec(y);       
      end;
      
    until (y> width) or ( Bod[x,y] <> tecka);
    if x = Height then exit;
    
    if (y<= Width) then dec(y);
    
    { while (y>1) and (Bod[x,y] = zpractecka ) and (Bod[x+1, y] <> tecka) do dec(y);
    if Bod[x+1,y] <> tecka then 
      konec := true
    else begin
      x := x +1;
      while (y>1) and (Bod[x,y-1] in [tecka, zpractecka]) do dec(y);
    end; }
    
    while (y>1) and (Bod[x,y-1] = zpractecka) do dec(y);
    x := x+1;
    if (Bod[x,y] = tecka) then begin
      while (y>1) and (Bod[x,y-1] = tecka) do dec(y);    
    end else begin
      while(y<Width) and (Bod[x,y+1] <> tecka) do inc(y);
      if (y=Width) then konec := true else y := y+1;
    end;
    
  until konec;  
  
  *)
  
  Bod[x,y] := zpractecka;
  if (x>1) and (Bod[x-1,y] = tecka) then ProjdiTecku(x-1,y);
  if (y>1) and (Bod[x,y-1] = tecka) then ProjdiTecku(x,y-1);
  if (x<Height) and (Bod[x+1,y] = tecka) then ProjdiTecku(x+1,y);
  if (y<Width) and (Bod[x,y+1] = tecka) then ProjdiTecku(x,y+1);    
end;  
    
function ProjdiKostku(x, y: integer): byte;
var konec: boolean;
    pocettecek: byte;
  { i: integer;}
begin
  pocettecek := 0; 
 
(*
 { writeln('VOla se projdikostku(',x,',',y,');');}
  pocettecek := 0; konec := false;
  repeat
    {writeln('Zpracovavam od bodu ',x,',',y);}
    repeat
      if Bod[x,y] = tecka then begin
        ProjdiTecku(x,y); inc(Pocettecek);
      end;
      Bod[x,y] := zprackostka;
      inc(y);
      
      while (x>1) and (Bod[x-1,y] in [tecka, kostka, zpractecka]) do begin
        dec(x);
	while(y>1) and (Bod[x,y-1] in [tecka, kostka, zpractecka]) do dec(y);       
      end;

    until (y> width) or ( Bod[x,y] = nic);
{    writeln('KOnec radku na ',x,',',y);
    for i := 1 to width do write(Bod[x,i]);}
    
    if x = Height then begin
      ProjdiKostku := pocettecek;
      exit;
    end;
    if (y<= Width) then dec(y);
    
    { while (y>1) and (Bod[x,y] <> nic ) and (Bod[x+1, y] = nic) do dec(y);
    if Bod[x+1,y] = nic then 
      konec := true
    else begin
      x := x +1;
      while (y>1) and (Bod[x,y-1] <> nic) do dec(y);
    end; }
    while (y>1) and (Bod[x,y-1] in [zpractecka, zprackostka]) do dec(y);
    x := x+1;
    if (Bod[x,y] in [tecka,kostka]) then begin
      while (y>1) and (Bod[x,y-1] in [tecka,kostka]) do dec(y);    
    end else begin
      while(y<Width) and not(Bod[x,y+1] in [tecka,kostka]) do inc(y);
      if (y=Width) then konec := true else y := y+1;
    end;
     
  until konec;
  ProjdiKostku := pocettecek;    
 { writeln('Vysledek je ',pocettecek);}
 
 *)
  if Bod[x,y]= tecka then begin
    inc(pocettecek);
    ProjdiTecku(x,y);
  end;
  Bod[x,y] := zprackostka;
  if (x>1) and (Bod[x-1,y] in [kostka, tecka, zpractecka]) then
    pocettecek := pocettecek + ProjdiKostku(x-1,y);
  if (x<Height) and (Bod[x+1,y] in [kostka, tecka, zpractecka]) then
    pocettecek := pocettecek + ProjdiKostku(x+1,y);
  if (y>1) and (Bod[x,y-1] in [kostka, tecka, zpractecka]) then
    pocettecek := pocettecek + ProjdiKostku(x,y-1);
  if (y<Width) and (Bod[x,y+1] in [kostka, tecka, zpractecka]) then
    pocettecek := pocettecek + ProjdiKostku(x,y+1);
  ProjdiKostku := Pocettecek;
end;

var PoctyTecek: array[1..6] of integer;
    pocettecek : byte;    

begin
  readln(height, width);
  while (height <> 0) and (width <> 0) do begin
    for i:=1 to height do begin
      readln(Bod[i]);
    end;
    for i:= 1 to 6 do PoctyTecek[i] := 0;
      
    for i := 1 to height do begin
      for j := 1 to width do begin
        if Bod[i,j] in [tecka, kostka] then begin
	  pocettecek := ProjdiKostku(i,j);
	  inc(PoctyTecek[pocettecek]);
	end;    
      end;
    end;
    
    write('Throw:');
    for j := 1 to 6 do begin
      for i:= 1 to PoctyTecek[j] do write(' ',j);
    end;
    writeln;
    readln(height, width);
  end;
end.  