#include <bits/stdc++.h>
using namespace std;
int mod;
const int maxn = 1e6 + 100;
struct edge {
  int to, next;
} e[maxn];
int head[maxn], ecnt;
void add(int u, int v) {
  e[++ecnt] = (edge){v, head[u]};
  head[u] = ecnt;
}
int size[maxn], son[maxn], depth[maxn], fa[maxn];
void dfs1(int u, int f) {
  size[u] = 1;
  for (int i = head[u]; i; i = e[i].next) {
    int v = e[i].to;
    if (v == f) continue;
    fa[v] = u;
    depth[v] = depth[u] + 1;
    dfs1(v, u);
    size[u] += size[v];
    if (size[v] > size[son[u]]) son[u] = v;
  }
}
int top[maxn], dfn[maxn], link[maxn], a[maxn];
int dfs_clock;
void dfs2(int u, int t) {
  top[u] = t;
  dfn[u] = ++dfs_clock;
  link[dfs_clock] = a[u];
  if (son[u]) dfs2(son[u], t);
  for (int i = head[u]; i; i = e[i].next) {
    int v = e[i].to;
    if (v == fa[u] || v == son[u]) continue;
    dfs2(v, v);
  }
}
struct tree {
  int l, r;
  mutable int val;
  bool operator<(const tree &A) const { return l < A.l; }
  tree(int _l, int _r = -1, int _val = 0) { l = _l, r = _r, val = _val; }
};
set<tree> s;
set<tree>::iterator split(int pos) {
  set<tree>::iterator it = s.lower_bound(tree(pos));
  if (it != s.end() && it->l == pos) return it;
  it--;
  int l = it->l, r = it->r, val = it->val;
  s.erase(it);
  s.insert(tree(l, pos - 1, val));
  return s.insert(tree(pos, r, val)).first;
}
void assign(int l, int r, int val) {
  set<tree>::iterator it2 = split(r + 1), it1 = split(l);
  s.erase(it1, it2);
  s.insert(tree(l, r, val));
}
inline int read() {
  int k = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) k = k * 10 + ch - '0';
  return k * f;
}
int main() {
  int n = read();
  for (int i = 1; i < n; i++) {
    int u = read(), v = read();
    add(u, v), add(v, u);
  }
  dfs1(1, 0);
  dfs2(1, 1);
  s.insert(tree(0, 500000 + 100));
  int m = read();
  while (m--) {
    int op = read(), k = read();
    if (op == 1) {
      assign(dfn[k], dfn[k] + size[k] - 1, 1);
    } else if (op == 2) {
      int pos = top[k];
      while (pos != 1) {
        assign(dfn[pos], dfn[k], 0);
        k = fa[pos];
        pos = top[k];
      }
      assign(dfn[1], dfn[k], 0);
    } else {
      printf("%d\n", split(dfn[k])->val);
    }
  }
}
