#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  char c;
  long long x = 0, w = 1;
  for (c = getchar(); c < '0' || c > '9'; c = getchar())
    if (c == '-') w = -1;
  for (; c <= '9' && c >= '0'; c = getchar())
    x = (x << 1) + (x << 3) + (c ^ 48);
  return x * w;
}
const int maxn = 500005;
long long n, h[maxn], cnt, q;
struct edge {
  long long to, next;
};
edge e[maxn << 1];
inline void add(long long x, long long y) {
  e[++cnt].next = h[x];
  e[cnt].to = y;
  h[x] = cnt;
}
long long d[maxn], son[maxn], top[maxn], siz[maxn], f[maxn], sign, id[maxn];
inline void dfs1(long long x, long long dep) {
  d[x] = dep;
  siz[x] = 1;
  long long maxs = -1;
  for (register int i = h[x]; i; i = e[i].next) {
    long long y = e[i].to;
    if (f[x] == y) continue;
    f[y] = x;
    dfs1(y, dep + 1);
    siz[x] += siz[y];
    if (maxs < siz[y]) maxs = siz[y], son[x] = y;
  }
}
inline void dfs2(long long x, long long ntop) {
  id[x] = ++sign;
  top[x] = ntop;
  if (!son[x]) return;
  dfs2(son[x], ntop);
  for (register int i = h[x]; i; i = e[i].next) {
    long long y = e[i].to;
    if (f[x] == y || y == son[x]) continue;
    dfs2(y, y);
  }
}
long long tag[maxn << 2], ans[maxn << 2];
inline long long ls(long long p) { return p << 1; }
inline long long rs(long long p) { return p << 1 | 1; }
inline void push_down(long long p) {
  ans[ls(p)] = tag[p];
  ans[rs(p)] = tag[p];
  tag[ls(p)] = tag[p];
  tag[rs(p)] = tag[p];
  tag[p] = -1;
}
inline void upd(long long p, long long l, long long r, long long nl,
                long long nr, long long v) {
  if (l >= nl && r <= nr) {
    ans[p] = v;
    tag[p] = v;
    return;
  }
  if (tag[p] != -1) push_down(p);
  long long mid = (l + r) >> 1;
  if (mid >= nl) upd(ls(p), l, mid, nl, nr, v);
  if (mid < nr) upd(rs(p), mid + 1, r, nl, nr, v);
}
inline long long query(long long p, long long l, long long r, long long x) {
  if (l == r) return ans[p];
  if (tag[p] != -1) push_down(p);
  long long mid = (l + r) >> 1;
  if (mid >= x)
    return query(ls(p), l, mid, x);
  else
    return query(rs(p), mid + 1, r, x);
}
inline void upd_range(long long x) {
  while (top[x] != 1) {
    upd(1, 1, n, id[top[x]], id[x], 0);
    x = f[top[x]];
  }
  upd(1, 1, n, 1, id[x], 0);
}
int main() {
  memset(tag, -1, sizeof(tag));
  n = read();
  for (register int i = 1; i < n; i++) {
    long long x = read(), y = read();
    add(x, y);
    add(y, x);
  }
  dfs1(1, 1);
  dfs2(1, 1);
  q = read();
  for (register int i = 1; i <= q; i++) {
    long long op = read();
    if (op == 1) {
      long long v = read();
      upd(1, 1, n, id[v], id[v] + siz[v] - 1, 1);
    }
    if (op == 2) {
      long long v = read();
      upd_range(v);
    }
    if (op == 3) {
      long long v = read();
      printf("%lld\n", query(1, 1, n, id[v]));
    }
  }
  return 0;
}
