#include <bits/stdc++.h>
const int mod = 10007;
const int maxn = 5e5 + 5;
const int inf = 1e9;
const long long onf = 1e18;
using namespace std;
int n, m;
int cnt, tot, head[maxn << 1];
int in[maxn], out[maxn];
int line[maxn << 2], lazy[maxn << 2], father[maxn];
bool flag = 0;
struct node {
  int v, next;
} tree[maxn << 1];
void add_edge(int u, int v) {
  tree[cnt].v = v;
  tree[cnt].next = head[u];
  head[u] = cnt++;
}
void DFS(int u, int fa) {
  in[u] = ++tot;
  father[u] = fa;
  for (int i = head[u]; i != -1; i = tree[i].next) {
    int v = tree[i].v;
    if (v == fa) continue;
    DFS(v, u);
  }
  out[u] = tot;
}
void push_up(int rt) {
  if (line[rt << 1] && line[rt << 1 | 1])
    line[rt] = 1;
  else
    line[rt] = 0;
}
void push_down(int rt) {
  if (lazy[rt]) {
    lazy[rt << 1] = lazy[rt << 1 | 1] = lazy[rt];
    line[rt << 1] = line[rt << 1 | 1] = lazy[rt];
    lazy[rt] = 0;
  }
}
void push_date(int L, int R, int x, int l, int r, int rt) {
  if (L == 0) return;
  if (L <= l && R >= r) {
    if (!line[rt]) flag = 1;
    line[rt] = x, lazy[rt] = x;
    return;
  }
  push_down(rt);
  int mid = (l + r) >> 1;
  if (L <= mid) push_date(L, R, x, l, mid, rt << 1);
  if (R > mid) push_date(L, R, x, mid + 1, r, rt << 1 | 1);
  push_up(rt);
}
void query(int L, int R, int l, int r, int rt) {
  if (L <= l && R >= r) {
    if (!line[rt]) flag = 1;
    return;
  }
  push_down(rt);
  int mid = (l + r) >> 1;
  if (L <= mid) query(L, R, l, mid, rt << 1);
  if (R > mid) query(L, R, mid + 1, r, rt << 1 | 1);
}
void init() {
  memset(head, -1, sizeof(head));
  tot = cnt = 0;
}
int main() {
  init();
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add_edge(u, v);
    add_edge(v, u);
  }
  DFS(1, 0);
  scanf("%d", &m);
  while (m--) {
    int opt, pos;
    scanf("%d%d", &opt, &pos);
    if (opt == 1) {
      flag = 0;
      push_date(in[pos], out[pos], 1, 1, n, 1);
      if (flag) push_date(in[father[pos]], in[father[pos]], 0, 1, n, 1);
    } else if (opt == 2) {
      push_date(in[pos], in[pos], 0, 1, n, 1);
    } else {
      flag = 0;
      query(in[pos], out[pos], 1, n, 1);
      if (flag)
        puts("0");
      else
        puts("1");
    }
  }
  return 0;
}
