#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
const int maxn = 5e5 + 10;
vector<int> adj[maxn];
bool vis[maxn];
int seg1[4 * maxn], seg2[4 * maxn], st[maxn], ft[maxn], timex = 0;
inline void dfs(int x) {
  timex++;
  vis[x] = 1;
  st[x] = timex;
  for (int i : adj[x]) {
    if (!vis[i]) {
      dfs(i);
    }
  }
  ft[x] = timex;
}
inline void add1(int id, int l, int r, int L, int R, int ok) {
  if (R <= l || L >= r) {
    return;
  }
  if (L <= l && R >= r) {
    seg1[id] = ok;
    return;
  }
  int mid = (l + r) / 2;
  add1(id * 2, l, mid, L, R, ok);
  add1(id * 2 + 1, mid, r, L, R, ok);
}
inline void add2(int id, int l, int r, int idx, int ok) {
  if (idx < l || idx >= r) {
    return;
  }
  if (l + 1 == r) {
    seg2[id] = ok;
    return;
  }
  int mid = (l + r) / 2;
  add2(id * 2, l, mid, idx, ok);
  add2(id * 2 + 1, mid, r, idx, ok);
  seg2[id] = ok;
}
inline int get1(int id, int l, int r, int idx) {
  if (idx < l || idx >= r) {
    return 0;
  }
  if (l + 1 == r) {
    return seg1[id];
  }
  int mid = (l + r) / 2;
  return max(seg1[id],
             max(get1(id * 2, l, mid, idx), get1(id * 2 + 1, mid, r, idx)));
}
inline int get2(int id, int l, int r, int L, int R) {
  if (R <= l || L >= r) {
    return 0;
  }
  if (L <= l && R >= r) {
    return seg2[id];
  }
  int mid = (l + r) / 2;
  return max(get2(id * 2, l, mid, L, R), get2(id * 2 + 1, mid, r, L, R));
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int v, u;
    cin >> v >> u;
    adj[v].push_back(u);
    adj[u].push_back(v);
  }
  dfs(1);
  n++;
  for (int i = 0; i < 4 * (5e5 + 10); i++) {
    seg2[i] = 1;
  }
  int q;
  cin >> q;
  for (int i = 2; i <= q + 1; i++) {
    int boi, v;
    cin >> boi >> v;
    if (boi == 1) {
      add1(1, 0, n, st[v], ft[v] + 1, i);
    }
    if (boi == 2) {
      add2(1, 0, n, st[v], i);
    }
    if (boi == 3) {
      cout << (get1(1, 0, n, st[v]) > get2(1, 0, n, st[v], ft[v] + 1)) << endl;
    }
  }
}
