#include <bits/stdc++.h>
using namespace std;
int n, m;
int opt, u;
const int MAXN = 500006;
int tree[MAXN << 2], tag[MAXN << 2];
int son[MAXN], id[MAXN], fa[MAXN], top_[MAXN], siz[MAXN], de[MAXN];
int head[MAXN], nxt[MAXN << 1], to[MAXN << 1];
int cnt, tot;
inline void add_edge(int x, int y) {
  ++cnt;
  to[cnt] = y;
  nxt[cnt] = head[x];
  head[x] = cnt;
}
inline int dfs1(int now, int fath) {
  siz[now] = 1;
  de[now] = de[fath] + 1;
  fa[now] = fath;
  int maxn = -1;
  for (register int i = head[now]; i; i = nxt[i]) {
    if (to[i] == fath) continue;
    siz[now] += dfs1(to[i], now);
    if (siz[to[i]] > maxn) {
      maxn = siz[to[i]];
      son[now] = to[i];
    }
  }
  return siz[now];
}
inline void dfs2(int now, int _top) {
  top_[now] = _top;
  id[now] = ++tot;
  if (!son[now]) return;
  dfs2(son[now], _top);
  for (register int i = head[now]; i; i = nxt[i]) {
    if (to[i] == fa[now] || to[i] == son[now]) continue;
    dfs2(to[i], to[i]);
  }
  return;
}
inline void Pushdown(int l, int r, int k) {
  tree[k << 1] = tree[k];
  tree[k << 1 | 1] = tree[k];
  tag[k << 1] = tag[k];
  tag[k << 1 | 1] = tag[k];
  tag[k] = -1;
}
inline void undate(int L, int R, int l, int r, int k, int v) {
  if (L <= l && r <= R) {
    tree[k] = v;
    tag[k] = v;
    return;
  }
  if (tag[k] != -1) Pushdown(l, r, k);
  int mid = (l + r) >> 1;
  if (L <= mid) undate(L, R, l, mid, k << 1, v);
  if (R > mid) undate(L, R, mid + 1, r, k << 1 | 1, v);
  return;
}
inline int query(int L, int R, int l, int r, int k) {
  if (L <= l && r <= R) {
    return tree[k];
  }
  if (tag[k] != -1) Pushdown(l, r, k);
  int mid = (l + r) >> 1;
  if (L <= mid)
    return query(L, R, l, mid, k << 1);
  else
    return query(L, R, mid + 1, r, k << 1 | 1);
}
inline void Rundate(int x, int y) {
  while (top_[x] != top_[y]) {
    if (de[top_[x]] < de[top_[y]]) swap(x, y);
    undate(id[top_[x]], id[x], 1, n, 1, 0);
    x = fa[top_[x]];
  }
  if (de[x] > de[y]) swap(x, y);
  undate(id[x], id[y], 1, n, 1, 0);
  return;
}
int main() {
  memset(tag, -1, sizeof tag);
  int x, y;
  scanf("%d", &n);
  for (register int i = 1; i < n; i = -~i) {
    scanf("%d%d", &x, &y);
    add_edge(x, y);
    add_edge(y, x);
  }
  dfs1(1, 0);
  dfs2(1, 1);
  scanf("%d", &m);
  while (m--) {
    scanf("%d%d", &opt, &x);
    if (opt == 1) undate(id[x], id[x] + siz[x] - 1, 1, n, 1, 1);
    if (opt == 2) Rundate(1, x);
    if (opt == 3) printf("%d\n", query(id[x], id[x], 1, n, 1));
  }
  return 0;
}
