#include<bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define ll long long
#define maxheap priority_queue<int>
#define minheap priority_queue<int,vector<int>,greater<int>>
#define all(v) (v).begin(),(v).end()
const  double pi = acos(-1.0);
const  double eps = 1e-12;
using namespace std;

const int N = 1e8 + 10;
int a[N][2];
unordered_map <int, ll> t[4];
ll sum(int i, int id) {
  ll res = 0;
  for (; i >= 0; i -= (i + 1) & -(i + 1))
    if (t[id].count(i)) res += t[id][i];
  return res;
}
void inc(int i, int value, int id) {
    for (; i < N; i += (i + 1) & -(i + 1))
        t[id][i] += value;
}

ll sum (int l, int r, int id){
	ll res =  0;
    if (r > 0) res = sum (r, id);
    if (l - 1 >= 0) res -= sum (l - 1, id);
    return res;
}
int n, m, q;

void solve(){ 
  
    cin >> n >> m >> q;
    inc(0, n, 0);
    inc(0, m, 1);
    ll ans = 0;
    
    while (q--){
        int type, x, y;
        cin >> type >> x >> y;
        type--;
        inc(a[x][type], -1, type);
        inc(y, 1, type);
        inc(a[x][type], -a[x][type], type + 2);
        inc(y, y, type + 2);
        
        ll prefSumx = sum(0, a[x][type], type ^ 1);
        ll prefSumy = sum(0, y, type ^ 1);
        ll delta = sum(a[x][type] + 1, y, (type + 2) ^ 1);
        ans -= prefSumx * a[x][type];
        ans += prefSumy * y;
        ans -= delta;
        a[x][type] = y;
        //cout << ans << " " << prefSumx << " " << prefSumy << " " << delta << endl;
        cout << ans << "\n";
    }
    //cout << ans << endl;
    
    
} 


int main(){
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(6);
    //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout);
    //freopen("exercise.in","r",stdin); freopen("exercise.out", "w", stdout);
    int step;
    step = 1;
    //cin >> step;
    for (int i = 1; i <= step; i++){
        solve(); 
    }
}
#pragma GCC optimize("O3")
#pragma GCC target("avx512f")
#include <algorithm>
#include <iostream>
#include <bitset>
#include <vector>
#include <array>
using namespace std;
#define f(x,y,z) for(int x=y;x<=z;++x)
vector<int> v[200001];
int n, a, b, it;
array<int, 200001> jr, dlm, nmr;
bitset<200001> sdh;
void jrk(int x) {
    for(int &i:v[x]) if(!jr[i]) {
        jr[i] = jr[x]+1, jrk(i);
    }
}
void trn(int x) {
    sdh[x] = true;
    for(int &i:v[x]) if(!sdh[i]) {
        trn(i), dlm[x] = max(dlm[x], dlm[i]+1);
    }
}
void isi(int x) {
    sdh[x] = true, nmr[x] = a;
    vector<pair<int, int>> mn;
    for(int &i:v[x]) if(!sdh[i]) mn.push_back({dlm[i], i});
    sort(mn.begin(), mn.end());
    for(auto &i:mn) ++a, isi(i.second), ++a;
}
int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    cin >> n;
    f(i,2,n) {
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    jr[1] = a = 1, jrk(1);
    it = max_element(jr.begin()+1, jr.begin()+n+1)-jr.begin();
    trn(it), sdh.reset(), isi(it);
    f(i,1,n) cout << nmr[i] << ' ';
}