#pragma comment(linker, "/stack:200000000")
        #pragma GCC optimize ("Ofast")
        #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
        #include <iostream>
        #include <iomanip>
        #include <sstream>
        #include <cstring>
        #include <vector>
        #include <deque>
        #include <queue>
        #include <set>
        #include <map>
        #include <valarray>
        #include <iterator>
        #include <functional>
        #include <limits>
        #include <algorithm>
        #include <numeric>
        #include <cmath>
        #include <cassert>
        #include <unordered_map>
        #include <unordered_set>
        #include <stack>
        using namespace std;
        #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
         #define trace(x) cerr << #x << ": " << x << " " << endl;
     
        typedef int64_t ll;
     
        #define endl '\n'
        #define int ll
        ll mod=1e9+7;
        ll mod1=1e9+5;
        ll power(ll a,ll b)
        {
            if(b==0) return 1;
            else if(b%2==0)
                return power((((a%mod)*(a%mod))%mod),b/2)%mod;
            else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
        }
        int a[301][301];
        int c=0;
        int n,m;
        int init[501][501];

     int32_t main()
        {
        IOS
       
            int f=0;
            cin>>n>>m>>f;
            int st[n+1];
            for(int i=1;i<=n;++i)
            {
                int p=0;
                for(int j=1;j<=m;++j)
                {
                    char ch;
                    cin>>ch;
                    if(ch=='#')
                    {
                        init[i][j]=1;
                        p++;
                    }
                    else
                    {
                        init[i][j]=0;
                    }
                }
                if(p)
                    st[i]=1;
                else
                    st[i]=0;

            }
            int co=0;
            for(int i=1;i<=n;++i)
            {
                for(int j=1;j<=m;++j)
                {
                    if(init[i][j])
                    {
                        co++;
                        int in;
                        a[i][j]=co;
                        in=j;
                        for(int k=j+1;k<=m;++k)
                        {
                            if(init[i][k])
                            {
                                break;
                            }
                            else
                            {
                                in=k;
                                a[i][k]=co;
                            }
                        }
                        int in1=j;
                        for(int k=j-1;k>=1;--k)
                        {
                            if(a[i][k])
                            {
                                break;
                            }
                            else
                            {
                                in1=k;
                                a[i][k]=co;
                            }
                        }
                        for(int k=i+1;k<=n;++k)
                        {
                            if(st[k]==0)
                            {
                                for(int l=in1;l<=in;++l)
                                    a[k][l]=co;
                            }
                            else
                            {
                                break;
                            }
                        }
                        for(int k=i-1;k>=1;--k)
                        {
                            if(st[k]==0)
                            {
                                if(a[k][in1])
                                    break;
                                for(int l=in1;l<=in;++l)
                                    a[k][l]=co;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
            }
            for(int i=1;i<=n;++i)
            {
                for(int j=1;j<=m;++j)
                    cout<<a[i][j]<<" ";
                cout<<endl;
            }

        }

Measured memory_bytes: 2688