#include <bits/stdc++.h>
inline int read() {
  int num = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) f = c == '-' ? -1 : 1, c = getchar();
  while (isdigit(c)) num = (num << 1) + (num << 3) + (c ^ 48), c = getchar();
  return num * f;
}
namespace Line {
struct node {
  node *lson, *rson;
  int sum, add;
  node(node *lson = NULL, node *rson = NULL, int sum = 0, int add = -1)
      : lson(lson), rson(rson), sum(sum), add(add) {}
};
typedef node *tree;
inline void update(tree &now) { now->sum = now->lson->sum + now->rson->sum; }
void build(tree &now, int l, int r) {
  now = new node();
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(now->lson, l, mid);
  build(now->rson, mid + 1, r);
}
inline void pushdown(tree &now, int l, int r) {
  if (now->add == -1) return;
  int mid = (l + r) >> 1;
  now->lson->sum = now->add * (mid - l + 1);
  now->rson->sum = now->add * (r - mid);
  now->lson->add = now->add;
  now->rson->add = now->add;
  now->add = -1;
}
void change(tree &now, int l, int r, int ql, int qr, int k) {
  if (ql <= l && r <= qr) {
    now->sum = k * (r - l + 1);
    now->add = k;
    return;
  }
  pushdown(now, l, r);
  int mid = (l + r) >> 1;
  if (ql <= mid) change(now->lson, l, mid, ql, qr, k);
  if (qr >= mid + 1) change(now->rson, mid + 1, r, ql, qr, k);
  update(now);
}
int query(tree &now, int l, int r, int q) {
  if (l == r) return now->sum;
  pushdown(now, l, r);
  int mid = (l + r) >> 1;
  if (q <= mid) return query(now->lson, l, mid, q);
  return query(now->rson, mid + 1, r, q);
}
}  // namespace Line
struct Edge {
  int to, next;
  Edge(int to = 0, int next = 0) : to(to), next(next) {}
} G[500005 << 1];
int head[500005], cnt;
inline void add(int u, int v) {
  G[++cnt] = Edge(v, head[u]);
  head[u] = cnt;
  G[++cnt] = Edge(u, head[v]);
  head[v] = cnt;
}
int size[500005], son[500005], dep[500005], fa[500005], id[500005], top[500005],
    dfn;
int n, m, x, y;
Line::tree t;
void dfs1(int now) {
  dep[now] = dep[fa[now]] + 1;
  size[now] = 1;
  for (int i = head[now]; ~i; i = G[i].next) {
    int &v = G[i].to;
    if (v == fa[now]) continue;
    fa[v] = now;
    dfs1(v);
    size[now] += size[v];
    if (size[v] > size[son[now]]) son[now] = v;
  }
}
void dfs2(int now, int t) {
  id[now] = ++dfn;
  top[now] = t;
  if (!son[now]) return;
  dfs2(son[now], t);
  for (int i = head[now]; ~i; i = G[i].next) {
    int &v = G[i].to;
    if (v == fa[now] || v == son[now]) continue;
    dfs2(v, v);
  }
}
int main() {
  memset(head, -1, sizeof(head));
  n = read();
  for (int i = 1; i <= n - 1; i++) x = read(), y = read(), add(x, y);
  m = read();
  dfs1(1);
  dfs2(1, 1);
  Line::build(t, 1, n);
  for (int i = 1; i <= m; i++) {
    x = read();
    y = read();
    if (x == 1)
      Line::change(t, 1, n, id[y], id[y] + size[y] - 1, 1);
    else if (x == 2) {
      while (top[y] != 1)
        Line::change(t, 1, n, id[top[y]], id[y], 0), y = fa[top[y]];
      Line::change(t, 1, n, 1, id[y], 0);
    } else if (x == 3)
      printf("%d\n", Line::query(t, 1, n, id[y]));
  }
  return 0;
}
