#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let (h,w,k) = get!(usize, usize, usize);
    let s = get!(String;h).into_iter().map(|e| e.chars().collect::<Vec<_>>()).collect::<Vec<_>>();
    let nums = s.iter().map(|ref e| e.iter().filter(|&&e| e=='#').count()).collect::<Vec<_>>();
    let mut sums = vec![0; h+1];
    for i in 0..h {
        sums[i+1] = sums[i] + nums[i];
    }
    let mut now = 1;
    let mut res = vec![String::new(); h];
    for x in 0..h {
        if x > 0 && nums[x] == 0 {
            res[x] = res[x-1].clone();
            continue;
        }
        let mut row = String::new();
        for y in 0..w {
            row += &format!("{} ", now);
            if s[x][y] == '#' && now + 1 <= sums[x+1] {
                now += 1;
            }
        }
        res[x] = row;
        if now == sums[x+1] {
            now += 1;
        }
    }
    let mut i = 0;
    while i < h {
        if nums[i] == 0 {
            i += 1;
            continue;
        }
        for j in 0..i {
            res[j] = res[i].clone();
        }
        break;
    }
    for e in res {
        println!("{}", e);
    }
}


Measured memory_bytes: 9084