#include <bits/stdc++.h>
using namespace std;
template <typename t>
inline void fcin(t &x) {
  int sign = 1;
  x = 0;
  char op = getchar();
  while (op < '0' || op > '9') {
    if (op == '-') sign = -1;
    op = getchar();
  }
  while (op >= '0' && op <= '9') {
    x = x * 10 + (op - 48);
    op = getchar();
  }
  x *= sign;
}
struct node {
  int L, R;
  mutable int v;
  node(int x, int y = -1, int z = 0) : L(x), R(y), v(z) {}
  bool operator<(const node &x) const { return L < x.L; }
};
set<node> s;
set<node>::iterator split(int pos) {
  set<node>::iterator iter = s.lower_bound(node(pos));
  if (iter != s.end() && iter->L == pos) return iter;
  iter--;
  int x = iter->L, y = iter->R;
  int z = iter->v;
  s.erase(iter);
  s.insert(node(x, pos - 1, z));
  return s.insert(node(pos, y, z)).first;
}
inline void fill(int l, int r, int d) {
  set<node>::iterator iterr = split(r + 1), iterl = split(l);
  s.erase(iterl, iterr);
  s.insert(node(l, r, d));
}
int query(int pos) {
  set<node>::iterator iter = split(pos);
  return iter->v;
}
int n, m;
int to[500005 << 1], nxt[500005 << 1], head[500005], siz[500005], id[500005];
int w[500005], Xson[500005], dep[500005], fa[500005], top[500005], tot;
inline void Eadd(int u, int v) {
  nxt[++tot] = head[u];
  to[tot] = v;
  head[u] = tot;
}
void DFS(int u) {
  siz[u] = 1;
  int maxsize = 0;
  for (int i = head[u]; i; i = nxt[i])
    if (!dep[to[i]]) {
      dep[to[i]] = dep[u] + 1;
      DFS(to[i]);
      siz[u] += siz[to[i]];
      fa[to[i]] = u;
      if (siz[to[i]] > maxsize) {
        maxsize = siz[to[i]];
        Xson[u] = to[i];
      }
    }
}
void DFS(int u, int TOP) {
  id[u] = ++id[0];
  top[u] = TOP;
  if (siz[u] == 1) return;
  DFS(Xson[u], TOP);
  for (int i = head[u]; i; i = nxt[i])
    if (to[i] != Xson[u] & fa[u] != to[i]) DFS(to[i], to[i]);
}
void pathcov(int x, int y, int dt) {
  while (top[x] != top[y]) {
    if (dep[top[x]] < dep[top[y]]) swap(x, y);
    fill(id[top[x]], id[x], dt);
    x = fa[top[x]];
  }
  if (dep[x] < dep[y]) swap(x, y);
  fill(id[y], id[x], dt);
}
int main() {
  fcin(n);
  int op, x, y;
  for (int i = 1; i < n; i++) fcin(x), fcin(y), Eadd(x, y), Eadd(y, x);
  s.insert(node(1, n, 0));
  dep[1] = 1;
  DFS(1);
  DFS(1, 1);
  fcin(m);
  for (int i = 1; i <= m; i++) {
    fcin(op);
    fcin(x);
    if (op == 1) {
      fill(id[x], id[x] + siz[x] - 1, 1);
    } else if (op == 2) {
      pathcov(1, x, 0);
    } else {
      printf("%d\n", query(id[x]));
    }
  }
  return 0;
}
