import Control.Monad
import Data.List
import Data.List.Split

main = do
    getLine
    ss <- lines <$> getContents
    mapM_ putStrLn . map (unwords . (map show)). numbering 1 $ cut ss

cut ss = map (\xs -> (map length (cut2 (head xs)), length xs)) $ cut1 ss

cut1 ss = f $ split (keepDelimsL $ whenElt (any (=='#'))) ss
    where f (xs:xss) | null xs = xss 
                     | otherwise = let (ys:yss) = xss in (ys ++ xs) : yss

cut2 s = f $ split (keepDelimsL $ whenElt (== '#')) s
    where f (x:xs) | null x = xs
                   | otherwise = let (y:ys) = xs in (y ++ x) : ys

numbering _ [] = []
numbering k ((xs,l):xss) = replicate l (g k xs) ++ numbering (k + length xs) xss
    where g k xs = concat $ zipWith replicate xs [k..] 