#include <bits/stdc++.h>
using namespace std;
const int MAX = 500100;
int n, q;
vector<vector<int> > g;
int m = 0;
int pos[MAX];
int last[MAX];
int st[MAX * 4], lz[MAX * 4];
int par[MAX];
void dfs(int u, int p = -1) {
  pos[u] = m++;
  par[u] = p;
  for (int i = 0; i < (int)g[u].size(); i++) {
    int v = g[u][i];
    if (v != p) {
      dfs(v, u);
    }
  }
  last[u] = m - 1;
}
void update(int node, int second, int e, int i, int j, int val) {
  if (lz[node] != -1) {
    st[node] = lz[node] * (e - second + 1);
    if (second != e) {
      lz[2 * node + 1] = lz[2 * node + 2] = lz[node];
    }
    lz[node] = -1;
  }
  if (second > j || e < i) return;
  if (second >= i && e <= j) {
    st[node] = val * (e - second + 1);
    if (e != second) {
      lz[2 * node + 1] = lz[2 * node + 2] = val;
    }
    return;
  }
  update(2 * node + 1, second, (second + e) / 2, i, j, val);
  update(2 * node + 2, (second + e) / 2 + 1, e, i, j, val);
  st[node] = st[2 * node + 1] + st[2 * node + 2];
}
int query(int node, int second, int e, int i, int j) {
  if (lz[node] != -1) {
    st[node] = lz[node] * (e - second + 1);
    if (second != e) {
      lz[2 * node + 1] = lz[2 * node + 2] = lz[node];
    }
    lz[node] = -1;
  }
  if (second > j || e < i) return 0;
  if (second >= i && e <= j) return st[node];
  return query(2 * node + 1, second, (second + e) / 2, i, j) +
         query(2 * node + 2, (second + e) / 2 + 1, e, i, j);
}
int main() {
  scanf("%d", &n);
  g.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    --u, --v;
    g[u].push_back(v);
    swap(u, v);
    g[u].push_back(v);
  }
  dfs(0);
  memset(st, 0, sizeof st);
  memset(lz, -1, sizeof lz);
  scanf("%d", &q);
  while (q--) {
    int t, u;
    scanf("%d%d", &t, &u);
    --u;
    if (t == 1) {
      if (query(0, 0, n - 1, pos[u], last[u]) < last[u] - pos[u] + 1 &&
          par[u] != -1)
        update(0, 0, n - 1, pos[par[u]], pos[par[u]], 0);
      update(0, 0, n - 1, pos[u], last[u], 1);
    } else if (t == 2) {
      update(0, 0, n - 1, pos[u], pos[u], 0);
    } else {
      if (query(0, 0, n - 1, pos[u], last[u]) < last[u] - pos[u] + 1)
        printf("0\n");
      else
        printf("1\n");
    }
  }
  return 0;
}
