program problemFloodFill;

type	tField =	array[ 1..14 ] of string[14];

var	ans: array[ 1..25 ] of char;
	ans_n: longInt;

function dfs( var f: tField; x, y: longInt; c: char ): longInt;
var	old: char;
	res: longInt;
begin
	res := 1;
	old := f[x][y];
	
	f[x][y] := c;
	
	if ( x > 1 ) and ( f[x - 1][y] = old ) then
		inc( res, dfs( f, x - 1, y, c ) );
	
	if ( x < 14 ) and ( f[x + 1][y] = old ) then
		inc( res, dfs( f, x + 1, y, c ) );
	
	if ( y > 1 ) and ( f[x][y - 1] = old ) then
		inc( res, dfs( f, x, y - 1, c ) );
	
	if ( y < 14 ) and ( f[x][y + 1] = old ) then
		inc( res, dfs( f, x, y + 1, c ) );
	
	exit( res );
end;
	
function brute( f: tField; k: longInt ): boolean;
var	i, j: longInt;
	g: array[ '0'..'5' ] of tField;
	sz: array[ '0'..'5' ] of longInt;
	ok: boolean;
	c, cc: char;
begin
	ok := true;
	for i := 1 to 14 do
		for j := 1 to 14 do
			if ( not ok ) or ( f[i][j] <> f[1][1] ) then
			begin
				ok := false;
				
				break;
			end;
	
	if ( ok ) then
	begin
		ans_n := k + 1;
	
		exit( true );
	end;
	
	if ( k = 0 ) then
		exit( false );
	
	for c := '0' to '5' do
	begin
		if ( f[1][1] = c ) then
		begin
			sz[c] := -1;
		
			continue;
		end;
		
		g[c] := f;
		dfs( g[c], 1, 1, c );
		g[ f[1][1] ] := g[c];
		sz[c] := dfs( g[ f[1][1] ], 1, 1, f[1][1] );
	end;
	
	for i := 1 to 5 do
	begin
		c := '-';
		for cc := '0' to '5' do
			if ( c = '-' ) or ( sz[cc] > sz[c] ) then
				c := cc;
		
		sz[c] := -1;
		
		if ( brute( g[c], k - 1 ) ) then
		begin
			ans[k] := c;
			
			exit( true );
		end;
	end;
	
	exit( false );
end;

var	i: longInt;
	f: tField;

begin
	for i := 1 to 14 do
		readln( f[i] );
	
	brute( f, 25 );
	
	for i := 25 downto ans_n + 1 do
		write( ans[i], ' ' );
	
	writeln( ans[ans_n] );
end.