// ラベリング処理 Labeling
//
// author: Leonardone @ NEETSDKASU
//
import java.util.*;
import java.lang.*;
import java.io.*;

class Ideone
{
	static int[][] map;
	static int[] groupLink;
	static int nextGroupID = 1;
	static int h, w;
	
	static int getGroupID(int x, int y) {
		if (x < 0 | x >= w | y < 0 | y >= h) {
			return 0;
		}
		int g = map[y][x];
		while (groupLink[g] != g) {
			g = groupLink[g];
		}
		map[y][x] = g;
		return g;
	}
	
	static void setGroupID(int x, int y) {
		int ga = getGroupID(x - 1, y);
		int gb = getGroupID(x, y - 1);
		if (ga == 0 && gb == 0) {
			map[y][x] = nextGroupID;
			groupLink[nextGroupID] = nextGroupID;
			nextGroupID++;
		} else if (ga == 0) {
			map[y][x] = gb;
		} else if (gb == 0) {
			map[y][x] = ga;
		} else if (ga < gb) {
			groupLink[gb] = ga;
			map[y][x] = ga;
		} else if (ga > gb) {
			groupLink[ga] = gb;
			map[y][x] = gb;
		}
	}
	
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner in = new Scanner(System.in);
		
		w = in.nextInt();
		h = in.nextInt();
		
		map = new int[h][w];
		groupLink = new int[h * w + 1];
		
		for (int i = 0; i < h; i++) {
			String line = in.next();
			for (int j = 0; j < w; j++) {
				if (line.charAt(j) == '1') {
					setGroupID(j, i);
				}
				System.out.printf("%02d ", map[i][j]);
			}
			System.out.println();
		}
		
		System.out.println();
		System.out.println();
		
		Map<Integer, Character> groupChar = new HashMap<>();
		char ch = 'A';
		
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				Integer g = getGroupID(j, i);
				if (g > 0) {
					if (groupChar.containsKey(g) == false) {
						groupChar.put(g, ch);
						ch++;
					}
					System.out.print(groupChar.get(g));
				} else {
					System.out.print('0');
				}
			}
			System.out.println();
		}
	}
}