#include <bits/stdc++.h>
using namespace std;
vector<int> v[500010];
int Time = 0, inTime[500010], outTime[500010], parent[500010];
set<int> st;
void dfs(int node, int _parent) {
  inTime[node] = ++Time;
  parent[node] = _parent;
  int counts = 0;
  for (auto child : v[node]) {
    if (child != _parent) {
      counts++;
      dfs(child, node);
    }
  }
  if (counts == 0) st.insert(Time);
  outTime[node] = ++Time;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  dfs(1, 0);
  int q;
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    if (a == 1) {
      if (parent[b] != 0) {
        auto it = st.lower_bound(inTime[parent[b]]);
        if (it != st.end() && (*it) <= outTime[parent[b]]) {
          st.insert(inTime[parent[b]]);
        }
      }
      st.erase(st.lower_bound(inTime[b]), st.upper_bound(outTime[b]));
    } else if (a == 2) {
      st.insert(inTime[b]);
    } else {
      auto it = st.lower_bound(inTime[b]);
      if (it != st.end() && (*it) <= outTime[b]) {
        cout << 0 << endl;
      } else {
        cout << 1 << endl;
      }
    }
  }
  return 0;
}
