#include <bits/stdc++.h>
using namespace std;
inline int Mid(int a, int b) { return (a + b) >> 1; }
struct Edge {
  int from, to, nex;
} edge[510000 << 1];
int head[510000], edgenum;
void add(int u, int v) {
  Edge E = {u, v, head[u]};
  edge[edgenum] = E;
  head[u] = edgenum++;
}
struct node {
  int l, r, minn;
} tree[510000 << 2];
void push_up(int id) {
  tree[id].minn =
      min(tree[id].minn, min(tree[(id << 1)].minn, tree[(id << 1 | 1)].minn));
}
void push_down(int id) {
  if (tree[id].l == tree[id].r) return;
  if (tree[id].minn) {
    tree[(id << 1)].minn = tree[(id << 1 | 1)].minn = 1;
  }
}
void build(int l, int r, int id) {
  tree[id].l = l, tree[id].r = r;
  tree[id].minn = 0;
  if (l == r) return;
  int mid = Mid(l, r);
  build(l, mid, (id << 1));
  build(mid + 1, r, (id << 1 | 1));
}
void updata_point(int pos, int id) {
  push_down(id);
  if (tree[id].l == tree[id].r) {
    tree[id].minn = 0;
    return;
  }
  int mid = Mid(tree[id].l, tree[id].r);
  if (pos <= mid)
    updata_point(pos, (id << 1));
  else
    updata_point(pos, (id << 1 | 1));
  push_up(id);
}
void updata_inter(int l, int r, int id) {
  push_down(id);
  if (l == tree[id].l && tree[id].r == r) {
    tree[id].minn = 1;
    return;
  }
  int mid = Mid(tree[id].l, tree[id].r);
  if (mid < l)
    updata_inter(l, r, (id << 1 | 1));
  else if (r <= mid)
    updata_inter(l, r, (id << 1));
  else {
    updata_inter(l, mid, (id << 1));
    updata_inter(mid + 1, r, (id << 1 | 1));
  }
  push_up(id);
}
int query(int l, int r, int id) {
  push_down(id);
  if (l == tree[id].l && tree[id].r == r) return tree[id].minn;
  int mid = Mid(tree[id].l, tree[id].r);
  if (mid < l)
    return query(l, r, (id << 1 | 1));
  else if (r <= mid)
    return query(l, r, (id << 1));
  else
    return min(query(l, mid, (id << 1)), query(mid + 1, r, (id << 1 | 1)));
}
int n;
int in[510000], out[510000], Time, Father[510000];
void dfs(int u, int fa) {
  Father[u] = fa;
  in[u] = ++Time;
  for (int i = head[u]; ~i; i = edge[i].nex) {
    int v = edge[i].to;
    if (v == fa) continue;
    dfs(v, u);
  }
  out[u] = Time;
}
void init() {
  memset(head, -1, sizeof head);
  edgenum = 0;
}
int main() {
  int i, j, u, v, que;
  while (~scanf("%d", &n)) {
    init();
    for (i = 1; i < n; i++) {
      scanf("%d %d", &u, &v);
      add(u, v);
      add(v, u);
    }
    Time = 0;
    dfs(1, -1);
    build(1, Time, 1);
    scanf("%d", &que);
    while (que--) {
      scanf("%d %d", &u, &v);
      if (u == 1) {
        int tmp = query(in[v], out[v], 1);
        updata_inter(in[v], out[v], 1);
        if (Father[v] != -1 && tmp == 0) updata_point(in[Father[v]], 1);
      } else if (u == 2) {
        updata_point(in[v], 1);
      } else
        printf("%d\n", query(in[v], out[v], 1));
    }
  }
  return 0;
}
