#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
struct Segtree {
  struct Node {
    int cmax, tag;
  } t[N << 2];
  void Addtag(int now, int key) {
    t[now].cmax = max(t[now].cmax, key);
    t[now].tag = max(t[now].tag, key);
  }
  void pushdown(int now) {
    if (!t[now].tag) return;
    Addtag((now << 1), t[now].tag);
    Addtag((now << 1 | 1), t[now].tag);
    t[now].tag = 0;
  }
  void Modify(int now, int x, int y, int key, int l, int r) {
    if (x <= l && r <= y) return Addtag(now, key);
    pushdown(now);
    int mid = (l + r) >> 1;
    if (x <= mid) Modify((now << 1), x, y, key, l, mid);
    if (y >= mid + 1) Modify((now << 1 | 1), x, y, key, mid + 1, r);
    t[now].cmax = max(t[(now << 1)].cmax, t[(now << 1 | 1)].cmax);
  }
  int query(int now, int x, int y, int l, int r) {
    if (x <= l && r <= y) return t[now].cmax;
    pushdown(now);
    int mid = (l + r) >> 1, res = 0;
    if (x <= mid) res = max(res, query((now << 1), x, y, l, mid));
    if (y >= mid + 1) res = max(res, query((now << 1 | 1), x, y, mid + 1, r));
    return res;
  }
} t0, t1;
int one[N], idx;
int Next[N], ver[N];
inline void AddEdge(int a, int b) {
  Next[idx] = one[a];
  ver[idx] = b;
  one[a] = idx++;
  Next[idx] = one[b];
  ver[idx] = a;
  one[b] = idx++;
}
int n, m;
int dfn[N], siz[N], times;
void dfs(int x, int fa) {
  dfn[x] = ++times;
  siz[x] = 1;
  for (int i = one[x], y; ~i; i = Next[i]) {
    if ((y = ver[i]) == fa) continue;
    dfs(y, x);
    siz[x] += siz[y];
  }
}
int main() {
  int i;
  int opt, x, y, z;
  scanf("%d", &n);
  memset(one, -1, sizeof one);
  for (i = 1; i <= n - 1; i++) {
    scanf("%d%d", &x, &y);
    AddEdge(x, y);
  }
  dfs(1, 0);
  scanf("%d", &m);
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &opt, &x);
    if (opt == 1)
      t1.Modify(1, dfn[x], dfn[x] + siz[x] - 1, i, 1, n);
    else if (opt == 2)
      t0.Modify(1, dfn[x], dfn[x], i, 1, n);
    else {
      y = t0.query(1, dfn[x], dfn[x] + siz[x] - 1, 1, n);
      z = t1.query(1, dfn[x], dfn[x], 1, n);
      printf("%d\n", (y < z));
    }
  }
  return 0;
}
