#include <bits/stdc++.h>
using namespace std;
inline int input() {
  int ret = 0;
  bool isN = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') isN = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    ret = ret * 10 + c - '0';
    c = getchar();
  }
  return isN ? -ret : ret;
}
inline void output(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  int len = 0, data[11];
  while (x) {
    data[len++] = x % 10;
    x /= 10;
  }
  if (!len) data[len++] = 0;
  while (len--) putchar(data[len] + 48);
  putchar('\n');
}
const int MAXN = 500005;
int to[MAXN], last[MAXN], cnt;
int n, x, y, status[MAXN << 2], q, fa[MAXN], lazy[MAXN << 2];
struct EDGE {
  int v, next;
} edge[MAXN << 1];
int head[MAXN], e;
inline void addEdge(int u, int v) {
  edge[e].v = v;
  edge[e].next = head[u];
  head[u] = e++;
}
inline void dfs(int now, int pre) {
  to[now] = (++cnt);
  fa[now] = pre;
  for (int i = head[now]; i != -1; i = edge[i].next) {
    int v = edge[i].v;
    if (v != pre) dfs(v, now);
  }
  last[now] = cnt;
}
inline void push_up(int t) {
  status[t] = min(status[t << 1], status[t << 1 | 1]);
}
inline void push_down(int t) {
  if (lazy[t] != -1) {
    status[t << 1] = status[t << 1 | 1] = lazy[t];
    lazy[t << 1] = lazy[t << 1 | 1] = lazy[t];
    lazy[t] = -1;
  }
}
inline void add(int t, int l, int r, int x, int y, int st) {
  if (l >= x && r <= y) {
    status[t] = lazy[t] = st;
    return;
  }
  push_down(t);
  int mid = (l + r) >> 1;
  if (y <= mid)
    add(t << 1, l, mid, x, y, st);
  else if (x > mid)
    add(t << 1 | 1, mid + 1, r, x, y, st);
  else {
    add(t << 1, l, mid, x, mid, st);
    add(t << 1 | 1, mid + 1, r, mid + 1, y, st);
  }
  push_up(t);
}
inline void add(int t, int l, int r, int x, int st) {
  if (l == r) {
    status[t] = st;
    return;
  }
  push_down(t);
  int mid = (l + r) >> 1;
  if (x <= mid)
    add(t << 1, l, mid, x, st);
  else
    add(t << 1 | 1, mid + 1, r, x, st);
  push_up(t);
}
inline int query(int t, int l, int r, int x, int y) {
  if (l >= x && r <= y) return status[t];
  push_down(t);
  int mid = (l + r) >> 1;
  if (y <= mid)
    return query(t << 1, l, mid, x, y);
  else if (x > mid)
    return query(t << 1 | 1, mid + 1, r, x, y);
  else {
    return min(query(t << 1, l, mid, x, mid),
               query(t << 1 | 1, mid + 1, r, mid + 1, y));
  }
}
void Print(int t) {
  if (t <= 5) {
    printf("%d %d\n", t, status[t]);
    Print(t << 1), Print(t << 1 | 1);
  }
}
int main() {
  n = input();
  memset(head, -1, sizeof head);
  e = cnt = 0;
  for (int i = 1; i < n; i++) {
    x = input(), y = input();
    addEdge(x, y);
    addEdge(y, x);
  }
  dfs(1, 0);
  memset(status, 0, sizeof status);
  memset(lazy, -1, sizeof lazy);
  q = input();
  while (q--) {
    y = input();
    x = input();
    if (y == 1) {
      int v = query(1, 1, cnt, to[x], last[x]);
      add(1, 1, cnt, to[x], last[x], 1);
      if (fa[x] != 0 && v == 0) {
        add(1, 1, cnt, to[fa[x]], 0);
      }
    } else if (y == 2) {
      add(1, 1, cnt, to[x], 0);
    } else {
      output(query(1, 1, cnt, to[x], last[x]));
    }
  }
  return 0;
}
