{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TypeApplications #-}

module Main where

import Control.Lens
import Control.Monad
import Control.Monad.Cont
import qualified Data.ByteString.Char8 as BS
import qualified Data.Char as Char
import Data.Function (on)
import qualified Data.List as List
import Data.Traversable (for)
import qualified Data.Vector.Unboxed as VU

type Point = (Int, Int)

type Strawberry = Point

type LeftTop = Point

type RightBottom = Point

type Area = (LeftTop, RightBottom)

main :: IO ()
main = do
  [h, w, k] <- BS.getLine <&> toListOf (unfolded (BS.readInt . BS.dropWhile Char.isSpace))
  lines <- replicateM h BS.getLine
  let strawberries :: [Strawberry]
      strawberries = lines ^.. (indexing each <.> indexing each) . filtered (== fromIntegral (Char.ord '#')) . asIndex
  let answer = solve ((0, 0), (h - 1, w - 1)) strawberries
  for [0 .. h - 1] $ \ih -> do
    for [0 .. w - 1] $ \iw -> do
      let p =
            answer & findIndexOf itraversed ( \p -> (p ^. _1 . _1 <= ih && ih <= p ^. _2 . _1) && (p ^. _1 . _2 <= iw && iw <= p ^. _2 . _2))
              & (^?! _Just)
      putStr (show p) *> putChar ' '
    putChar '\n'
  pure ()

solve :: Area -> [Strawberry] -> [Area]
solve cake [x] = [cake]
solve cake strawberries@(a : b : _) =
  if a ^. _1 == b ^. _1
    then verticalSplit (snd a) strawberries
    else horizontalSplit (fst a) strawberries
  where
    horizontalSplit p ss =
      let (top, bottom) = List.partition (\s -> fst s <= p) ss
       in solve (cake & _2 . _1 .~ p) top <> solve (cake & _1 . _1 .~ p + 1) bottom
    verticalSplit p ss =
      let (left, right) = List.partition (\s -> snd s <= p) ss
       in solve (cake & _2 . _2 .~ p) left <> solve (cake & _1 . _2 .~ p + 1) right
