#include <bits/stdc++.h>
using namespace std;
const int N = 1000100;
int n, q, s[N / 2], f[N / 2], par[N / 2], timer;
vector<int> g[N / 2];
void dfs(int x = 1, int pp = 0) {
  s[x] = ++timer;
  par[x] = pp;
  for (auto &it : g[x])
    if (it != par[x]) {
      dfs(it, x);
    }
  f[x] = ++timer;
}
struct node {
  int sum;
  bool set;
  void merge(node &lt, node &rt) { sum = lt.sum + rt.sum; }
} st[N << 2];
void push(int x, int lx, int rx) {
  if (st[x].set) {
    st[x].set = 0;
    st[x].sum = rx - lx + 1;
    if (lx == rx) return;
    st[x << 1].set = st[x << 1 | 1].set = 1;
  }
}
void bld(int x = 1, int lx = 1, int rx = n + n) {
  if (lx == rx) {
    st[x] = {0, 0};
    return;
  }
  int mid = lx + rx >> 1;
  bld(x << 1, lx, mid);
  bld(x << 1 | 1, mid + 1, rx);
  st[x].merge(st[x << 1], st[x << 1 | 1]);
}
void modify(bool z, int &u, int &v, int x = 1, int lx = 1, int rx = n + n) {
  push(x, lx, rx);
  if (v < lx or u > rx) return;
  if (u <= lx and rx <= v) {
    if (z) {
      st[x].set = 1;
      push(x, lx, rx);
    } else {
      st[x].sum = 0;
    }
    return;
  }
  int mid = lx + rx >> 1;
  modify(z, u, v, x << 1, lx, mid);
  modify(z, u, v, x << 1 | 1, mid + 1, rx);
  st[x].merge(st[x << 1], st[x << 1 | 1]);
}
int qry(int &u, int &v, int x = 1, int lx = 1, int rx = n + n) {
  push(x, lx, rx);
  if (v < lx or u > rx) return 0;
  if (u <= lx and rx <= v) return st[x].sum;
  int mid = lx + rx >> 1;
  return qry(u, v, x << 1, lx, mid) + qry(u, v, x << 1 | 1, mid + 1, rx);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int u, v, i = 1; i < n; i++) {
    cin >> u >> v;
    g[u].emplace_back(v);
    g[v].emplace_back(u);
  }
  timer = 0;
  dfs();
  bld();
  cin >> q;
  int ty, v;
  while (q--) {
    cin >> ty >> v;
    if (ty == 1) {
      if (par[v] != 0 and qry(s[v], f[v]) != f[v] - s[v] + 1) {
        modify(0, s[par[v]], s[par[v]]);
      }
      modify(1, s[v], f[v]);
    } else if (ty == 2) {
      modify(0, s[v], s[v]);
    } else {
      cout << (qry(s[v], f[v]) == f[v] - s[v] + 1) << '\n';
    }
  }
  return 0;
}
