#include <bits/stdc++.h>
using namespace std;
const int maxx = 5e5 + 100;
int head[maxx << 1], pre[maxx], id[maxx];
int size[maxx], son[maxx], fa[maxx];
int dep[maxx], top[maxx];
struct edge {
  int to;
  int next;
} e[maxx << 1];
struct node {
  int l;
  int r;
  int lazy;
  int sum;
} p[maxx * 4];
int n, m, tot, sign;
void init() {
  memset(head, -1, sizeof(head));
  tot = sign = 0;
}
void add(int u, int v) {
  e[tot].to = v, e[tot].next = head[u], head[u] = tot++;
}
void dfs1(int u, int f) {
  dep[u] = dep[f] + 1;
  fa[u] = f;
  size[u] = 1;
  for (int i = head[u]; i != -1; i = e[i].next) {
    int to = e[i].to;
    if (to == f) continue;
    dfs1(to, u);
    size[u] += size[to];
    if (size[to] > size[son[u]]) son[u] = to;
  }
}
void dfs2(int u, int Top) {
  id[u] = ++sign;
  pre[sign] = u;
  top[u] = Top;
  if (son[u]) dfs2(son[u], Top);
  for (int i = head[u]; i != -1; i = e[i].next) {
    int to = e[i].to;
    if (to == son[u] || to == fa[u]) continue;
    dfs2(to, to);
  }
}
void pushup(int cur) { p[cur].sum = p[cur << 1].sum + p[cur << 1 | 1].sum; }
void pushdown(int cur) {
  if (p[cur].lazy > 0) {
    p[cur << 1].sum = p[cur << 1].r - p[cur << 1].l + 1;
    p[cur << 1 | 1].sum = p[cur << 1 | 1].r - p[cur << 1 | 1].l + 1;
    p[cur << 1].lazy = 1;
    p[cur << 1 | 1].lazy = 1;
    p[cur].lazy = 0;
  } else if (p[cur].lazy < 0) {
    p[cur << 1].sum = p[cur << 1 | 1].sum = 0;
    p[cur << 1].lazy = p[cur << 1 | 1].lazy = -1;
    p[cur].lazy = 0;
  }
}
void build(int l, int r, int cur) {
  p[cur].l = l;
  p[cur].r = r;
  p[cur].sum = 0;
  if (l == r) return;
  int mid = (l + r) / 2;
  build(l, mid, 2 * cur);
  build(mid + 1, r, 2 * cur + 1);
  pushup(cur);
}
void update(int l, int r, int cur, int add) {
  if (p[cur].sum == p[cur].r - p[cur].l + 1 && add == 1) return;
  if (p[cur].sum == 0 && add == -1) return;
  int L = p[cur].l;
  int R = p[cur].r;
  if (l <= L && R <= r) {
    if (add > 0) {
      p[cur].sum = (R - L + 1);
      p[cur].lazy = 1;
    } else {
      p[cur].sum = 0;
      p[cur].lazy = -1;
    }
    return;
  }
  pushdown(cur);
  int mid = (L + R) / 2;
  if (r <= mid)
    update(l, r, 2 * cur, add);
  else if (l > mid)
    update(l, r, 2 * cur + 1, add);
  else {
    update(l, mid, 2 * cur, add);
    update(mid + 1, r, 2 * cur + 1, add);
  }
  pushup(cur);
}
int query(int x, int cur) {
  int L = p[cur].l;
  int R = p[cur].r;
  if (p[cur].sum == R - L + 1) return 1;
  if (L == R) {
    if (p[cur].sum)
      return 1;
    else
      return 0;
  }
  pushdown(cur);
  int mid = (L + R) / 2;
  if (x <= mid)
    return query(x, 2 * cur);
  else
    return query(x, 2 * cur + 1);
}
void solve(int x, int y) {
  while (top[x] != top[y]) {
    if (dep[top[x]] < dep[top[y]]) swap(x, y);
    update(id[top[x]], id[x], 1, -1);
    x = fa[top[x]];
  }
  if (id[x] > id[y]) swap(x, y);
  update(id[x], id[y], 1, -1);
}
int main() {
  init();
  scanf("%d", &n);
  int x, y;
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    add(x, y);
    add(y, x);
  }
  dep[0] = 0;
  dfs1(1, 0);
  dfs2(1, 1);
  build(1, n, 1);
  scanf("%d", &m);
  while (m--) {
    scanf("%d%d", &x, &y);
    if (x == 1)
      update(id[y], id[y] + size[y] - 1, 1, 1);
    else if (x == 2)
      solve(1, y);
    else
      printf("%d\n", query(id[y], 1));
  }
  return 0;
}
