def parse(inFile):
    return [inFile.getInts() for k in xrange(inFile.getInts()[0])]

def solve(grid):
    [w,h] = [len(grid[0]),len(grid)]
    dest = [[(i,j) for j in xrange(w)] for i in xrange(h)]
    for i in xrange(h):
        for j in xrange(w):
            if (i > 0) and grid[i-1][j] < grid[dest[i][j][0]][dest[i][j][1]]:
                dest[i][j] = (i - 1, j)
            if (j > 0) and grid[i][j-1] < grid[dest[i][j][0]][dest[i][j][1]]:
                dest[i][j] = (i, j - 1)
            if (j + 1 < w) and grid[i][j+1] < grid[dest[i][j][0]][dest[i][j][1]]:
                dest[i][j] = (i, j + 1)
            if (i + 1 < h) and grid[i+1][j] < grid[dest[i][j][0]][dest[i][j][1]]:
                dest[i][j] = (i + 1, j)
    for k in xrange(14):
        for i in xrange(h):
            for j in xrange(w):
                (i0,j0) = dest[i][j]
                dest[i][j] = dest[i0][j0]
    grid = [["" for g in row] for row in grid]
    labels = {}
    nextLabel = "a"
    for i in xrange(h):
        for j in xrange(w):
            if labels.has_key(dest[i][j]):
                grid[i][j] = labels[dest[i][j]]
            else:
                labels[dest[i][j]] = nextLabel
                grid[i][j] = nextLabel
                nextLabel = chr(ord(nextLabel) + 1)
    return "\n".join([""]+[" ".join(row) for row in grid])

if __name__ == "__main__":
    from GCJ import GCJ
    GCJ(parse, solve, "/Users/lpebody/gcj/2009_q/", "b").run()
