#include <bits/stdc++.h>
using namespace std;
const int maxn = 500010;
int Laxt[maxn], Next[maxn << 1], To[maxn << 1], cnt;
int fa[maxn], in[maxn], out[maxn], times;
void read(int &res) {
  char c = getchar();
  for (; c > '9' || c < '0'; c = getchar())
    ;
  for (res = 0; c >= '0' && c <= '9'; c = getchar())
    res = (res << 3) + (res << 1) + c - '0';
}
void add(int u, int v) {
  Next[++cnt] = Laxt[u];
  Laxt[u] = cnt;
  To[cnt] = v;
}
void dfs(int u, int pre) {
  fa[u] = pre;
  in[u] = ++times;
  for (int i = Laxt[u]; i; i = Next[i]) {
    int v = To[i];
    if (v != pre) dfs(v, u);
  }
  out[u] = times;
}
int Lazy[maxn << 2], all[maxn << 2];
struct DFSTree {
  void pushdown(int Now) {
    if (Lazy[Now]) {
      Lazy[Now] = 0;
      all[Now << 1] = 1;
      all[Now << 1 | 1] = 1;
      Lazy[Now << 1] = 1;
      Lazy[Now << 1 | 1] = 1;
    }
  }
  void pushup(int Now) { all[Now] = all[Now << 1] & all[Now << 1 | 1]; }
  void add(int Now, int L, int R, int l, int r) {
    if (l <= L && r >= R) {
      Lazy[Now] = 1;
      all[Now] = 1;
      return;
    }
    int Mid = (L + R) >> 1;
    pushdown(Now);
    if (l <= Mid) add(Now << 1, L, Mid, l, r);
    if (r > Mid) add(Now << 1 | 1, Mid + 1, R, l, r);
    pushup(Now);
  }
  int query(int Now, int L, int R, int l, int r) {
    if (l <= L && r >= R) return all[Now];
    int Mid = (L + R) >> 1;
    pushdown(Now);
    if (l <= Mid)
      if (!query(Now << 1, L, Mid, l, r)) return 0;
    if (r > Mid)
      if (!query(Now << 1 | 1, Mid + 1, R, l, r)) return 0;
    pushup(Now);
    return 1;
  }
  void del(int Now, int L, int R, int l, int r) {
    if (l <= L && r >= R) {
      Lazy[Now] = 0;
      all[Now] = 0;
      return;
    }
    int Mid = (L + R) >> 1;
    pushdown(Now);
    if (l <= Mid) del(Now << 1, L, Mid, l, r);
    if (r > Mid) del(Now << 1 | 1, Mid + 1, R, l, r);
    pushup(Now);
  }
} Tree;
int main() {
  int N, Q, u, v, i, j, opt;
  read(N);
  for (i = 1; i < N; i++) {
    read(u);
    read(v);
    add(u, v);
    add(v, u);
  }
  dfs(1, 1);
  read(Q);
  while (Q--) {
    read(opt);
    read(u);
    if (opt == 1) {
      if (!Tree.query(1, 1, N, in[u], out[u]))
        Tree.del(1, 1, N, in[fa[u]], in[fa[u]]);
      Tree.add(1, 1, N, in[u], out[u]);
    } else if (opt == 2)
      Tree.del(1, 1, N, in[u], in[u]);
    else
      printf("%d\n", Tree.query(1, 1, N, in[u], out[u]));
  }
  return 0;
}
