#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int N = 500010;
int first[N], Next[N << 1], V[N << 1];
int n;
int L[N], R[N], mk1[N << 2];
int tim;
void DFS(int u, int f) {
  L[u] = ++tim;
  for (int i = first[u]; i != -1; i = Next[i]) {
    int v = V[i];
    if (f == v) continue;
    DFS(v, u);
  }
  R[u] = tim;
}
void build1(int l, int r, int rt) {
  mk1[rt] = 0;
  if (l == r) return;
  int m = l + r >> 1;
  build1(l, m, rt << 1);
  build1(m + 1, r, rt << 1 | 1);
}
void update1(int pos, int a, int l, int r, int rt) {
  if (l == r) {
    mk1[rt] = a;
    return;
  }
  int m = l + r >> 1;
  if (pos <= m)
    update1(pos, a, l, m, rt << 1);
  else
    update1(pos, a, m + 1, r, rt << 1 | 1);
  mk1[rt] = max(mk1[rt << 1], mk1[rt << 1 | 1]);
}
int query1(int L, int R, int l, int r, int rt) {
  if (L <= l && R >= r) return mk1[rt];
  int m = l + r >> 1;
  if (L <= m && R > m)
    return max(query1(L, R, l, m, rt << 1),
               query1(L, R, m + 1, r, rt << 1 | 1));
  if (L <= m) return query1(L, R, l, m, rt << 1);
  if (R > m) return query1(L, R, m + 1, r, rt << 1 | 1);
}
int dfn[N], Rank[N], deep[N], fa[N], top[N], son[N], sz[N];
int mk2[N << 2];
void build2(int l, int r, int rt) {
  mk2[rt] = 0;
  if (l == r) return;
  int m = l + r >> 1;
  build2(l, m, rt << 1);
  build2(m + 1, r, rt << 1 | 1);
}
void DFS1(int u) {
  sz[u] = 1;
  son[u] = -1;
  for (int i = first[u]; i != -1; i = Next[i]) {
    int v = V[i];
    if (v == fa[u]) continue;
    deep[v] = deep[u] + 1;
    fa[v] = u;
    DFS1(v);
    sz[u] += sz[v];
    if (son[u] == -1 || sz[son[u]] < sz[v]) son[u] = v;
  }
}
void DFS2(int u, int tp) {
  top[u] = tp;
  dfn[u] = ++tim;
  Rank[tim] = u;
  if (son[u] == -1) return;
  DFS2(son[u], tp);
  for (int i = first[u]; i != -1; i = Next[i]) {
    int v = V[i];
    if (v != fa[u] && v != son[u]) DFS2(v, v);
  }
}
void buildtree() {
  tim = 0;
  deep[1] = 0;
  fa[1] = 1;
  DFS1(1);
  DFS2(1, 1);
  build2(1, n, 1);
}
void update2(int pos, int a, int l, int r, int rt) {
  if (l == r) {
    mk2[rt] = a;
    return;
  }
  int m = l + r >> 1;
  if (pos <= m)
    update2(pos, a, l, m, rt << 1);
  else
    update2(pos, a, m + 1, r, rt << 1 | 1);
  mk2[rt] = max(mk2[rt << 1], mk2[rt << 1 | 1]);
}
int query2(int L, int R, int l, int r, int rt) {
  if (L <= l && R >= r) return mk2[rt];
  int m = l + r >> 1;
  if (L <= m && R > m)
    return max(query2(L, R, l, m, rt << 1),
               query2(L, R, m + 1, r, rt << 1 | 1));
  if (L <= m) return query2(L, R, l, m, rt << 1);
  if (R > m) return query2(L, R, m + 1, r, rt << 1 | 1);
}
int Query(int u, int v) {
  int mx = -1;
  while (top[u] != top[v]) {
    if (deep[top[u]] < deep[top[v]]) swap(u, v);
    mx = max(mx, query2(dfn[top[u]], dfn[u], 1, n, 1));
    u = fa[top[u]];
  }
  if (deep[u] > deep[v]) swap(u, v);
  mx = max(mx, query2(dfn[u], dfn[v], 1, n, 1));
  return mx;
}
int main() {
  int i, j, k, m;
  int a, b;
  while (scanf("%d", &n) == 1) {
    for (i = 1; i <= n; i++) first[i] = -1;
    int p = 0;
    for (i = 1; i < n; i++) {
      scanf("%d %d", &a, &b);
      V[++p] = b, Next[p] = first[a], first[a] = p;
      V[++p] = a, Next[p] = first[b], first[b] = p;
    }
    tim = 0;
    DFS(1, 1);
    build1(1, n, 1);
    buildtree();
    scanf("%d", &m);
    for (i = 1; i <= m; i++) {
      scanf("%d %d", &a, &b);
      if (a == 1)
        update2(dfn[b], i, 1, n, 1);
      else if (a == 2)
        update1(L[b], i, 1, n, 1);
      else {
        a = query1(L[b], R[b], 1, n, 1);
        b = Query(1, b);
        if (a >= b)
          puts("0");
        else
          puts("1");
      }
    }
  }
  return 0;
}
