#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 20;
const int M = 2e6 + 20;
const long long mod = 998244353;
const int inf = 1e9;
const long long INF = 1e16;
void data() {}
template <typename T>
void scerr(T nums) {
  for (auto it : nums) cerr << it << " | ";
  cerr << "\n";
}
int n, q, t[M], p[M], sz[N], cnt, posl[N], posr[N], anc[N];
vector<int> g[N];
void dfs(int v = 1, int p = -1) {
  sz[v] = 1;
  posl[v] = ++cnt;
  anc[v] = p;
  for (auto to : g[v]) {
    if (to == p) continue;
    dfs(to, v);
    sz[v] += sz[to];
  }
  posr[v] = cnt;
}
void push(int v, int tl, int tr) {
  if (p[v] != -1) {
    int tm = (tl + tr) / 2;
    t[v] = (tr - tl + 1) * p[v];
    if (tl != tr) {
      p[v * 2] = p[v * 2 + 1] = p[v];
      t[v * 2] = (tm - tl + 1) * p[v];
      t[v * 2 + 1] = (tr - tm) * p[v];
    }
    p[v] = -1;
  }
}
void upd(int l, int r, int val, int v = 1, int tl = 1, int tr = n) {
  push(v, tl, tr);
  if (r < tl || tr < l) return;
  if (l <= tl && tr <= r) {
    p[v] = val;
    push(v, tl, tr);
    return;
  }
  int tm = (tl + tr) / 2;
  upd(l, r, val, v * 2, tl, tm);
  upd(l, r, val, v * 2 + 1, tm + 1, tr);
  t[v] = t[v * 2] + t[v * 2 + 1];
}
int get_sum(int l, int r, int v = 1, int tl = 1, int tr = n) {
  push(v, tl, tr);
  if (r < tl || tr < l) return 0;
  if (l <= tl && tr <= r) return t[v];
  int tm = (tl + tr) / 2;
  return get_sum(l, r, v * 2, tl, tm) + get_sum(l, r, v * 2 + 1, tm + 1, tr);
}
int main() {
  data();
  scanf("%d", &n);
  for (int i = 0; i < M; ++i) p[i] = -1;
  for (int i = 1, u, v; i < n; ++i) {
    scanf("%d %d", &u, &v);
    g[v].push_back(u);
    g[u].push_back(v);
  }
  dfs();
  scanf("%d", &q);
  while (q--) {
    int tp, v;
    scanf("%d %d", &tp, &v);
    if (tp == 1) {
      if (get_sum(posl[v], posr[v]) != sz[v] && anc[v] != -1)
        upd(posl[anc[v]], posl[anc[v]], 0);
      upd(posl[v], posr[v], 1);
    }
    if (tp == 2) {
      upd(posl[v], posl[v], 0);
    }
    if (tp == 3) {
      if (get_sum(posl[v], posr[v]) == sz[v])
        printf("1\n");
      else
        printf("0\n");
    }
  }
}
