#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(30) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int dx[8] = {1, 0, -1, 0, 0,0,0,0};
int dy[8] = {0, 0, 0,  0, 0 ,0,0,0};
int main(){
  lli A,B,C,D,E,F,N,M,K,L,R,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> H >> W >> K;
  DV(G,char,H,W,'.');
  DV(dist,lli,H,W,-1);
  queue<pint> que;
  flag=1;
  rep(i,0,H)rep(j,0,W){
    cin >> G[i][j];
    if(G[i][j]=='#'){
    dist[i][j]=flag;
    flag++;
    que.push(pint(i,j));
    }
  }
  while(!que.empty()){
    auto Xq=que.front();que.pop();
    rep(i,0,8){
         auto nx=Xq.first+dx[i];
         auto ny=Xq.second+dy[i];
         if(nx<0||nx>=H||ny<0||ny>=W)continue;
         if(dist[nx][ny]==-1){
            dist[nx][ny]=dist[Xq.first][Xq.second];
            que.push(pint(nx,ny));
         }
    }
  }
  rep(i,0,H)rep(j,1,W)if(dist[i][j-1]==-1)dist[i][j-1]=dist[i][j];
  rep(i,0,H)rep(j,0,W-1)if(dist[i][j+1]==-1)dist[i][j+1]=dist[i][j];
  rep(i,0,H)rep(j,1,W)if(dist[i][j-1]==-1)dist[i][j-1]=dist[i][j];
  rep(i,0,H)rep(j,0,W-1)if(dist[i][j+1]==-1)dist[i][j+1]=dist[i][j];
  rep(i,0,H)rep(j,1,W)if(dist[i][j-1]==-1)dist[i][j-1]=dist[i][j];
  rep(i,0,H)rep(j,0,W-1)if(dist[i][j+1]==-1)dist[i][j+1]=dist[i][j];
  rep(i,0,H)rep(j,1,W)if(dist[i][j-1]==-1)dist[i][j-1]=dist[i][j];
  rep(i,0,H)rep(j,0,W-1)if(dist[i][j+1]==-1)dist[i][j+1]=dist[i][j];
  rep(i,0,H)rep(j,1,W)if(dist[i][j-1]==-1)dist[i][j-1]=dist[i][j];
  rep(i,0,H)rep(j,0,W-1)if(dist[i][j+1]==-1)dist[i][j+1]=dist[i][j];
  rep(i,0,H)rep(j,1,W)if(dist[i][j-1]==-1)dist[i][j-1]=dist[i][j];
  rep(i,0,H)rep(j,0,W-1)if(dist[i][j+1]==-1)dist[i][j+1]=dist[i][j];
  rep(i,0,H)rep(j,1,W)if(dist[i][j-1]==-1)dist[i][j-1]=dist[i][j];
  rep(i,0,H)rep(j,0,W-1)if(dist[i][j+1]==-1)dist[i][j+1]=dist[i][j];
  rep(i,0,H)rep(j,1,W)if(dist[i][j-1]==-1)dist[i][j-1]=dist[i][j];
  rep(i,0,H)rep(j,0,W-1)if(dist[i][j+1]==-1)dist[i][j+1]=dist[i][j];
  rep(i,0,H)rep(j,1,W)if(dist[i][j-1]==-1)dist[i][j-1]=dist[i][j];
  rep(i,0,H)rep(j,0,W-1)if(dist[i][j+1]==-1)dist[i][j+1]=dist[i][j];
  rep(i,0,H)rep(j,1,W)if(dist[i][j-1]==-1)dist[i][j-1]=dist[i][j];
  rep(i,0,H)rep(j,0,W-1)if(dist[i][j+1]==-1)dist[i][j+1]=dist[i][j];
  rep(i,0,H)rep(j,1,W)if(dist[i][j-1]==-1)dist[i][j-1]=dist[i][j];
  rep(i,0,H)rep(j,0,W-1)if(dist[i][j+1]==-1)dist[i][j+1]=dist[i][j];
  rep(i,0,H)rep(j,1,W)if(dist[i][j-1]==-1)dist[i][j-1]=dist[i][j];
  rep(i,0,H)rep(j,0,W-1)if(dist[i][j+1]==-1)dist[i][j+1]=dist[i][j];
  rep(i,0,H)rep(j,1,W)if(dist[i][j-1]==-1)dist[i][j-1]=dist[i][j];
  rep(i,0,H)rep(j,0,W-1)if(dist[i][j+1]==-1)dist[i][j+1]=dist[i][j];
  rep(i,0,H)rep(j,1,W)if(dist[i][j-1]==-1)dist[i][j-1]=dist[i][j];
  rep(i,0,H)rep(j,0,W-1)if(dist[i][j+1]==-1)dist[i][j+1]=dist[i][j];
  rep(i,0,H)rep(j,1,W)if(dist[i][j-1]==-1)dist[i][j-1]=dist[i][j];
  rep(i,0,H)rep(j,0,W-1)if(dist[i][j+1]==-1)dist[i][j+1]=dist[i][j];
  rep(i,0,H)rep(j,1,W)if(dist[i][j-1]==-1)dist[i][j-1]=dist[i][j];
  rep(i,0,H)rep(j,0,W-1)if(dist[i][j+1]==-1)dist[i][j+1]=dist[i][j];
  rep(i,0,H)rep(j,1,W)if(dist[i][j-1]==-1)dist[i][j-1]=dist[i][j];
  rep(i,0,H)rep(j,0,W-1)if(dist[i][j+1]==-1)dist[i][j+1]=dist[i][j];
  rep(i,0,H)rep(j,0,W){
    cout << " " << dist[i][j];
    if(j==W-1)Out("");
  }
}

Measured memory_bytes: 3072