#include <bits/stdc++.h>
using namespace std;
long long t, n, c, q, res, new_pos, f, w, par[500010], lz[2000010],
    node_head[500010], tree[2000010], indx[500010], stsz[500010], sc[500010],
    disc[500010], fin[500010];
vector<long long> adj[500010];
void lazy(long long l, long long r, long long pos) {
  if (lz[pos] != -1) {
    tree[pos] = lz[pos];
    if (l != r) {
      lz[2 * pos] = lz[pos];
      lz[2 * pos + 1] = lz[pos];
    }
    lz[pos] = -1;
  }
}
void update(long long l, long long r, long long pos, long long L, long long R,
            long long val) {
  lazy(l, r, pos);
  if (l > R || r < L) {
    return;
  }
  if (l >= L && r <= R) {
    tree[pos] = val;
    if (l != r) {
      lz[2 * pos] = val;
      lz[2 * pos + 1] = val;
    }
    return;
  }
  long long mid = (l + r) / 2;
  update(l, mid, 2 * pos, L, R, val);
  update(mid + 1, r, 2 * pos + 1, L, R, val);
  tree[pos] = tree[2 * pos] + tree[2 * pos + 1];
}
long long query(long long l, long long r, long long pos, long long in) {
  lazy(l, r, pos);
  if (l > in || r < in) return 0;
  if (l == in && r == in) return tree[pos];
  long long mid = (l + r) / 2;
  return query(l, mid, 2 * pos, in) + query(mid + 1, r, 2 * pos + 1, in);
}
long long tym;
long long dfs(long long now, long long pre) {
  long long cnt = 1, sz = adj[now].size(), mx = 0, special = 0;
  par[now] = pre;
  for (int i = 0; i < sz; i++) {
    long long node = adj[now][i];
    if (node != pre) {
      cnt += dfs(node, now);
      if (stsz[node] > mx) {
        mx = stsz[node];
        special = node;
      }
    }
  }
  sc[now] = special;
  return stsz[now] = cnt;
}
void HLD(long long pre, long long now, long long head) {
  node_head[now] = head;
  indx[now] = ++new_pos;
  disc[now] = ++tym;
  if (sc[now] != 0) HLD(now, sc[now], head);
  long long sz = adj[now].size();
  for (int i = 0; i < sz; i++) {
    long long node = adj[now][i];
    if (node != sc[now] && node != pre) {
      HLD(now, node, node);
    }
  }
  fin[now] = tym;
}
void go_up(long long u) {
  if (node_head[u] == 1) {
    update(1, n, 1, 1, indx[u], 0);
    return;
  }
  update(1, n, 1, indx[node_head[u]], indx[u], 0);
  update(1, n, 1, indx[par[node_head[u]]], indx[par[node_head[u]]], 0);
  go_up(par[node_head[u]]);
}
int main() {
  memset(lz, -1, sizeof lz);
  long long u, v;
  scanf("%lld", &n);
  for (int i = 0; i < n - 1; i++) {
    scanf("%lld%lld", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1, 1);
  HLD(1, 1, 1);
  scanf("%lld", &q);
  while (q--) {
    scanf("%lld%lld", &f, &u);
    if (f == 1) {
      update(1, n, 1, disc[u], fin[u], 1);
    } else if (f == 2) {
      go_up(u);
    } else {
      printf("%lld\n", query(1, n, 1, indx[u]));
    }
  }
  return 0;
}
