#include <bits/stdc++.h>
using namespace std;
int solve(int);
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T, i;
  T = 1;
  for (i = 1; i <= T; ++i) {
    int x = solve(i);
  }
  return 0;
}
int n, m;
const int N = 5e5 + 5;
const int md = 1e9 + 7;
vector<int> a[N];
int L[N], R[N], level[N], num[N], rnum[N], fa[N];
int cnt = 0;
int dfs(int x, int pre, int lv) {
  int m = a[x].size(), i;
  num[x] = ++cnt;
  rnum[cnt] = x;
  L[cnt] = R[cnt] = cnt;
  level[cnt] = lv;
  for (i = 0; i <= m - 1; ++i) {
    if (a[x][i] == pre) continue;
    R[num[x]] = dfs(a[x][i], x, lv + 1);
  }
  fa[num[x]] = pre == -1 ? -1 : num[pre];
  return R[num[x]];
}
struct Tree {
  int v;
} tree[4 * N];
inline void update(int n, int a, int b) { tree[n].v = tree[a].v && tree[b].v; }
inline void down(int n, int n1, int n2) {
  if (tree[n].v) tree[n1].v = tree[n2].v = 1;
}
void build(int n, int l, int r) {
  if (l == r) {
    tree[n].v = 0;
    return;
  }
  int mid = (l + r) >> 1, n1 = n << 1, n2 = (n << 1) + 1;
  build(n1, l, mid);
  build(n2, mid + 1, r);
  update(n, n1, n2);
}
void update(int n, int l, int r, int x, int y) {
  if (x <= l && y >= r) {
    tree[n].v = 1;
    return;
  }
  int mid = (l + r) >> 1;
  int n1 = n << 1, n2 = (n << 1) | 1;
  down(n, n1, n2);
  if (x <= mid) update(n1, l, mid, x, y);
  if (y > mid) update(n2, mid + 1, r, x, y);
  update(n, n1, n2);
}
int query(int n, int l, int r, int x, int y) {
  if (x <= l && y >= r) {
    return tree[n].v;
  }
  int mid = (l + r) >> 1;
  int n1 = n << 1, n2 = (n << 1) | 1;
  int p1, p2;
  p1 = p2 = 1;
  down(n, n1, n2);
  if (x <= mid) p1 = query(n1, l, mid, x, y);
  if (y > mid) p2 = query(n2, mid + 1, r, x, y);
  return p1 && p2;
}
void update(int n, int l, int r, int x) {
  if (l == r && l == x) {
    tree[n].v = 0;
    return;
  }
  int mid = (l + r) >> 1;
  int n1 = n << 1, n2 = (n << 1) | 1;
  down(n, n1, n2);
  if (x <= mid)
    update(n1, l, mid, x);
  else
    update(n2, mid + 1, r, x);
  update(n, n1, n2);
}
void print_tree(int n) {
  int i, j;
  int num = 1;
  for (i = 0; int(pow(2, i - 1)) <= n; ++i) {
    for (j = 1; j <= int(pow(2, i)); ++j) cout << tree[num++].v << ' ';
    cout << '\n';
  }
  cout << '\n';
}
int solve(int T) {
  int i, j;
  cin >> n;
  for (i = 1; i <= n - 1; ++i) {
    int x, y;
    cin >> x >> y;
    a[x].push_back(y);
    a[y].push_back(x);
  }
  int root = 1;
  dfs(root, -1, 1);
  build(1, 1, n);
  int Q;
  cin >> Q;
  while (Q--) {
    int flag, v;
    cin >> flag >> v;
    int p = num[v];
    if (flag == 1) {
      int x = query(1, 1, n, L[p], R[p]);
      update(1, 1, n, L[p], R[p]);
      if (x == 0 && fa[p] != -1) update(1, 1, n, fa[p]);
    } else if (flag == 2) {
      update(1, 1, n, p);
      if (fa[p] != -1) update(1, 1, n, fa[p]);
    } else {
      int ans = query(1, 1, n, L[p], R[p]);
      cout << ans << '\n';
    }
  }
  return 0;
}
