#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
inline long long input() {
  long long n;
  cin >> n;
  return n;
}
long long poww(long long a, long long b, long long md) {
  return (!b ? 1
             : (b & 1 ? a * poww(a * a % md, b / 2, md) % md
                      : poww(a * a % md, b / 2, md) % md));
}
const int MAXN = 5e5 + 10;
const int MAXLG = 18;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const long long INF = 8e18;
vector<int> adj[MAXN];
int n, q;
int id[MAXN], e[MAXN], par[MAXN];
int cnt;
set<int> st;
void dfs(int v) {
  e[v] = cnt;
  id[v] = cnt++;
  for (auto u : adj[v]) {
    if (u == par[v]) {
      continue;
    }
    par[u] = v;
    dfs(u);
    e[v] = e[u];
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  par[0] = -1;
  dfs(0);
  for (int i = 0; i < n; i++) {
    st.insert(i);
  }
  cin >> q;
  while (q--) {
    int type;
    cin >> type;
    if (type == 2) {
      int v;
      cin >> v;
      v--;
      st.insert(id[v]);
      continue;
    }
    if (type == 1) {
      int v;
      cin >> v;
      v--;
      bool flag = false;
      auto it = st.lower_bound(id[v]);
      while (true) {
        if (it == st.end() || *it > e[v]) {
          break;
        }
        st.erase(it++);
        flag = true;
      }
      if (flag && par[v] != -1) {
        st.insert(id[par[v]]);
      }
      continue;
    }
    if (type == 3) {
      int v;
      cin >> v;
      v--;
      auto it = st.lower_bound(id[v]);
      if (it == st.end() || *it > e[v]) {
        cout << 1 << "\n";
      } else {
        cout << 0 << "\n";
      }
    }
  }
}
