#include <bits/stdc++.h>
using namespace std;
const int MAX = (int)5e5;
const long long LINF = (long long)1e18 + 47;
struct segment_Tree
{
vector<long long> t_sum, t_mx;
int size;
void init(int n)
{
size = 1;
while (size < n) size *= 2;
t_sum.assign(2 * size - 1, 0);
t_mx.assign(2 * size - 1, 0);
}
long long sum(int v, int tl, int tr, int l, int r)
{
if (l >= tr || r <= tl) return 0;
if (tl >= l && tr <= r)
{
return t_sum[v];
}
int tm = (tl + tr) / 2;
long long s1 = sum(v * 2 + 1, tl, tm, l, r);
long long s2 = sum(v * 2 + 2, tm, tr, l, r);
return s1 + s2;
}
long long mx(int v, int tl, int tr, int l, int r)
{
if (l >= tr || r <= tl) return -LINF;
if (tl >= l && tr <= r) return t_mx[v];
int tm = (tl + tr) / 2;
long long s1 = mx(v * 2 + 1, tl, tm, l, r);
long long s2 = mx(v * 2 + 2, tm, tr, l, r);
return max(s1, s2);
}
long long sum(int l, int r)
{
return sum(0, 0, size, l, r);
}
long long mx(int l, int r)
{
return mx(0, 0, size, l, r);
}
void update_sum(int v, int tl, int tr, int pos, int val)
{
if (tr - tl == 1)
{
t_sum[v] = val;
return;
}
int tm = (tl + tr) / 2;
if (pos < tm)
{
update_sum(v * 2 + 1, tl, tm, pos, val);
}
else
{
update_sum(v * 2 + 2, tm, tr, pos, val);
}
t_sum[v] = t_sum[v * 2 + 1] + t_sum[v * 2 + 2];
}
void update_mx(int v, int tl, int tr, int pos, int val)
{
if (tr - tl == 1)
{
t_mx[v] = val;
return;
}
int tm = (tl + tr) / 2;
if (pos < tm)
{
update_mx(v * 2 + 1, tl, tm, pos, val);
}
else
{
update_mx(v * 2 + 2, tm, tr, pos, val);
}
t_mx[v] = max(t_mx[v *2 + 1], t_mx[v *2 + 2]);
}
void update_mx(int pos, int val)
{
update_mx(0, 0, size, pos, val);
}
void update_sum(int pos, int val)
{
update_sum(0, 0, size, pos, val);
}
} T;
vector<int> g[MAX];
int timer = 0;
int tin[MAX], tout[MAX];
int lvl[MAX];
vector<int> leaf;
int pr[MAX];
int n;
void dfs(int v, int l = 0, int p = -1)
{
pr[v] = p;
tin[v] = timer++;
lvl[v] = l;
for (auto to: g[v])
{
if (to == p) continue;
dfs(to, l + 1, v);
}
tout[v] = timer;
}
int main()
{
cin >> n;
for (int i = 0; i < n - 1; i++)
{
int a, b;
cin >> a >> b;
--a, --b;
g[a].push_back(b);
g[b].push_back(a);
}
for (int i = 1; i < n; i++)
{
if (g[i].size() == 1) leaf.push_back(i);
}
int q;
cin >> q;
vector<pair<int, int> > vec;
int nxt = n;
while (q--)
{
int type;
cin >> type;
if (type == 2)
{
int x;
cin >> x;
--x;
vec.push_back({1, x});
}
else
{
int x;
cin >> x;
--x;
vec.push_back({2, nxt});
g[x].push_back(nxt);
g[nxt++].push_back(x);
}
}
dfs(0);
T.init(MAX);
for (int i = 0; i < n; i++)
{
T.update_sum(tin[i], 1);
}
for (auto x: leaf)
{
T.update_mx(tin[x], lvl[x]);
}
for (int i = 0; i < vec.size(); i++)
{
if (vec[i].first == 1)
{
long long mx_deep_leaf = T.mx(tin[vec[i].second], tout[vec[i].second]);
long long count_of_leaf = T.sum(tin[vec[i].second], tout[vec[i].second]) - 1;
cout << 2 * count_of_leaf - (mx_deep_leaf - lvl[vec[i].second]) << '\n';
}
else
{
T.update_sum(tin[vec[i].second], 1);
T.update_mx(tin[vec[i].second], lvl[vec[i].second]);
int par = pr[vec[i].second];
T.update_mx(tin[par], 0);
}
}
return 0;
}