#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 20;
vector<int> adj[N];
int tIn[N], tOut[N], T, n, lazy[4 * N], parent[N];
bool seg[4 * N];
void dfs(int u, int par) {
  tIn[u] = T++;
  parent[u] = par;
  for (int i = 0; i < (int)adj[u].size(); i++)
    if (adj[u][i] != par) dfs(adj[u][i], u);
  tOut[u] = T - 1;
}
void apply(int idx) {
  if (lazy[idx] == -1) return;
  seg[idx * 2 + 1] = seg[idx * 2] = lazy[idx];
  lazy[idx * 2] = lazy[idx * 2 + 1] = lazy[idx];
  lazy[idx] = -1;
}
void fill(int l, int r, int idx, int ql, int qr, bool sign) {
  if (ql <= l && r <= qr) {
    lazy[idx] = sign;
    seg[idx] = sign;
    return;
  }
  if (r < ql || qr < l) return;
  apply(idx);
  int mid = (l + r) / 2;
  fill(l, mid, idx * 2, ql, qr, sign);
  fill(mid + 1, r, idx * 2 + 1, ql, qr, sign);
  seg[idx] = seg[idx * 2] & seg[idx * 2 + 1];
}
bool isFull(int l, int r, int idx, int ql, int qr) {
  if (ql <= l && r <= qr) return seg[idx];
  if (r < ql || qr < l) return 1;
  apply(idx);
  int mid = (l + r) / 2;
  return isFull(l, mid, idx * 2, ql, qr) &
         isFull(mid + 1, r, idx * 2 + 1, ql, qr);
}
int main() {
  int temp, q;
  cin >> n;
  temp = n - 1;
  while (temp--) {
    int a, b;
    scanf("%d%d", &a, &b);
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  dfs(1, 0);
  memset(lazy, -1, sizeof lazy);
  cin >> q;
  while (q--) {
    int t, v;
    scanf("%d%d", &t, &v);
    if (t == 1) {
      if (parent[v] && !isFull(0, n - 1, 1, tIn[v], tOut[v]))
        fill(0, n - 1, 1, tIn[parent[v]], tIn[parent[v]], 0);
      fill(0, n - 1, 1, tIn[v], tOut[v], 1);
    } else if (t == 2) {
      fill(0, n - 1, 1, tIn[v], tIn[v], 0);
    } else {
      printf("%d\n", isFull(0, n - 1, 1, tIn[v], tOut[v]));
    }
  }
  return 0;
}
