import java.io.*;

public class S5
{
    static boolean[] [] visited;
    static boolean[] numVisited = {false, false, false, false, false};
    static int endX;
    static int endY;
    static PrintWriter output;

    public static void main (String[] args) throws Exception
    {
	BufferedReader input = new BufferedReader (new FileReader ("DATA5.txt"));
	output = new PrintWriter (new FileWriter ("OUT5.txt"));
	int numLines = Integer.parseInt (input.readLine ());
	input.readLine ();
	String[] data = new String [numLines];
	for (int counter = 0 ; counter < numLines ; counter++)
	{
	    data [counter] = input.readLine ();
	}

	char[] [] map = new char [numLines] [data [0].length ()];
	for (int row = 0 ; row < data.length ; row++)
	{
	    for (int col = 0 ; col < data [row].length () ; col++)
	    {
		map [row] [col] = data [row].charAt (col);
	    }
	}

	visited = new boolean [map.length] [map [0].length];
	for (int r = 0 ; r < visited.length ; r++)
	    for (int c = 0 ; c < visited [r].length ; c++)
		visited [r] [c] = false;
	for (char start = '1' ; start <= '5' ; start++)
	{
	    for (int row = 0 ; row < map.length ; row++)
	    {
		for (int col = 0 ; col < map [row].length ; col++)
		{
		    if (map [row] [col] == start)
		    {
			output.print (start + ":");
			find (map, row, col, start);


			for (int r = 0 ; r < visited.length ; r++)
			    for (int c = 0 ; c < visited [r].length ; c++)
				visited [r] [c] = false;

			for (int i = 0 ; i < numVisited.length ; i++)
			    numVisited [i] = false;
			output.println ();
		    }

		}
	    }
	}

	output.close ();
    }


    static void find (char[] [] map, int row, int col, char start) throws Exception
    {
	if (map [row] [col] == '#')
	    return;
	if (!visited [row] [col])
	    visited [row] [col] = true;
	else
	    return;
	if (Character.isDigit (map [row] [col]) && map [row] [col] != start && !numVisited [Integer.parseInt ("" + map [row] [col])])
	{
	    output.print (map [row] [col] + " ");
	    numVisited [Integer.parseInt ("" + map [row] [col])] = true;
	}

	if (row > 0 && (map [row - 1] [col] != '#'))
	    find (map, row - 1, col, start);
	if (row < map.length - 1 && (map [row + 1] [col] != '#'))
	    find (map, row + 1, col, start);
	if (col > 0 && (map [row] [col - 1] != '#'))
	    find (map, row, col - 1, start);
	if (col < map [0].length - 1 && (map [row] [col + 1] != '#'))
	    find (map, row, col + 1, start);

	if (Character.isLowerCase (map [row] [col]))
	{
	    for (int r = 0 ; r < map.length ; r++)
	    {
		for (int c = 0 ; c < map [r].length ; c++)
		{
		    if (map [r] [c] == Character.toUpperCase (map [row] [col]))
			find (map, r, c, start);
		}
	    }
	}
    }
}



