#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;
class unionfind{
    int n;
    vector<int>par;
    vector<int>rank;
public:
    unionfind(int n_){
        n=n_;
        par.resize(n,-1);
        rank.resize(n,0);
    }
    int find(int x){
        if(par[x]<0)
            return x;
        return par[x]=find(par[x]);
    }
    void marge(int a,int b){
        a=find(a);
        b=find(b);
        if(a==b)
            return;
        if(rank[a]<rank[b])
            swap(a,b);
        par[b]=a;
        if(rank[a]==rank[b])
            rank[a]++;
    }
    bool same(int a,int b){
        return find(a)==find(b);
    }
    int size(int x){
        return -(par[find(x)]);
    }
};
vector<pair<int,int>>G[100000];
int ans[100000],n;
void dfs(int v,int par,int col){
    if(ans[par]==col)
        ans[v]=col%n+1;
    else
        ans[v]=col;
    for(int i=0;i<G[v].size();i++)
        if(G[v][i].first!=par)
            dfs(G[v][i].first,v,G[v][i].second);
}
signed main(){
    int m,u,v,c;
    cin>>n>>m;
    unionfind uf(n);
    while(cin>>u>>v>>c){
        u--,v--;
        if(uf.same(u,v))
            continue;
        uf.marge(u,v);
        G[u].emplace_back(v,c);
        G[v].emplace_back(u,c);
    }
    ans[0]=1;
    for(int i=0;i<G[0].size();i++)
        dfs(G[0][i].first,0,G[0][i].second);
    for(int i=0;i<n;i++)
        cout<<ans[i]<<endl;
}

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;

inline void MAX(int &a,const int &b) {if(b>a) a=b;}
inline void MIN(int &a,const int &b) {if(b<a) a=b;}
inline int max(const int &a,const int &b) {return a>b?a:b;}
inline int min(const int &a,const int &b) {return a<b?a:b;}

const int N=2e5+5;

int mx,n,m,a[N],b[N];
int tmp[N],len;

struct BIT {
	int c[N];
	long long d[N];
	inline void addc(int pos,int key) {for(int i=pos ; i<=mx ; i+=i&-i) c[i]+=key;}
	inline void addd(int pos,long long key) {for(int i=pos ; i<=mx ; i+=i&-i) d[i]+=key;}
	inline int sumc(int pos) {int res=0;for(int i=pos ; i ; i-=i&-i) res+=c[i];return res;}
	inline long long sumd(int pos) {long long res=0;for(int i=pos ; i ; i-=i&-i) res+=d[i];return res;}
	inline long long query(int key) {
		return sumd(mx)-sumd(key)+1LL*sumc(key)*tmp[key];
	}
}TA,TB;

struct ask {
	int t,x;
	long long y;
	inline ask (int T=0,int X=0,int Y=0) : t(T),x(X),y(Y) {}
}w[N];

int q;

int main() {
	tmp[++len]=0;
	scanf("%d%d",&n,&m);
	scanf("%d",&q);
	for(int i=1 ; i<=q ; ++i) scanf("%d%d%d",&w[i].t,&w[i].x,&w[i].y),tmp[++len]=w[i].y;
	sort(tmp+1,tmp+len+1);
	mx=unique(tmp+1,tmp+len+1)-tmp-1;
	TA.addc(1,n),TB.addc(1,m);
	long long ans=0;
	for(int i=1 ; i<=q ; ++i) {
		int t=w[i].t,x=w[i].x,y=w[i].y,p=lower_bound(tmp+1,tmp+mx+1,y)-tmp;
		if(t==1) {
			int po=lower_bound(tmp+1,tmp+mx+1,a[x])-tmp;
			ans-=TB.query(po),TA.addc(po,-1),TA.addd(po,-a[x]);
			ans+=TB.query(p),TA.addc(p,1),TA.addd(p,y);
			a[x]=y;
		}
		else {
			int po=lower_bound(tmp+1,tmp+mx+1,b[x])-tmp;
			ans-=TA.query(po),TB.addc(po,-1),TB.addd(po,-b[x]);
			ans+=TA.query(p),TB.addc(p,1),TB.addd(p,y);
			b[x]=y;
		}
		printf("%lld\n",ans);
	}
	return 0;
}