#include <bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a; i >-1; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a; i > b; --i)
#define repl(i, a) for (ll i = (ll)0; i < (ll)a; ++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
#define fi first
#define se second
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll mod_998244353 = 998244353;
constexpr ll INF = 1LL << 60;

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

//using lll=boost::multiprecision::cpp_int;
//using Double=boost::multiprecision::number<boost::multiprecision::cpp_dec_float<128>>;//仮数部が1024桁
template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

ll mypow(ll x, ll n, const ll &p = -1)
{ //x^nをmodで割った余り

	if (p != -1)
	{
		x =(x%p+p)%p;
	}
	ll ret = 1;
	while (n > 0)
	{
		if (n & 1)
		{
			if (p != -1)
				ret = (ret * x) % p;
			else
				ret *= x;
		}
		if (p != -1)
			x = (x * x) % p;
		else
			x *= x;
		n >>= 1;
	}
	return ret;
}

using namespace std;
//using namespace atcoder;

template<typename T>
struct BIT{
  //0オリジンで与える
  vector<T>bit;
  int N;

  BIT(int n):N(n){
    bit.assign(++n,0);
  }

  T sum(int i){
    T s=0;
    ++i;//0オリジンに対応させる
    while(i>0){
      s+=bit[i];
      i-=i&-i;//iから最後の1のビットを減算
    }
    return s;
  }

  void add(int i,T x){
    ++i;//0オリジンに対応させる
    while(i<(int)bit.size()){
      bit[i]+=x;
      i+=i&-i;
    }
  }

  T Lower_bound(T k){
    if(k<=0)
      return 0;
    T x = 0;
    T mul = 1;
    while (mul<N){
      mul *= 2;
    }
    for (T i = mul; i > 0;i/=2){
      if(x+i<=N&&bit[x+i]<k){
        k -= bit[x + i];
        x += i;
      }
    }
    return x;
  }
};


using P=pair<ll,int>;
void solve()
{	
	int n,m,q;
	cin>>n>>m>>q;
	vector<int>t(q),x(q);
	vector<ll>y(q);
	rep(i,q)cin>>t[i]>>x[i]>>y[i],x[i]--;
	vector<ll>prea(n),preb(m);
	vector<int>id(q);
	rep(i,q)id[i]=y[i];
	id.eb(0);
	sort(all(id));

	BIT<ll>a(q+1),b(q+1);
	BIT<int>aid(q+1),bid(q+1);
	aid.add(0,n);
	bid.add(0,m);

	ll ans=0;
	rep(i,q){
		if(t[i]==1){
			int pos=lower_bound(all(id),prea[x[i]])-id.begin();
			ll val=bid.sum(pos)*prea[x[i]];
			val+=b.sum(q+1)-b.sum(pos);
			ans-=val;
			aid.add(pos,-1);
			a.add(pos,-prea[x[i]]);
			
			prea[x[i]]=y[i];
			pos=lower_bound(all(id),prea[x[i]])-id.begin();
			val=bid.sum(pos)*prea[x[i]];
			val+=b.sum(q+1)-b.sum(pos);
			ans+=val;
			aid.add(pos,1);
			a.add(pos,prea[x[i]]);
		}else{
			int pos=lower_bound(all(id),preb[x[i]])-id.begin();
			ll val=aid.sum(pos)*preb[x[i]];
			val+=a.sum(q+1)-a.sum(pos);
			ans-=val;
			bid.add(pos,-1);
			b.add(pos,-preb[x[i]]);
			
			preb[x[i]]=y[i];
			pos=lower_bound(all(id),preb[x[i]])-id.begin();
			val=aid.sum(pos)*preb[x[i]];
			val+=a.sum(q+1)-a.sum(pos);
			ans+=val;
			bid.add(pos,1);
			b.add(pos,preb[x[i]]);
		}
		cout<<ans<<"\n";
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define fo(i, x, y) for (int i = (x); i <= (y); ++i)
#define fd(i, x, y) for (int i = (x); i >= (y); --i)

const int maxn = 2e5 + 5, inf = 1e9;

struct edge{int to; edge *nxt;} *arc[maxn], pool[maxn << 1], *pt = pool;
int n, k, len, cnt;
int mi[maxn], mx[maxn];

int getint()
{
	char ch;
	int res = 0, p;
	while (!isdigit(ch = getchar()) && (ch ^ '-'));
	p = ch == '-'? ch = getchar(), -1 : 1;
	while (isdigit(ch))
		res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
	return res * p;
}

void dfs(int x, int fa)
{
	mi[x] = inf; mx[x] = 0;
	for (edge *e = arc[x]; e; e = e->nxt)
		if (e->to != fa)
		{
			dfs(e->to, x);
			mi[x] = min(mi[x], mi[e->to] + 1);
			mx[x] = max(mx[x], mx[e->to] + 1);
		}
	if (mi[x] + mx[x] <= len)
		mx[x] = -inf;
	else if (mi[x] + mx[x] > len && mx[x] == len)
		mi[x] = 0, mx[x] = -inf, cnt++;
}

bool check(int x)
{
	len = x; cnt = 0;
	dfs(1, 0);
	cnt += (mi[1] + mx[1] > len);
	return cnt <= k;
}

void addedge(int u, int v)
{
	*pt = (edge){v, arc[u]};
	arc[u] = pt++;
}

int main()
{
	n = getint(); k = getint();
	fo(i, 1, n - 1)
	{
		int u, v;
		u = getint(); v = getint();
		addedge(u, v);
		addedge(v, u);
	}
	int l = 0, r = n + 1;
	while (l + 1 < r)
	{
		int mid = l + r >> 1;
		if (check(mid)) r = mid;
		else l = mid;
	}
	printf("%d\n", r);
	return 0;
}