#include <bits/stdc++.h>
using namespace std;
const int N = int(6e5);
int x, y, n;
int q, v, c, t;
int l[N], r[N], to, pred[N];
vector<int> g[N];
bool used[N];
set<int> st;
inline void dfs(int v) {
  used[v] = 1;
  l[v] = t++;
  bool first = 1;
  pred[v] = -1;
  for (int i = g[v].size() - 1; i >= 0; i--) {
    to = g[v][i];
    if (!used[to]) {
      first = 0;
      dfs(to);
    } else {
      pred[v] = to;
    }
  }
  r[v] = t;
  if (first) {
    st.insert(l[v]);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n - 1; i++) {
    scanf("%d%d", &x, &y);
    x--, y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  t = 0;
  dfs(0);
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d%d", &c, &v);
    v--;
    if (c == 1) {
      vector<int> vv;
      for (set<int>::iterator it = st.lower_bound(l[v]);
           it != st.end() && *it < r[v]; it++) {
        vv.push_back(*it);
      }
      for (int j = 0; j < vv.size(); j++) {
        st.erase(vv[j]);
      }
      if (vv.size() > 0 && pred[v] != -1) {
        st.insert(l[pred[v]]);
      }
    }
    if (c == 2) {
      st.insert(l[v]);
    }
    if (c == 3) {
      set<int>::iterator it = st.lower_bound(l[v]);
      if (it == st.end() || *it >= r[v])
        puts("1");
      else
        puts("0");
    }
  }
  return 0;
}
