#include <bits/stdc++.h>
using namespace std;
inline int rd() {
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  int x = (c ^ 48);
  c = getchar();
  while (c <= '9' && c >= '0') {
    x = x * 10 + (c ^ 48);
    c = getchar();
  }
  return x;
}
const int mxn = 5e5 + 5;
int n, tot, ldfn, q;
int lst[mxn], to[mxn << 1], nxt[mxn << 1], fa[mxn], dep[mxn];
int son[mxn], hson[mxn], pl[mxn], pr[mxn], tp[mxn];
inline void add(int a, int b) {
  tot++;
  to[tot] = b;
  nxt[tot] = lst[a];
  lst[a] = tot;
}
struct tree {
  int l;
  int r;
  int dx;
  int dn;
} tr[mxn << 2];
inline void dfs1(int pt) {
  son[pt] = 1;
  for (register int i = lst[pt]; i; i = nxt[i]) {
    if (!dep[to[i]]) {
      dep[to[i]] = dep[pt] + 1;
      fa[to[i]] = pt;
      dfs1(to[i]);
      son[pt] += son[to[i]];
      if (son[hson[pt]] < son[to[i]]) hson[pt] = to[i];
    }
  }
}
inline void dfs2(int pt, int top) {
  tp[pt] = top;
  ldfn++;
  pl[pt] = ldfn;
  if (hson[pt]) dfs2(hson[pt], top);
  for (register int i = lst[pt]; i; i = nxt[i]) {
    if (to[i] != fa[pt] && to[i] != hson[pt]) {
      dfs2(to[i], to[i]);
    }
  }
  pr[pt] = ldfn;
}
inline void build(int xl, int xr, int xp) {
  tr[xp].l = xl;
  tr[xp].r = xr;
  tr[xp].dn = 2;
  tr[xp].dx = 0;
  if (xl == xr) return;
  int md = (xl + xr) >> 1;
  build(xl, md, xp << 1);
  build(md + 1, xr, xp << 1 | 1);
}
inline void down(int xp) {
  if (tr[xp].dn != 2) {
    tr[xp << 1].dn = tr[xp].dn;
    tr[xp << 1].dx = tr[xp].dn;
    tr[xp << 1 | 1].dn = tr[xp].dn;
    tr[xp << 1 | 1].dx = tr[xp].dn;
    tr[xp].dn = 2;
  }
}
void change(int xl, int xr, int xp, int o) {
  if (xl <= tr[xp].l && tr[xp].r <= xr) {
    tr[xp].dx = o;
    tr[xp].dn = o;
    return;
  }
  down(xp);
  int md = (tr[xp].l + tr[xp].r) >> 1;
  if (xl <= md) change(xl, xr, xp << 1, o);
  if (md < xr) change(xl, xr, xp << 1 | 1, o);
}
int ask(int xd, int xp) {
  if (tr[xp].l == xd && tr[xp].r == xd) return tr[xp].dx;
  down(xp);
  int md = (tr[xp].l + tr[xp].r) >> 1;
  if (xd <= md) return ask(xd, xp << 1);
  if (md < xd) return ask(xd, xp << 1 | 1);
}
int main() {
  n = rd();
  for (register int u, v, i = 1; i < n; i++) {
    u = rd();
    v = rd();
    add(u, v);
    add(v, u);
  }
  dep[1] = 1;
  dfs1(1);
  dfs2(1, 1);
  build(1, n, 1);
  q = rd();
  for (register int iq = 1, op, opx; iq <= q; iq++) {
    op = rd();
    opx = rd();
    switch (op) {
      case 1:
        change(pl[opx], pr[opx], 1, 1);
        break;
      case 2:
        while (tp[opx] != 1) {
          change(pl[tp[opx]], pl[opx], 1, 0);
          opx = fa[tp[opx]];
        }
        change(pl[1], pl[opx], 1, 0);
        break;
      case 3:
        if (ask(pl[opx], 1))
          putchar('1');
        else
          putchar('0');
        putchar('\n');
        break;
    }
  }
  return 0;
}
