#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const ll maxn = 3e5 + 5;
struct T {
ll a, b;
};
ll t, n, q;
vector<vector<ll>> g(maxn, vector<ll>(0)), dp;
vector<T> e(maxn);
vector<bool> used(maxn);
void dfs(ll v, ll p = -1) {
for (auto i : g[v]) {
if (used[i]) continue;
ll to;
if (e[i].a == v) {
to = e[i].b;
} else {
to = e[i].a;
}
if (to == p) continue;
dfs(to, v);
dp[v][0] += max(dp[to][0], dp[to][1]);
}
for (auto i : g[v]) {
if (used[i]) continue;
ll to;
if (e[i].a == v) {
to = e[i].b;
} else {
to = e[i].a;
}
if (to == p) continue;
dp[v][1] = max(dp[v][1], dp[to][0] + 1 + dp[v][0] - max(dp[to][0], dp[to][1]));
}
}
void sol() {
cin >> t >> n;
for (int i = 1; i <= n - 1; i++) {
ll a, b; cin >> a >> b;
e[i] = {a, b};
g[a].push_back(i);
g[b].push_back(i);
}
cin >> q;
while (q--) {
ll type; cin >> type;
if (type == 1) {
ll id; cin >> id;
used[id] = !used[id];
} else {
ll x; cin >> x;
dp.assign(maxn, vector<ll>(2, 0));
dfs(x);
cout << max(dp[x][0], dp[x][1]) << '\n';
}
}
}
int main() {
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
ll tests = 1;
//cin >> tests;
while (tests--) sol();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIGxsID0gbG9uZyBsb25nOwp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgbGwgbWF4biA9IDNlNSArIDU7CgpzdHJ1Y3QgVCB7CiAgICBsbCBhLCBiOwp9OwoKbGwgdCwgbiwgcTsKdmVjdG9yPHZlY3RvcjxsbD4+IGcobWF4biwgdmVjdG9yPGxsPigwKSksIGRwOwp2ZWN0b3I8VD4gZShtYXhuKTsKdmVjdG9yPGJvb2w+IHVzZWQobWF4bik7Cgp2b2lkIGRmcyhsbCB2LCBsbCBwID0gLTEpIHsKICAgIGZvciAoYXV0byBpIDogZ1t2XSkgewogICAgICAgIGlmICh1c2VkW2ldKSBjb250aW51ZTsKICAgICAgICBsbCB0bzsKICAgICAgICBpZiAoZVtpXS5hID09IHYpIHsKICAgICAgICAgICAgdG8gPSBlW2ldLmI7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdG8gPSBlW2ldLmE7CiAgICAgICAgfQogICAgICAgIGlmICh0byA9PSBwKSBjb250aW51ZTsKICAgICAgICBkZnModG8sIHYpOwogICAgICAgIGRwW3ZdWzBdICs9IG1heChkcFt0b11bMF0sIGRwW3RvXVsxXSk7CiAgICB9CiAgICBmb3IgKGF1dG8gaSA6IGdbdl0pIHsKICAgICAgICBpZiAodXNlZFtpXSkgY29udGludWU7CiAgICAgICAgbGwgdG87CiAgICAgICAgaWYgKGVbaV0uYSA9PSB2KSB7CiAgICAgICAgICAgIHRvID0gZVtpXS5iOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRvID0gZVtpXS5hOwogICAgICAgIH0KICAgICAgICBpZiAodG8gPT0gcCkgY29udGludWU7CiAgICAgICAgZHBbdl1bMV0gPSBtYXgoZHBbdl1bMV0sIGRwW3RvXVswXSArIDEgKyBkcFt2XVswXSAtIG1heChkcFt0b11bMF0sIGRwW3RvXVsxXSkpOwogICAgfQp9Cgp2b2lkIHNvbCgpIHsKICAgIGNpbiA+PiB0ID4+IG47CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBuIC0gMTsgaSsrKSB7CiAgICAgICAgbGwgYSwgYjsgY2luID4+IGEgPj4gYjsKICAgICAgICBlW2ldID0ge2EsIGJ9OwogICAgICAgIGdbYV0ucHVzaF9iYWNrKGkpOwogICAgICAgIGdbYl0ucHVzaF9iYWNrKGkpOwogICAgfQogICAgY2luID4+IHE7CiAgICB3aGlsZSAocS0tKSB7CiAgICAgICAgbGwgdHlwZTsgY2luID4+IHR5cGU7CiAgICAgICAgaWYgKHR5cGUgPT0gMSkgewogICAgICAgICAgICBsbCBpZDsgY2luID4+IGlkOwogICAgICAgICAgICB1c2VkW2lkXSA9ICF1c2VkW2lkXTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBsbCB4OyBjaW4gPj4geDsKICAgICAgICAgICAgZHAuYXNzaWduKG1heG4sIHZlY3RvcjxsbD4oMiwgMCkpOwogICAgICAgICAgICBkZnMoeCk7CiAgICAgICAgICAgIGNvdXQgPDwgbWF4KGRwW3hdWzBdLCBkcFt4XVsxXSkgPDwgJ1xuJzsKICAgICAgICB9CiAgICB9Cn0KCmludCBtYWluKCkgewogICAgLy9mcmVvcGVuKCJpbnB1dC50eHQiLCAiciIsIHN0ZGluKTsKICAgIC8vZnJlb3Blbigib3V0cHV0LnR4dCIsICJ3Iiwgc3Rkb3V0KTsKICAgIGlvczo6c3luY193aXRoX3N0ZGlvKDApOwogICAgY2luLnRpZSgwKTsKICAgIGxsIHRlc3RzID0gMTsKICAgIC8vY2luID4+IHRlc3RzOwogICAgd2hpbGUgKHRlc3RzLS0pIHNvbCgpOwogICAgcmV0dXJuIDA7Cn0K