#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 * 5 + 10;
struct node {
  int nextt, edge;
} w[maxn * 2];
int father[maxn], top[maxn], dep[maxn], siz[maxn];
int dfn[maxn], seq[maxn], f[maxn], head[maxn];
int sum[maxn * 5], flag[maxn * 5], heavy_son[maxn];
int ans, num, tot, x, y, z, p, m, r, n;
void add(int a, int b) {
  tot++;
  w[tot].edge = b;
  w[tot].nextt = head[a];
  head[a] = tot;
}
void dfs_1(int now, int fa) {
  father[now] = fa;
  siz[now] = 1;
  dep[now] = dep[fa] + 1;
  for (int i = head[now]; i; i = w[i].nextt)
    if (w[i].edge != fa) {
      dfs_1(w[i].edge, now);
      siz[now] += siz[w[i].edge];
      if (siz[w[i].edge] > siz[heavy_son[now]]) heavy_son[now] = w[i].edge;
    }
}
void dfs_2(int now, int topp) {
  top[now] = topp;
  dfn[now] = ++num;
  seq[num] = now;
  if (heavy_son[now] == 0) return;
  dfs_2(heavy_son[now], topp);
  for (int i = head[now]; i; i = w[i].nextt)
    if (w[i].edge != father[now] && w[i].edge != heavy_son[now])
      dfs_2(w[i].edge, w[i].edge);
}
void push_down(int now) {
  int son = now << 1;
  flag[son] = flag[son + 1] = sum[son] = sum[son + 1] = flag[now];
  flag[now] = -1;
}
void query(int now, int l, int r) {
  if (l == r) {
    ans = sum[now];
    return;
  }
  if (flag[now] != -1) push_down(now);
  int son = now << 1;
  int mid = (l + r) >> 1;
  if (x <= mid)
    query(son, l, mid);
  else
    query(son + 1, mid + 1, r);
}
void change(int now, int l, int r) {
  if (l >= x && r <= y) {
    sum[now] = flag[now] = z;
    return;
  }
  if (flag[now] != -1) push_down(now);
  int son = now << 1;
  int mid = (l + r) >> 1;
  if (x <= mid) change(son, l, mid);
  if (y > mid) change(son + 1, mid + 1, r);
}
void change_sum(int a, int b) {
  int ta = top[a];
  int tb = top[b];
  while (ta != tb) {
    if (dep[ta] < dep[tb]) {
      swap(ta, tb);
      swap(a, b);
    }
    x = dfn[ta];
    y = dfn[a];
    change(1, 1, n);
    a = father[ta];
    ta = top[a];
  }
  if (dep[a] < dep[b]) swap(a, b);
  x = dfn[b];
  y = dfn[a];
  change(1, 1, n);
}
int main() {
  int i, a, b, op;
  cin >> n;
  for (i = 1; i <= n - 1; ++i) {
    scanf("%d%d", &a, &b);
    add(a, b);
    add(b, a);
  }
  dfs_1(1, 0);
  dfs_2(1, 1);
  cin >> m;
  for (i = 1; i <= 2500005; ++i) flag[i] = -1;
  for (i = 1; i <= m; ++i) {
    scanf("%d%d", &op, &a);
    if (op == 1) {
      x = dfn[a];
      y = x + siz[a] - 1;
      z = 1;
      change(1, 1, n);
    }
    if (op == 2) {
      z = 0;
      change_sum(1, a);
    }
    if (op == 3) {
      ans = -1;
      x = dfn[a];
      query(1, 1, n);
      cout << ans << endl;
    }
  }
  return 0;
}
