#include <bits/stdc++.h>
using namespace std;
int n, q;
vector<int> e[501000];
int p[501000];
int in[501000], out[501000];
int timer;
set<int> t;
set<int>::iterator it;
void dfs(int v, int pr = -1) {
  p[v] = (pr == -1 ? pr : in[pr]);
  in[v] = timer++;
  for (int i = 0; i < (int)e[v].size(); ++i) {
    if (e[v][i] != pr) {
      dfs(e[v][i], v);
    }
  }
  out[v] = timer;
  if (out[v] - in[v] <= 1) {
    t.insert(in[v]);
  }
}
int main() {
  scanf("%d", &n);
  for (int a, b, i = 1; i < n; ++i) {
    scanf("%d%d", &a, &b);
    e[a - 1].push_back(b - 1);
    e[b - 1].push_back(a - 1);
  }
  dfs(0);
  scanf("%d", &q);
  for (int c, v, i = 0; i < q; ++i) {
    scanf("%d%d", &c, &v);
    --v;
    if (c == 1) {
      it = t.lower_bound(in[v]);
      bool ins = false;
      while (it != t.end() && *it < out[v]) {
        t.erase(it);
        it = t.lower_bound(in[v]);
        ins = true;
      }
      if (p[v] != -1 && ins) {
        t.insert(p[v]);
      }
    } else if (c == 2) {
      t.insert(in[v]);
    } else {
      it = t.lower_bound(in[v]);
      printf("%d\n", it == t.end() || *it >= out[v]);
    }
  }
  return 0;
}
