#include <bits/stdc++.h>
using namespace std;
const int maxn = 500005;
int n, q, tim;
int fll[maxn * 10], tag[maxn * 10], empty[maxn * 10], in[maxn], out[maxn],
    leaf[maxn * 4];
vector<int> edge[maxn];
void dfs(int x, int par) {
  tim++;
  in[x] = tim;
  for (int(i) = 0; (i) < edge[x].size(); i++) {
    int y = edge[x][i];
    if (y != par) dfs(y, x);
  }
  tim++;
  out[x] = tim;
}
void get_leaf(int l, int r, int node) {
  if (l == r) {
    leaf[l] = node;
    return;
  }
  int mid = (l + r) >> 1;
  get_leaf(l, mid, node * 2);
  get_leaf(mid + 1, r, node * 2 + 1);
}
void Push(int tree[], int node, bool type) {
  if (!type) return;
  if (tag[node]) {
    tree[node] = tree[node * 2] = tree[node * 2 + 1] = tag[node];
    tag[node * 2] = tag[node * 2 + 1] = tag[node];
    tag[node] = 0;
  }
}
void modify(int tree[], int l, int r, int vl, int vr, int node, int val) {
  if (l > vr || r < vl) return;
  if (l >= vl && r <= vr) {
    tag[node] = val;
    Push(tree, node, true);
    return;
  }
  int mid = (l + r) >> 1;
  Push(tree, node, true);
  modify(tree, l, mid, vl, vr, node * 2, val);
  modify(tree, mid + 1, r, vl, vr, node * 2 + 1, val);
  tree[node] = max(tree[node * 2], tree[node * 2 + 1]);
}
void update(int tree[], int pos, int val) {
  pos = leaf[pos];
  tree[pos] = val;
  while (pos) {
    pos >>= 1;
    tree[pos] = max(tree[pos * 2], tree[pos * 2 + 1]);
  }
}
int query(int tree[], int l, int r, int vl, int vr, int node, bool type) {
  if (l > vr || r < vl) return 0;
  if (l >= vl && r <= vr) return tree[node];
  Push(tree, node, type);
  int mid = (l + r) >> 1;
  return max(query(tree, l, mid, vl, vr, node * 2, type),
             query(tree, mid + 1, r, vl, vr, node * 2 + 1, type));
}
int main() {
  scanf("%d", &n);
  for (int(i) = 0; (i) < n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  dfs(1, -1);
  get_leaf(1, 2 * n, 1);
  scanf("%d", &q);
  for (int(i) = 1; (i) <= q; i++) {
    int type, x;
    scanf("%d%d", &type, &x);
    if (type == 1) {
      modify(fll, 1, n * 2, in[x], out[x], 1, i);
    } else if (type == 2) {
      update(empty, in[x], i);
    } else {
      int Empty = query(empty, 1, n * 2, in[x], out[x], 1, false);
      int Fll = query(fll, 1, n * 2, in[x], in[x], 1, true);
      if (Empty >= Fll)
        puts("0");
      else
        puts("1");
    }
  }
  return 0;
}
