program ddcc2020qualc
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: h,w,k
    integer(int32):: i,num,x,y,endy,endx
    integer(int32), allocatable:: a(:,:)
    character(:),allocatable:: s(:)

    read*, h,w,k
    allocate(character(w):: s(h))
    allocate(a(w,h), source=0)
    do i=1,h
        read*, s(i)
    end do
    num = 1
    endy = 0
    do y=1,h
        endx=0
        do x=1,w
            if (s(y)(x:x) == '#') then
                a(endx+1:x,endy+1:y) = num
                endx = x
                num=num+1
            end if
        end do
        if (endx < w .and. endy < h)then
            a(endx+1:w,endy+1:y) = num-1
        end if
        if (endx /= 0) endy=y 
    end do

    do i=1,h
        print*, a(:,i)
    end do
end program ddcc2020qualc