jiahuimbzuai/CoQuIR huggingface dataset:
//  [python]
def main():
    H, W, K = list(map(int, input().split()))
    S = []

    for i in range(H):
        s = input()
        S.append(s)

    ans = []
    for i in range(H):
        tmp = []
        ans.append(['.'] * W)

    # non_rows = []
    k = 1
    for i in range(H):
        row = S[i]
        k_c = row.count('#')
        if k_c == 0:
            # non_rows.append(i)
            pass
        else:
            new_row = []
            flag = True
            for si in row:
                if flag:
                    if si == '#':
                        new_row.append(str(k))
                        flag = False
                    elif si == '.':
                        new_row.append(str(k))
                else:
                    if si == '.':
                        new_row.append(str(k))
                    elif si == '#':
                        k += 1
                        new_row.append(str(k))
            flag = True
            k += 1
            ans[i] = new_row
    

    for i in range(1, H):
        if ans[i][0] == '.':
            ans[i] = ans[i-1]

    for i in range(H-1, -1, -1):
        if ans[i][0] == '.':
            ans[i] = ans[i+1]

    for ans1 in ans:
        print(" ".join(ans1))

if __name__ == "__main__":
    main()
//  [python]
# -*- coding: utf-8 -*-

H,W,K=map(int, input().split())
val=[input() for i in range(H)]


temp=[[0]*W for i in range(H)]
counter=1
for j in range(W):
    lbound=0
    for i in range(H):
        if val[i][j]=="#":
            for k in range(H-lbound):
                temp[k+lbound][j]=counter
            counter=counter+1
            lbound=i+1
            
for jtemp in range(W-1):
    j=jtemp+1
    for i in range(H):
            if temp[i][j]==0:
                temp[i][j]=temp[i][j-1]
                
for jtemp in range(W-1):
    j=W-2-jtemp
    for i in range(H):
            if temp[i][j]==0:
                temp[i][j]=temp[i][j+1]  
for i in range(H):
    for j in range(W):
        if j==W-1:
            print(temp[i][j])
        else:
            print(temp[i][j],end=' ')
//  [python]
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

h = 0
w = 0
k = 0
a = []
num = 1
cnt = []
c = []

def rec(x1, y1, x2, y2):
    global num
    # print("x1:{}, y1:{}, x2:{}, y2:{}".format(x1, y1, x2, y2))
    sts = []
    for i in range(y1, y2+1):
        for j in range(x1, x2+1):
            if c[i][j] == '#':
                sts.append((j, i)) # x, y
    if len(sts) == 1:
        for i in range(y1, y2+1):
            for j in range(x1, x2+1):
                a[i][j] = num
        num += 1
        return
    p1, q1 = sts[0]
    p2, q2 = sts[1]
    if q1 < q2:
        rec(x1, y1, x2, q1)
        rec(x1, q1+1, x2, y2)
    else:
        # q1 = q2
        rec(x1, y1, min(p1, p2), y2)
        rec(min(p1, p2)+1, y1, x2, y2)

def main():
    global h, w, k, a, num, cnt, c
    h, w, k = list(map(int, input().strip().split()))
    c = [[0] * w for _ in range(h)]
    a = [[0] * w for _ in range(h)]
    for i in range(h):
        c[i] = input().strip()

    rec(0, 0, w-1, h-1)
    for i in range(h):
        print(" ".join(str(c) for c in a[i]))


if __name__ == '__main__':
    main()
//  [python]
H, W, K = map(int, input().split())
s = [0]*H
a = [[0]*W for _ in range(H)]
for i in range(H):
    s[i] = input()
index = 0
for i in range(H):
    for j in range(W):
        if s[i][j] == '#':
            index += 1
            a[i][j] = index
            for k in range(j+1):
                if a[i][k] == 0:
                    a[i][k] = index
        elif j == W-1:
            if a[i][0] != 0:
                for k in range(j+1):
                    if a[i][k] == 0:
                        a[i][k] = index
for i in range(H-1):
    if a[i][0] == 0 and a[i+1][0] != 0:
        a[i] = a[i+1]
for i in reversed(range(H-1)):
    if a[i][0] == 0 and a[i+1][0] != 0:
        a[i] = a[i+1]
for i in range(1, H):
    if a[i][0] == 0 and a[i-1][0] != 0:
        a[i] = a[i-1]
for i in reversed(range(1, H)):
    if a[i][0] == 0 and a[i-1][0] != 0:
        a[i] = a[i-1]
for i in range(H):
    print(' '.join(map(str, a[i])))
//  [java]
//  PDF 解法2.横に切って、その後縦に切る
import java.util.*;

public class Main {

    public static void main(String[] args) {

    	Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int K = sc.nextInt();

        char[][] cake = new char[H][W];
        int[][] cutCake = new int[H][W];
        String[] str = new String[H];
        boolean hasIchigo = false;
        int a = 1;

        for (int i = 0; i < H; i++) 
        	str[i] = sc.next();

        for (int i = 0; i < H; i++) {
            String s = str[i];
            if (s.contains("#"))
            	hasIchigo = true;

            for (int j = 0; j < W; j++) {
                cake[i][j] = s.charAt(j);
  				cutCake[i][j] = a;
            }
            int k = 1;
  			while (i+k < H && !str[i+k].contains("#")) {
   				for (int l = 0; l < W; l++)
  					cutCake[i+k][l] = a;
  				k++;
  			}
  			i += k-1;
            if (hasIchigo)
            	a++;
            hasIchigo = false;
        }

        for (int i = 0; i < H; i++) {

        	String s = str[i];
        	int firstIndexOfIchigo = s.indexOf('#');
        	int lastIndexOfIchigo = s.lastIndexOf('#');
     
        	if (firstIndexOfIchigo == -1)
        		continue;

        	if (firstIndexOfIchigo == lastIndexOfIchigo)
        		continue;		

        	for (int j = 0; j < W; j++) {

        		if (j <= firstIndexOfIchigo) {

        			int k = 1;
     				while (i-k >= 0 && cutCake[i-k][j] == cutCake[i][j]) {
        				cutCake[i-k][j] = a;
        				k++;
     				}
     				k = 1;
        			while (i+k < H && cutCake[i+k][j] == cutCake[i][j]) {
        				cutCake[i+k][j] = a;
        				k++;
        			}
        			cutCake[i][j] = a;
        		}

        		if (j == firstIndexOfIchigo) {
        			if (!s.contains("#")) 
        				break;
        			s = s.replaceFirst("#", ".");
        			a++;
        			firstIndexOfIchigo = s.indexOf('#');
        			lastIndexOfIchigo = s.lastIndexOf('#');
        			if (firstIndexOfIchigo == lastIndexOfIchigo)
        				break;
        		}
        	}
        }

        for (int i = 0; i < H; i++) {
        	for (int j = 0; j < W; j++) {
        		System.out.print(cutCake[i][j] + " ");
        	}
        	System.out.println();
        }
    }
}
//  [java]
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int H=stdIn.nextInt();
		int W=stdIn.nextInt();
		int K=stdIn.nextInt();
		char s[][]=new char[H][W];
		int A[][]=new int[K][2];
		int map[][]=new int[H][W];
		boolean h[]=new boolean[H];
		int z=0;
		for(int i=0;i<H;i++){
			String a=stdIn.next();
			for(int j=0;j<W;j++){
				s[i][j]=a.charAt(j);
				if(s[i][j]=='#'){
					h[i]=true;
					A[z][0]=i;
					A[z][1]=j;
					z++;
				}
			}
		}
		for(int i=0;i<K;i++){
			int u=A[i][0],d=u,l=A[i][1],r=l;
			map[u][l]=i+1;
			boolean uk=false,dk=false,rk=false,lk=false;
			while(true){
				if(u!=0&&h[u-1]==false){
					u--;uk=true;
				}
				if(d!=H-1&&h[d+1]==false){
					d++;dk=true;
				}
				for(int j=l;j<=r;j++){
					if(uk)
						if(map[u][j]!=0){
							u++;uk=false;
						}
					if(dk)
						if(map[d][j]!=0){
							d--;dk=false;
						}
				}
				if(r!=W-1){
					r++;rk=true;
				}
				if(l!=0){
					l--;lk=true;
				}
				for(int j=u;j<=d;j++){
					if(rk)
						if(map[j][r]!=0||s[j][r]=='#'){
							r--;rk=false;
						}
					if(lk)
						if(map[j][l]!=0||s[j][l]=='#'){
							l++;lk=false;
						}
				}
				if(rk==false&&lk==false&&uk==false&&dk==false){
					for(int j=u;j<=d;j++){
						for(int k=l;k<=r;k++){
							map[j][k]=i+1;
						}
					}
					break;
				}
				rk=false;lk=false;uk=false;dk=false;
			}
		}
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				System.out.println(map[i][j]);
			}
		}
	}
}
//  [cpp]
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int dm = 1 << 20;
char dn[dm], * di = dn;
inline void putint(int X) {
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = ' ';
}

int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int H, W, K;
	scanf("%d", &H);
	scanf("%d", &W);
	scanf("%d", &K);
	getchar_unlocked();

	int kara[300] = {};
	int hajimete = 500;
	int k = 0;
	int kotae[300][300];
	rep(i, H) {
		int aru = 0;
		k++;
		rep(j, W) {
			if (getchar_unlocked() == '#') {
				if (aru == 0) aru = 1;
				else k++;
			}
			kotae[i][j] = k;
		}

		getchar_unlocked();
		if (!aru) {
			kara[i] = 1;
			k--;
			if (hajimete < i) {
				rep(j, W) kotae[i][j] = kotae[i - 1][j];
			}
		}
		if (aru && hajimete == 500) hajimete = i;
	}

	for (int i = H - 1; i >= 0; i--) {
		if (kara[i] && hajimete > i) {
			rep(j, W) kotae[i][j] = kotae[i + 1][j];
		}
	}

	rep(i, H) rep(j, W) putint(kotae[i][j]);

	fwrite(dn, 1, di - dn, stdout);


	Would you please return 0;
}
//  [cpp]
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int dm = 1 << 20;
char dn[dm], * di = dn;
inline void putint(int X) {
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = ' ';
}

int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int H, W, K;
	scanf("%d", &H);
	scanf("%d", &W);
	scanf("%d", &K);
	getchar_unlocked();
	char S[300][300];

	int kara[300] = {};
	int hajimete = 500;
	rep(i, H) {
		int aru = 0;
		rep(j, W) if ((S[i][j] = getchar_unlocked()) == '#') aru = 1;
		getchar_unlocked();
		if (!aru) kara[i] = 1;
		if (aru && hajimete == 500) hajimete = i;
	}

	int k = 0;
	int kotae[300][300];
	rep(i, H) {
		if (!kara[i]) {
			k++;
			int aru = 0;
			rep(j, W) {
				if (S[i][j] == '#') {
					if (aru == 0) aru = 1;
					else k++;
				}
				kotae[i][j] = k;
			}
		}
		else if (hajimete < i) {
			rep(j, W) kotae[i][j] = kotae[i - 1][j];
		}
	}
	for (int i = H - 1; i >= 0; i--) {
		if (kara[i] && hajimete > i) {
			rep(j, W) kotae[i][j] = kotae[i + 1][j];
		}
	}

	rep(i, H) rep(j, W) putint(kotae[i][j]);

	fwrite(dn, 1, di - dn, stdout);


	Would you please return 0;
}
//  [cpp]
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int dm = 1 << 20;
char dn[dm], * di = dn;
inline void putint(int X) {
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = ' ';
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	int H, W, K;
	scanf("%d", &H);
	scanf("%d", &W);
	scanf("%d", &K);
	getchar_unlocked();
	char S[300][300];

	int kara[300] = {};
	int hajimete = 500;
	rep(i, H) {
		int aru = 0;
		rep(j, W) if ((S[i][j] = getchar_unlocked()) == '#') aru = 1;
		getchar_unlocked();
		if (!aru) kara[i] = 1;
		if (aru && hajimete == 500) hajimete = i;
	}

	int k = 0;
	int kotae[300][300];
	rep(i, H) {
		if (!kara[i]) {
			k++;
			int aru = 0;
			rep(j, W) {
				if (S[i][j] == '#') {
					if (aru == 0) aru = 1;
					else k++;
				}
				kotae[i][j] = k;
			}
		}
		else if (hajimete < i) {
			rep(j, W) kotae[i][j] = kotae[i - 1][j];
		}
	}
	for (int i = H - 1; i >= 0; i--) {
		if (kara[i] && hajimete > i) {
			rep(j, W) kotae[i][j] = kotae[i + 1][j];
		}
	}

	rep(i, H) rep(j, W) putint(kotae[i][j]);

	fwrite(dn, 1, di - dn, stdout);


	Would you please return 0;
}
//  [cpp]
#include <iostream>
using namespace std;
using ll = unsigned long long;

ll sumarr(int a[], int n) {
  ll s = 0;
  for (int i = 0; i < n; i++) {
    s += a[i];
  }
  return s;
}


int main() {
  const int hmax = 300;
  const int wmax = 300;
  int H, W, K;
  int pos[hmax * wmax][2];
  int a[hmax][wmax];

  cin >> H;
  cin >> W;
  cin >> K;

  int k = 0;
  int B = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      char c;
      cin >> c;
      if (c == '#') {
        pos[k][0] = i;
        pos[k][1] = j;
        k++;
        if (B < i) B = i;
      }
    }
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      a[i][j] = 0;
    }
  }

  for (k = 0; k < K; k++) {
    int right, bottom;

    if (pos[k][0] == B) {
      bottom = H - 1;
    } else {
      bottom = pos[k][0];
    }

    if (k == K - 1 || pos[k][0] != pos[k + 1][0]) {
      right = W - 1;
    } else {
      right = pos[k][1];
    }

    for (int i = 0; i <= bottom; i++) {
      for (int j = 0; j <= right; j++) {
        // cout << i << " " << j << endl;
        if (a[i][j] == 0) a[i][j] = k + 1;
      }
    }
  }
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
}
//  [c]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll h,w,k;
char s[310][310];
int a[310][310];
int main(){
	scanf("%lld%lld%lld",&h,&w,&k);
	rep(i,0,h)scanf(" %s",s[i]);
	
	ll l=0,cnt=0;
	rep(i,0,h){
		int flag=-1;
		rep(j,0,w)if(s[i][j]=='#')flag=j;
		if(flag==-1)continue;
		rep(j,0,w){
			rep(k,l,i+1)a[k][j]=cnt;
			if(s[i][j]=='#')cnt++;
		}
		rep(j,flag+1,w)rep(k,l,i+1)a[k][j]=cnt-1;
		l=i+1;
	}
	rep(i,l,h)rep(j,0,w)a[i][j]=a[l-1][j];
	
	rep(i,0,h){
		rep(j,0,w)printf("%d ",a[i][j]+1);
		puts("");
	}
}
//  [c]
#include <stdio.h>

int main()
{
	int i, j, H, W, K;
	char s[302][302] = {};
	scanf("%d %d %d", &H, &W, &K);
	for (i = 1; i <= H; i++) scanf("%s", &(s[i][1]));

	int k = 1, l, m, id[302][302] = {}, flag;
	for (i = 1; i <= H; i++) {
		flag = 0;
		for (j = 1; j <= W; j++) {
			id[i][j] = -1;
			if (flag == 1) {
				if (s[i][j] == '#') k++;
				for (l = i; id[l][j] == -1; l--) id[l][j] = k;
			} else if (s[i][j] == '#') {
				flag = 1;
				for (m = 1; m <= j; m++) {
					for (l = i; id[l][m] == -1; l--) id[l][m] = k;
				}
			}
		}
		if (flag == 1) k++;
	}
	
	for (i = H; id[i][1] == -1; i--);
	for (j = 1; j <= W; j++) {
		for (l = i + 1; l <= H; l++) id[l][j] = id[i][j];
	}
		
	for (i = 1; i <= H; i++) {
		for (j = 1; j <= W; j++) printf("%d ", id[i][j]);
		printf("\n");
	}
	fflush(stdout);
	return 0;
}
//  [c]
#include <stdlib.h>
#include <stdio.h>
long long MIN(long long a, long long b){
    return a<b?a:b;
}
int main()
{   int h,w,k;
    scanf("%d%d%d",&h,&w,&k);
    char s[h][w+1];
    for(int i=0;i<h;i++){
        scanf("%s",s[i]);
    }
    int a[300][300]={0},cat=1,map[h];
    for(int i=0;i<h;i++){
        map[i]=0;
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='#'){
               map[i]++; 
            }
        }
    }
    for(int i=0;i<h;i++){
        if(map[i]>0){
            int flag=0,x=0;
            for(int j=0;j<w;j++){
                if(s[i][j]=='#'&&flag==0){
                    while(x<=j){
                        a[i][x]=k;
                        x++;
                    }
                    flag=1;
                }
                if(s[i][j]=='#'){
                    a[i][j]=k;
                    x=j+1;
                    while(s[i][x]=='.'){
                        a[i][x]=k;
                        x++;
                    }
                    k--;
                }
            }
        }
    }
    int up=0,down=0;
    for(int i=0;i<h;i++){
        if(map[i]==0){
            up++;
        }else if(up>0){
            down=i-1;
            while(up>0){
                for(int j=0;j<w;j++){
                    a[down][j]=a[down+1][j];
                }
                down--;
                up--;
            }
            
        }
        if(i==h-1&&up>0){
            while(up>0){
                for(int j=0;j<w;j++){
                a[i-up+1][j]=a[i-up][j];
                }
                up--;
            }
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            printf("%d ",a[i][j]);
        }
        printf("\n");
    }
    return 0;
}
//  [c]
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_SIZE_MAX		305										// 最大サイズ

// 内部変数
static FILE *szpFpI;											// 入力
static int siW, siH;											// 幅・高さ
static char sc2Mass[D_SIZE_MAX][D_SIZE_MAX];					// マス
static int si1SCnt[D_SIZE_MAX];									// イチゴ数
static int si2No[D_SIZE_MAX][D_SIZE_MAX];						// 番号

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 実行メイン
int
fMain(
)
{
	int i, j, k;
	char lc1Buf[2048], lc1Buf2[128];

	// 幅・高さ - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%d", &siH, &siW);

	// マス - 取得
	for (i = 0; i < siH; i++) {
		fgets(sc2Mass[i], sizeof(sc2Mass[0]), szpFpI);
		sc2Mass[i][siW] = '#';

		// イチゴ数 - セット
		for (j = 0; j < siW; j++) {
			if (sc2Mass[i][j] == '#') {
				si1SCnt[i]++;
			}
		}
	}
	si1SCnt[siH] = 1;

	// 番号 - セット
	int liNo = 1;
	int liHSNo = 0;
	while (liHSNo < siH) {
		int liHENo, liHMNo;

		// 範囲 - 行 - 取得
		int liSCnt = 0;
		for (liHENo = liHSNo; ; liHENo++) {
			if (si1SCnt[liHENo] > 0) {
				if (liSCnt == 0) {
					liSCnt++;
					liHMNo = liHENo;
				}
				else {
					liHENo--;
					break;
				}
			}
		}

		// イチゴ数でループ
		int liWSNo = 0;
		for (i = 0; i < si1SCnt[liHMNo]; i++) {
			int liWENo;

			// 範囲 - 列 - 取得
			liSCnt = 0;
			for (liWENo = liWSNo; ; liWENo++) {
				if (sc2Mass[liHMNo][liWENo] == '#') {
					if (liSCnt == 0) {
						liSCnt++;
					}
					else {
						liWENo--;
						break;
					}
				}
			}

			// 番号 - セット
			for (j = liHSNo; j <= liHENo; j++) {
				for (k = liWSNo; k <= liWENo; k++) {
					si2No[j][k] = liNo;
				}
			}
			liNo++;

			// 次の開始列
			liWSNo = liWENo + 1;
		}

		// 次の開始行
		liHSNo = liHENo + 1;
	}

	// 出力
	for (i = 0; i < siH; i++) {
		sprintf(lc1Buf, "%d", si2No[i][0]);
		for (j = 1; j < siW; j++) {
			sprintf(lc1Buf2, " %d", si2No[i][j]);
			strcat(lc1Buf, lc1Buf2);
		}
		strcat(lc1Buf, "\n");
		fOutLine(lc1Buf);
	}

	return 0;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// データ - 初期化
	memset(si1SCnt, 0, sizeof(si1SCnt));						// イチゴ数

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}
//  [c]
#include <stdio.h>

int H, W, K;
char s[512][512];

int answer[512][512];

int main(void) {
	int i, j;
	int next = 0;
	if (scanf("%d%d%d", &H, &W, &K) != 3) return 1;
	for (i = 0; i < H; i++) {
		if (scanf("%511s", s[i]) != 1) return 1;
	}
	for (i = 0; i < H; i++) {
		int exists = 0;
		for (j = 0; j < W; j++) {
			exists = exists || (s[i][j] == '#');
		}
		if (exists) {
			int first = -1;
			for (j = 0; j < W; j++) {
				if (s[i][j] == '#') {
					if (first < 0) first = j;
					next++;
				}
				answer[i][j] = next;
			}
			for (j = 0; j < first; j++) {
				answer[i][j] = answer[i][first];
			}
		}
	}
	for (i = 1; i < H; i++) {
		for (j = 0; j < W; j++) {
			if (answer[i][j] == 0) answer[i][j] = answer[i - 1][j];
		}
	}
	for (i = H - 2; i >= 0; i--) {
		for (j = 0; j < W; j++) {
			if (answer[i][j] == 0) answer[i][j] = answer[i + 1][j];
		}
	}
	for (i = 0; i < H; i++) {
		printf("%d", answer[i][0]);
		for (j = 1; j < W; j++) printf(" %d", answer[i][j]);
		putchar('\n');
	}
	return 0;
}
//  [c]
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); bool s=false; if(c=='-'){s=true;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); int s=0; if(c=='-'){s=1;c=getchar_unlocked();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar_unlocked(); while(c==' '||c=='\n') c=getchar_unlocked(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar_unlocked(); } *s='\0'; return len; }

char s[300][301];
int t[300][300];
int m=1;

void f(int a, int b, int c, int d, int k){
	if(k==1){
		for(int i=a; i<=b; i++){
			for(int j=c; j<=d; j++){
				t[i][j]=m;
			}
		}
		m++;
	}else{
		int x, y;
		for(int i=a; i<=b; i++){
			bool f=false;
			for(int j=c; j<=d; j++){
				if(s[i][j]=='#'){
					x=i; y=j; f=true;
					break;
				}
			}
			if(f) break;
		}
		int i=1;
		for(int j=y+1; j<=d; j++){
			if(s[x][j]=='#') i++;
		}
		if(i==k){
			f(a, b, c, y, 1);
			f(a, b, y+1, d, k-1);
		}else{
			f(a, x, c, d, i);
			f(x+1, b, c, d, k-i);
		}
	}
}

int main(void){
	int h=nextint();
	int w=nextint();
	int k=nextint();
	for(int i=0; i<h; i++){
		nextstr(s[i]);
	}
	f(0, h-1, 0, w-1, k);
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			printf("%d ", t[i][j]);
		}
		putchar(10);
	}
}
//  [javascript]
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input, "index" : 0, "max" : input.length,
  "hasNext" : function(){return (this.index < this.max);},
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  }
}
Main();
function next(){return obj.next();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var one = nextIntArray();
  var H = one[0];
  var W = one[1];
  var K = one[2];
  var count = 0;
  var list = new Array(H);
  var nullIndex = new Set();
  for(var i = 0; i < H; i++){
    list[i] = nextCharArray();
    if(list[i].indexOf("#") == -1){
       nullIndex.add(i);
    }
  }
  myerr(nullIndex);
  for(var i = 0; i < H; i++){
    if(!nullIndex.has(i)){
       count++;
       var isFirst = false;
       for(var j = 0; j < W; j++){
         if(list[i][j] == "#"){
            if(!isFirst){
               isFirst = true;
            }else{
              count++;
            }
            list[i][j] = count;
         }else{
            list[i][j] = count;
         }
       }
    }
  }
  
  var nullKeys = Array.from(nullIndex);
  for(var i = 0; i < nullKeys.length; i++){
    var tmp = nullKeys[i];
    for(var j = 1; j < H; j++){
      var U = tmp - j;
      var D = tmp + j;
      if(U >= 0){
         if(!nullIndex.has(U)){
            list[tmp] = list[U];
            nullIndex.delete(tmp);
            break;
         }
      }
      if(D < H){
         if(!nullIndex.has(D)){
            list[tmp] = list[D];
            nullIndex.delete(tmp);
            break;
         }
      }
    }
  }
  
  for(var i = 0; i < H; i++){
    list[i] = myconv(list[i],8);
  }
  myout(myconv(list,9));
}
//  [javascript]
inp = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n')
l = inp.shift().split(' ')
H = l[0] * 1
W = l[1] * 1
K = l[2] * 1
o = []
idx = 1
r = 0
for (i=0; i<H; i++) {
    a = []
    o[i] = []
    for (j=0; j<W; j++) {
        if (inp[i][j] == '#') {
            a.push(j)
        }
    }
    if (a.length == 0) {
        if (r) {
            o[i] = r
        } else {
            o[i] = 'e'
        }
    } else {
        j = 0
        while(true) {
            k = a.shift()
            if (k === undefined) break;
            while(j <= k) {
                o[i][j] = idx
                j++
            }
            idx++
        }
        while(j<W) {
            o[i][j] = idx-1
            j++
        }
        r = o[i]
    }
}

if (o[0] == 'e') {
    j = 1
    while(o[j] == 'e') j++
    r = o[j]
    j--
    while(j >= 0) {
        o[j--] = r
    }
}
console.log(o.map(a => a.join(" ")).join('\n'))
//  [javascript]
console.log((args=>{
  const [HWK,...s] = args.trim().split`\n`;
  const [H,W,K] = HWK.split` `.map(v=>0|v);
  const map = Array.from({length:H},_=>Array(W).fill(0));
  const cut = (i,j,k) => map[i][j]?(k=map[i][j]):k?(map[i][j]=k):k;
  let g = 0;
  for ( let i = 0; i < H; i++ ) {
    let k = 0;
    for ( let j = 0; j < W; j++ ) {
      if ( s[i][j] === '#' ) k = ++g;
      map[i][j] = k;
    }
    for ( let j = W-1; j >= 0; j-- ) k = cut(i,j,k);
  }
  for ( let j = 0; j < W; j++ ) {
    let k = 0;
    for ( let i = 0; i < H; i++ ) k = cut(i,j,k);
    for ( let i = H-1; i >= 0; i-- ) k = cut(i,j,k);
  }
  return map.map(r=>r.join` `).join`\n`;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));
//  [javascript]
"use strict";
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
var ans,s;

console.log(main());
function main(){
  var h = o.a();
  var w = o.a();
  var k = o.a();
  s = o.r(h,1);
  ans = xArray(1,h,w);
  solve(0,0,h,w,1,k);
  return ans.map(a=>a.join(" ")).join("\n");
}

function solve(y,x,h,w,id,k){
  if(k === 1){
    for(var y3 = y; y3 < h; y3++)
    for(var x3 = x; x3 < w; x3++){
      ans[y3][x3] = id;
    }
    return;
  }
  var y2 = xArray(0,h-y);
  var x2 = xArray(0,w-x);
  for(var y3 = y; y3 < h; y3++){
    for(var x3 = x; x3 < w; x3++){
      if(s[y3][x3] === "#"){
        y2[y3-y]++;
        x2[x3-x]++;
      }
    }
  }
  for(var y3 = y+1; y3 < h; y3++)y2[y3-y] += y2[y3-y-1];
  for(var x3 = x+1; x3 < w; x3++)x2[x3-x] += x2[x3-x-1];
  if(x + 1 === w)return f(y,x,h,w,id,k,y2);
  var xf = x+w>>1;
  xf-= x;
  if(x2[xf] === 0){
    while(++xf){
      if(x2[xf] !== 0)break;
    }
    if(x2[xf] === k)return f(y,x,h,w,id,k,y2);
  }
  if(x2[xf] === k){
    while(--xf){
      if(x2[xf] !== k)break;
    }
    if(x2[xf] === 0 || x2[xf] === k)return f(y,x,h,w,id,k,y2,k);
  }
  solve(y,x,h,xf+x+1,id,x2[xf]);
  solve(y,xf+x+1,h,w,id+x2[xf],k-x2[xf]);
}

function f(y,x,h,w,id,k,y2){
  var yf = y+h>>1;
  yf -= y;
  if(y2[yf] === 0){
    while(++yf){
      if(y2[yf] !== 0)break;
    }
  }else if(y2[yf] === k){
    while(--yf){
      if(y2[yf] !== k)break;
    }
  }
  solve(y,x,yf+y+1,w,id,y2[yf]);
  solve(yf+y+1,x,h,w,id+y2[yf],k-y2[yf]);
}
//  [javascript]
module.exports=function(r){var t={};function e(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return r[n].call(i.exports,i,i.exports,e),i.l=!0,i.exports}return e.m=r,e.c=t,e.d=function(r,t,n){e.o(r,t)||Object.defineProperty(r,t,{enumerable:!0,get:n})},e.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},e.t=function(r,t){if(1&t&&(r=e(r)),8&t)return r;if(4&t&&"object"==typeof r&&r&&r.__esModule)return r;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:r}),2&t&&"string"!=typeof r)for(var i in r)e.d(n,i,function(t){return r[t]}.bind(null,i));return n},e.n=function(r){var t=r&&r.__esModule?function(){return r.default}:function(){return r};return e.d(t,"a",t),t},e.o=function(r,t){return Object.prototype.hasOwnProperty.call(r,t)},e.p="",e(e.s=0)}([function(r,t,e){"use strict";var n=e(1);e(2)(n.readFileSync("/dev/stdin","utf8"))},function(r,t){r.exports=require("fs")},function(r,t,e){"use strict";var n=e(3),i=e(5);r.exports=function(r){var t=new n(r);i(t)}},function(r,t,e){"use strict";var n=e(4);r.exports=class{constructor(r){var t=r.trim().split(/\s+/g);this.inp=new n(t)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(r,t,e){"use strict";r.exports=class{constructor(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=r.length,this.items=r,this.ind=0}enq(r){this.size+=1,this.items.push(r)}deq(){var r=this.items[this.ind];return this.size-=1,this.ind+=1,r}clear(){this.items=[],this.size=0,this.ind=0}}},function(r,t,e){"use strict";r.exports=function(r){for(var t=r.in(),e=r.in(),n=(r.in(),new Array(t)),i=0;i<t;i++)n[i]=r.inr().split("");for(var o=0,s=new Array(t).fill(1),u=0;u<t;u++){for(var f=!1,a=0;a<e;a++)"."==n[u][a]?f&&(n[u][a]=o):(f=!0,o+=1,n[u][a]=o);f||(s[u]=0)}for(var c=t-1;c>=0;c--)for(var l=!1,p=e-1;p>=0;p--)"."==n[c][p]?l&&(n[c][p]=o):(l=!0,o=n[c][p]);for(var d=1;d<t;d++)if(1!=s[d]&&0!=s[d-1]){for(var v=0;v<e;v++)n[d][v]=n[d-1][v];s[d]=1}for(var h=t-2;h>=0;h--)if(1!=s[h]&&0!=s[h+1]){for(var y=0;y<e;y++)n[h][y]=n[h+1][y];s[h]=1}for(var b=0;b<t;b++)console.log(n[b].join(" "))}}]);
//  [go]
package main

import (
	"bufio"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	iv, _ := strconv.Atoi(scanString())
	return iv
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 100001), 100001*100)
}

func main() {
	h, w, _ := scanInt(), scanInt(), scanInt()
	s := make([]string, h)
	for i := range s {
		s[i] = scanString()
	}

	sumW := make([][]int, h)
	sumH := make([][]int, h)
	for i := range s {
		sumW[i] = make([]int, w)
		sumH[i] = make([]int, w)
		for j := range s[i] {
			if j-1 >= 0 {
				sumW[i][j] = sumW[i][j-1]
			}
			if s[i][j] == '#' {
				sumW[i][j]++
			}
		}
	}
	for j := 0; j < w; j++ {
		for i := 0; i < h; i++ {
			if i-1 >= 0 {
				sumH[i][j] = sumH[i-1][j]
			}
			if s[i][j] == '#' {
				sumH[i][j]++
			}
		}
	}

	ans := make([][]int, h)
	for i := range ans {
		ans[i] = make([]int, w)
	}

	cnt := 1
	li := -1
	for i := range s {
		lj := -1
		for j := range s[i] {
			if s[i][j] == '#' {
				fi := i
				if sumH[i][j] == sumH[h-1][j] {
					fi = h - 1
				}
				fj := j
				if sumW[i][j] == sumW[i][w-1] {
					fj = w - 1
				}
				for ni := li + 1; ni <= fi; ni++ {
					for nj := lj + 1; nj <= fj; nj++ {
						ans[ni][nj] = cnt
					}
				}
				lj = j
				cnt++
			}
		}
		if sumW[i][w-1] > 0 {
			li = i
		}
	}

	var wr = bufio.NewWriter(os.Stdout)
	for _, row := range ans {
		for i, v := range row {
			wr.WriteString(strconv.Itoa(v))
			if i < w-1 {
				wr.WriteString(" ")
			} else {
				wr.WriteString("\n")
			}
		}
	}
	wr.Flush()
}
//  [go]
package main

import (
	"fmt"
)

func main() {
	var H, W, K int
	fmt.Scan(&H, &W, &K)

	a := make([]string, H)
	for i := 0; i < H; i++ {
		fmt.Scan(&a[i])
	}

	c := 0
	cake := make([][]int, H)
	for i := 0; i < H; i++ {
		cake[i] = make([]int, W)
		for j := 0; j < W; j++ {
			if a[i][j] == '#' {
				c++
				cake[i][j] = c
			} else {
				cake[i][j] = 0
			}
		}
	}

	for i := 0; i < H; i++ {
		for j := 1; j < W; j++ {
			if cake[i][j] == 0 {
				cake[i][j] = cake[i][j-1]
			}
		}

		for j := W - 2; j >= 0; j-- {
			if cake[i][j] == 0 {
				cake[i][j] = cake[i][j+1]
			}
		}
	}

	for i := 1; i < H; i++ {
		for j := 0; j < W; j++ {
			if cake[i][j] == 0 {
				cake[i][j] = cake[i-1][j]
			}
		}
	}

	for i := H - 2; i >= 0; i-- {
		for j := 0; j < W; j++ {
			if cake[i][j] == 0 {
				cake[i][j] = cake[i+1][j]
			}
		}
	}

	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			fmt.Print(cake[i][j])
			if j < W-1 {
				fmt.Print(" ")
			}
		}
		fmt.Println("")
	}
}
//  [ruby]
h, w, k = gets.split.map(&:to_i)

ans = Array.new(h){Array.new(w)}
now = 0
arr = []

h.times do |i|
    s = gets.chomp
    x = s.index("#")
    
    if x.nil?
        i == 0 || ans[i-1][0].nil? ? arr.unshift(i) : ans[i] = ans[i-1]
    else
        now += 1
        ans[i].fill(now, 0..x)
        (x+1).upto(w-1) do |j|
            now += 1 if s[j] == "#"
            ans[i][j] = now
        end
    end
end

arr.each {|i| ans[i] = ans[i+1]}
puts ans.map{|e| e.join(" ")}
//  [ruby]
h, w, k = gets.split.map(&:to_i)

ans = Array.new(h){Array.new(w)}
now = 0
l = -1

h.times do |i|
    s = gets.chomp
    x = s.index("#")
    
    if x.nil?
        l + 1 == i ? l = i : ans[i] = ans[i-1]
    else
        now += 1
        ans[i].fill(now, 0..x)
        (x+1).upto(w-1) do |j|
            now += 1 if s[j] == "#"
            ans[i][j] = now
        end
    end
end

l.downto(0) {|i| ans[i] = ans[i+1]}
puts ans.map{|e| e.join(" ")}
//  [ruby]
h,w,k=gets.split.map(&:to_i)
s=[]
l=1
h.times do
  s << gets.chomp.chars
  if s[-1].include?("#")
    f=false
    w.times do |j|
      if !f&&s[-1][j]=="."
        s[-1][j]=l
      elsif s[-1][j]=="#"
        s[-1][j]=l
        f=true if !f
        l+=1
      else
        s[-1][j]=s[-1][j-1]
      end
    end
  end
end
f=false
h.times do |i|
  if !f&&s[i][0]!="."
    i.times do |ii|
      s[ii]=s[i]
    end
    k=i
    f=true
  elsif s[i][0]!="."
    k=i
  else
    s[i]=s[k]
  end
end
h.times do |i|
  puts s[i].join(" ")
end
//  [ruby]
h, w, k = gets.chomp.split.map(&:to_i)
s = []
h.times do
  s.push gets.chomp.split(//)
end

def ume(h, w, starty, startx, s, num)
  ue = 0 # max
  shita = h - 1 # max
  migi = w - 1 # max
  hidari = 0 # max

  # 1 line hidari
  (startx-1).downto(0) do |x|
    if s[starty][x] != '.'
      hidari = x + 1
      break
    end
  end
  # 1 line migi
  (startx+1).upto(w-1) do |x|
    if s[starty][x] != '.'
      migi = x - 1
      break
    end
  end
  # ue
  (starty-1).downto(0) do |y|
    unless (hidari..migi).to_a.all?{|x| s[y][x] == '.'}
      ue = y + 1
      break
    end
  end
  # shita
  (starty+1).upto(h-1) do |y|
    unless (hidari..migi).to_a.all?{|x| s[y][x] == '.'}
      shita = y - 1
      break
    end
  end

  # fill
  (ue..shita).each do |i|
    (hidari..migi).each do |j|
      s[i][j] = num.to_s
    end
  end
  # p [num, ' ', ue, shita, hidari, migi, ' ', starty, startx]
end

num = 1
h.times do |i|
  w.times do |j|
    if s[i][j] == '#'
      ume(h, w, i, j, s, num)
      num += 1
    end
  end
end

h.times do |i|
  puts s[i].join(' ')
end
//  [ruby]
H, W, K = gets.split.map(&:to_i)

cake = H.times.map { gets.chomp.chars }
AREA = Array.new(H) { Array.new(W, -1) }

cnt = 0

H.times do |y|
  W.times do |x|
    c = cake[y][x]

    next if c != '#'
    cnt += 1

    AREA[y][x] = cnt
  end
end

require 'pp'
# pp AREA

def check_right
  H.times do |y|
    id = -1

    W.times do |x|
      if AREA[y][x] != -1
        id = AREA[y][x]
      end

      AREA[y][x] = id
    end
  end
end

def check_left
  (H - 1).downto(0) do |y|
    id = -1

    (W - 1).downto(0) do |x|
      if AREA[y][x] != -1
        id = AREA[y][x]
      end

      AREA[y][x] = id
    end
  end
end

def check_down
  H.times do |y|
    visited = Hash.new(false)

    W.times do |x|
      id = AREA[y][x]

      next if id == -1
      next if visited[id]

      visited[id] = true
      from = to = x

      (x + 1).upto(W - 1) do |nx|
        break if id != AREA[y][nx]

        to = nx
      end

      (y + 1).upto(H - 1) do |ny|
        break unless all_empty?(ny, from, to)

        update_area(ny, from, to, id)
      end
    end
  end
end

def check_up
  (H - 1).downto(0) do |y|
    visited = Hash.new(false)

    0.upto(W - 1) do |x|
      id = AREA[y][x]

      next if id == -1
      next if visited[id]

      visited[id] = true
      from = to = x

      (x + 1).upto(W - 1) do |nx|
        break if id != AREA[y][nx]

        to = nx
      end

      (y - 1).downto(0) do |ny|
        break unless all_empty?(ny, from, to)

        update_area(ny, from, to, id)
      end
    end
  end
end

def all_empty?(y, from, to)
  AREA[y][from..to].all? { |x| x == -1 }
end

def update_area(y, from, to, id)
  from.upto(to) do |x|
    raise if AREA[y][x] != -1
    AREA[y][x] = id
  end
end

require 'pp'

check_right
check_left
check_down
check_up

puts AREA.map { |row| row.join(' ') }
//  [ruby]
h, w, k = gets.split.map(&:to_i)
s = h.times.map { gets.chomp }

id = {} # [i,j]をkeyとするイチゴの番号
cnt = 1
non_empty_row = Array.new(h, false)
s.each_with_index do |row, i|
  w.times do |j|
    if s[i][j] == "#"
      non_empty_row[i] = true
      id["#{i}, #{j}"] = cnt
      cnt += 1
    end
  end
end

cake = Array.new(h) { Array.new(w, "?") }

# まずは横方向
h.times do |i|
  row = s[i]
  prev = "?"
  w.times do |j|
    if row[j] == "#"
      cake[i][j] = id["#{i}, #{j}"]
      prev = id["#{i}, #{j}"]
    else
      cake[i][j] = prev
    end
  end
  # 右端が?だったらその行にはイチゴがないのでとりあえずぱす
  next if cake[i][-1] == "?"
  next if cake[i][0] != "?"

  first_ichigo_id = -1
  cake[i].each_with_index do |c, j|
    if c != "?"
      first_ichigo_id = j
      break
    end
  end
  # pp first_ichigo_id
  w.times do |j|
    if cake[i][j] == "?"
      cake[i][j] = cake[i][first_ichigo_id]
    end
  end
end



empty_i = non_empty_row.map.with_index{|_, i| i}.select{|i| non_empty_row[i] == false}
nonempty_i = non_empty_row.map.with_index{|_, i| i}.select{|i| non_empty_row[i] == true}
# p empty_i
# p nonempty_i
# pp cake
# 上にある?行に対して上のをコピーする
empty_i.each do |i|
  # iより大きいjをnonempty_iからさがす
  nonempty_i.each do |j|
    if j > i
      cake[i] = cake[j]
      break
    end
  end
end

h.times do |i|
  if cake[i].include?("?")
    cake[i] = cake[nonempty_i[-1]]
  end
end


puts cake.map{|tmp| tmp.join(" ")}
//  [rust]
use std::io::{BufRead, BufWriter, Write};

fn main() {
    let stdin = std::io::stdin();
    let stdout = std::io::stdout();
    solve(&mut stdin.lock(), &mut BufWriter::new(stdout.lock()));
}

fn solve<R: BufRead, W: Write>(stdin: &mut R, stdout: &mut BufWriter<W>) {
    let (h, w, _k): (usize, usize, usize) = stdin.gets().split(' ').values();
    let map = stdin.lines().take(h).map(|x| x.unwrap().into_bytes()).collect::<Vec<_>>();
    let mut head = 0;
    for i in 0..h {
        if map[i].contains(&b'#') {
            head = i;
            break;
        }
    }
    let mut ans = vec![vec![0; w]; h];
    let mut count = 1;
    for i in head..h {
        if !map[i].contains(&b'#') {
            for j in 0..w {
                ans[i][j] = ans[i - 1][j];
            }
            continue;
        }
        let mut first = true;
        for j in 0..w {
            if map[i][j] == b'#' {
                if first {
                    first = false;
                } else {
                    count += 1;
                }
            }
            ans[i][j] = count;
        }
        count += 1;
    }
    for i in 0..h {
        let ii = std::cmp::max(i, head);
        for j in 0..w {
            write!(stdout, "{} ", ans[ii][j]).unwrap();
        }
        writeln!(stdout, "").unwrap();
    }
}

trait Gets { fn gets(&mut self) -> String; }
impl<T: std::io::BufRead> Gets for T {
    fn gets(&mut self) -> String { self.lines().next().unwrap().unwrap() } }

trait Values<T> { fn values(&mut self) -> T; }
impl<'a, I, T1, T2, T3> Values<(T1, T2, T3)> for I
    where I: Iterator<Item=&'a str>,
          T1: std::str::FromStr, T1::Err: std::fmt::Debug,
          T2: std::str::FromStr, T2::Err: std::fmt::Debug,
          T3: std::str::FromStr, T3::Err: std::fmt::Debug {
    fn values(&mut self) -> (T1, T2, T3) {
        (self.next().unwrap().parse().unwrap(),
         self.next().unwrap().parse().unwrap(),
         self.next().unwrap().parse().unwrap())
    }
}
//  [rust]
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, [ $t:tt ]) => {{
    let len = read_value!($iter, usize);
    (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  }};

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    h: usize,
    w: usize,
    _k: usize,
    s: [chars; h],
  }
  let mut id = 1;
  let mut field = vec![vec![0; w]; h];
  for i in 0 .. h {
    let sharps: Vec<_> = s[i].iter().enumerate().filter(|&(_, &c)| c == '#').map(|(i, _)| i).collect();
    if sharps.is_empty() {
      continue;
    }
    let mut j = 0;
    for &s in &sharps {
      while j <= s {
        field[i][j] = id;
        j += 1;
      }
      id += 1;
    }
    while j < w {
      field[i][j] = id - 1;
      j += 1;
    }
  }
  let mut row = field.iter().filter(|&r| r[0] != 0).next().unwrap().clone();
  for i in 0 .. h {
    if field[i][0] == 0 {
      field[i] = row.clone();
    } else {
      row = field[i].clone();
    }
  }
  for row in &field {
    for &x in row {
      puts!("{} ", x);
    }
    puts!("\n");
  }
}
//  [rust]
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn print_table(t: &Vec<(usize, usize, usize, usize)>, h: usize, w: usize){
    let mut table = vec![vec![0;w];h];
    for k in 0..t.len(){
        let r = &t[k];
        for i in r.0..r.2{
            for j in r.1..r.3{
                table[i][j] = k+1;
            }
        }
    }

    for i in 0..h{
        for j in 0..w{
            print!("{} ", table[i][j]);
        }
        println!("");
    }
}

fn main(){
    let line = read_as_vec::<usize>();
    let (h, w, k) = (line[0], line[1], line[2]);

    let mut straws = vec![];
    for i in 0..h{
        let line = read_as_string().chars().collect::<Vec<char>>();
        for j in 0..line.len(){
            if line[j] == '#'{
                straws.push((i, j));
            }
        }
    }

    straws.sort();

    let mut cur_top = 0;
    let bottom_i: usize = {
        let mut tmp = straws.clone();
        tmp.sort_by_key(|x| x.0);
        tmp.last().unwrap().0
    };
    let mut ranges: Vec<(usize, usize, usize, usize)> = vec![];
    for i in 0..h{
        let mut cur_left = 0;
        let filted_straws = straws.iter().filter(|x| x.0 == i).collect::<Vec<&(usize, usize)>>();
        if filted_straws.len() == 0{
            continue;
        }
        //println!("{:?}", filted_straws);
        for &straw in &filted_straws{

            if i == bottom_i{
                ranges.push((cur_top, cur_left, h, straw.1+1));
            }else{
                ranges.push((cur_top, cur_left, straw.0+1, straw.1+1));
            }
            cur_left = straw.1+1;
        }
        let last_i = ranges.len()-1;
        ranges[last_i].3 = w;
        cur_top = ranges[last_i].2;

    }
    //println!("calculated is over");
    print_table(&ranges, h, w);
}