#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int n, m;
int e, beg[N], to[N << 1], ne[N << 1];
inline void add(int u, int v) {
  to[++e] = v;
  ne[e] = beg[u];
  beg[u] = e;
}
int sta[N << 2];
inline void push_down(int l, int r, int root) {
  sta[(root << 1)] = sta[(root << 1 | 1)] = sta[root];
  sta[root] = -1;
}
void update(int a, int b, int l, int r, int root, int k) {
  if (a <= l && r <= b) {
    sta[root] = k;
    return;
  }
  if (sta[root] != -1) push_down(l, r, root);
  if (a <= ((r + l) >> 1)) update(a, b, l, ((r + l) >> 1), (root << 1), k);
  if (b > ((r + l) >> 1))
    update(a, b, ((r + l) >> 1) + 1, r, (root << 1 | 1), k);
}
int query(int x, int l, int r, int root) {
  if (sta[root] != -1) return sta[root];
  if (x <= ((r + l) >> 1))
    return query(x, l, ((r + l) >> 1), (root << 1));
  else
    return query(x, ((r + l) >> 1) + 1, r, (root << 1 | 1));
}
int deep[N], siz[N], son[N], fa[N], top[N];
int cnt, id[N];
void dfs1(int x) {
  siz[x] = 1, deep[x] = deep[fa[x]] + 1;
  for (int i = beg[x]; i; i = ne[i]) {
    if (to[i] == fa[x]) continue;
    fa[to[i]] = x;
    dfs1(to[i]);
    siz[x] += siz[to[i]];
    if (siz[son[x]] < siz[to[i]]) son[x] = to[i];
  }
}
void dfs2(int x, int topp) {
  id[x] = ++cnt;
  top[x] = topp;
  if (son[x]) dfs2(son[x], topp);
  for (int i = beg[x]; i; i = ne[i])
    if (to[i] != fa[x] && to[i] != son[x]) dfs2(to[i], to[i]);
}
int qPoint(int x) { return query(id[x], 1, n, 1); }
void upRange(int x, int y, int k) {
  while (top[x] != top[y]) {
    if (deep[top[x]] < deep[top[y]]) swap(x, y);
    update(id[top[x]], id[x], 1, n, 1, k);
    x = fa[top[x]];
  }
  if (deep[x] < deep[y]) swap(x, y);
  update(id[y], id[x], 1, n, 1, k);
}
inline void upSon(int x, int k) {
  update(id[x], id[x] + siz[x] - 1, 1, n, 1, k);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int u, v;
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    add(u, v);
    add(v, u);
  }
  int r = 1;
  dfs1(r);
  dfs2(r, r);
  int m, a, b;
  cin >> m;
  while (m--) {
    cin >> a >> b;
    switch (a) {
      case 1:
        upSon(b, 1);
        break;
      case 2:
        upRange(b, r, 0);
        break;
      case 3:
        cout << qPoint(b) << endl;
        break;
    }
  }
}
