#include <bits/stdc++.h>
using namespace std;
#define int long long
const int nax=1e5+100;
struct node
{
    int n,ok;
    vector<int> par;
    node(int n):n(n),par(n,-1),ok(n){}
    bool merge(int x,int y)
    {
        x=find(x);
        y=find(y);
        if(x==y)
        return 0;
        if(par[x]>par[y])
        swap(x,y);
        par[x]+=par[y];
        par[y]=x;
        --ok;
        return 1;
    }
    int find(int v)
    {
        if(par[v]<0)
        return v;
        return par[v]=find(par[v]);
    }
    int get(int x)
    {
        return -par[find(x)];
    }
    bool same(int x,int y)
    {
        return find(x)==find(y);
    }
    vector<int> check() const{
        vector<int> res;
        res.reserve(ok);
        for(int i=0;i<par.size();i++)
        if(par[i]<0)
        res.push_back(i);
        return res;
    }
};
int32_t main()
{
    int h,w;
    cin>>h>>w;
    vector<string> s(h);
    for(int i=0;i<h;i++)
    cin>>s[i];
    node root(h+w);
    root.merge(0,h);
    root.merge(0,h+w-1);
    root.merge(h-1,w);
    root.merge(h-1,h+w-1);
    for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
    if(s[i][j]=='#')
    {
        int row=i,col=h+j;
        root.merge(row,col);
    }
    int res=0;
    for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
    {
        if(s[i][j]=='#')
        {
            if(!root.same(i,0))
            {
                root.merge(i,0);
                ++res;
            }
        }
    }
    int e=0,o=0;
    {
        for(int i=1;i<=h-2;i++)
        {
            bool f=1;
            for(int j=0;j<w;j++)
            if(s[i][j]=='#')
            {
                f=0;
                break;
            }
            if(f)
            ++e;
        }
        for(int j=1;j<=w-2;j++)
        {
            bool f=1;
            for(int i=0;i<h;i++)
            if(s[i][j]=='#')
            {
                f=0;
                break;
            }
            if(f)
            o++;
        }
    }
    res+=min(e,o);
    cout<<res;
    return 0;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<LL,LL> pii;
typedef pair<LL,pii> ppi;
typedef pair<pii,pii> ppp;
#define FOR(i, n) for(int i = 1; i<=n; i++)
#define F0R(i, n) for(int i = 0; i<n; i++)
#define mp make_pair
#define pb push_back
#define f first
#define s second

template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {cout << "["; F0R(i, v.size()) {if (i) cout << ", "; cout << v[i];} return cout << "]";}

struct fenwick{
	LL sz;
	vector<array<LL, 2>> tr;

	fenwick(LL ss){
		sz = ss;
		tr.assign(sz, {0, 0});
	}

	void upd(LL g, array<LL, 2> k){
		for(; g<sz; g+=g&-g){
			tr[g][0] += k[0];
			tr[g][1] += k[1];
		}
	}

	array<LL, 2> ge(LL g){
		array<LL, 2> res = {0, 0};
		for(; g>0; g-=g&-g){
			res[0] += tr[g][0];
			res[1] += tr[g][1];
		}

		return res;
	}
};

//var 
const LL MX = 400000;
LL T, n, m, q, ans = 0, a[200005], b[200005];
fenwick tra(400005), trb(400005);
array<LL, 3> queries[200005];
vector<LL> vals;
map<LL, LL> indexx;

void solve(){
	cin >> n >> m >> q;

	FOR(i, q){
		F0R(j, 3){
			cin >> queries[i][j];
		}
		vals.pb(queries[i][2]);
	}

	vals.pb(0);

	sort(vals.begin(), vals.end());
	vector<LL> equal = vals;
	vals.clear(); LL pr = -1;
	for(auto u : equal){
		if(u != pr) vals.pb(u);
		pr = u;
	}

	F0R(i, (int)vals.size())
		indexx[vals[i]] = i+1;

	tra.upd(indexx[0], {0, n});
	trb.upd(indexx[0], {0, m});

	FOR(i, n) a[i] = indexx[0];
	FOR(i, m) b[i] = indexx[0];

	//cout << vals << '\n';

	FOR(z, q){
		LL t1, i, x;
		t1 = queries[z][0], i = queries[z][1], x = queries[z][2];

		x = indexx[x];

		if(t1 == 1){
			tra.upd(a[i], {-vals[a[i] - 1], -1});
			ans -= trb.ge(a[i])[1] * vals[a[i] - 1] + (trb.ge(MX)[0] - trb.ge(a[i])[0]);

			a[i] = x;

			tra.upd(a[i], {vals[a[i] - 1], 1});
			ans += trb.ge(a[i])[1] * vals[a[i] - 1] + (trb.ge(MX)[0] - trb.ge(a[i])[0]);
		}
		else{
			trb.upd(b[i], {-vals[b[i] - 1], -1});
			ans -= tra.ge(b[i])[1] * vals[b[i] - 1] + (tra.ge(MX)[0] - tra.ge(b[i])[0]);

			b[i] = x;

			trb.upd(b[i], {vals[b[i] - 1], 1});
			ans += tra.ge(b[i])[1] * vals[b[i] - 1] + (tra.ge(MX)[0] - tra.ge(b[i])[0]);
		}

		cout << ans << "\n";
	}
}

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

	T = 1;
	//cin >> T;
	FOR(t, T)
		solve();

	cout.flush();
	return 0;
}