program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: h,w,n,i,j,ii
    integer(int32), allocatable:: ans(:,:)
    integer(int32), allocatable:: a(:), color(:)
    logical,allocatable:: painted(:,:)

    read*, h,w
    allocate(ans(w,h))
    allocate(painted(w,h), source=.false.)
    read*, n
    allocate(a(n))
    allocate(color(w*h))
    read*, a(:)
    ii=1

    do i=1,n
        do j=1,a(i)
            color(ii) = i
            ii=ii+1
        end do
    end do
    call paint(1,1,0,1)
    do i=1,h
        print'(*(i0,1x))', ans(:,i)
    end do

contains
    recursive subroutine paint(x,y,n,i)
        integer(int32):: dx(0:3)=[0,1,0,-1], dy(0:3)=[1,0,-1,0]
        integer(int32):: x,y,n, nn
        integer(int32):: i
        if (i > h*w) return
        ans(x,y) = color(i)
        painted(x,y) = .true.
        if (is_range(x+dx(n), 1, w) .and. is_range(y+dy(n), 1, h)) then
            nn = n
            if (painted(x+dx(nn),y+dy(nn))) nn = mod(n+1,4)
            call paint(x+dx(nn), y+dy(nn), nn, i+1)
        else
            nn = mod(n+1,4)
            if (is_range(x+dx(nn), 1, w) .and. is_range(y+dy(nn), 1, h)) then
                call paint(x+dx(nn), y+dy(nn), nn, i+1)
            end if
        end if
    end subroutine

    function is_range(val, fst, lst) result(ret)
        integer(int32):: val, fst, lst
        logical:: ret
        ret = fst <= val .and. val <= lst
    end function
end program main