#include <bits/stdc++.h>
using namespace std;
vector<long long> edge[500005];
long long tin[500005], tout[500005], tot = 0;
struct ppp {
  long long l, r, v, tag, sum;
} tree[2000005];
void dfs(long long u, long long fa) {
  tin[u] = ++tot;
  for (auto v : edge[u]) {
    if (v == fa) continue;
    dfs(v, u);
  }
  tout[u] = tot;
}
void push(long long i) {
  if (tree[i].tag == 0) return;
  tree[i * 2].tag = tree[i].tag;
  tree[i * 2 + 1].tag = tree[i].tag;
  tree[i * 2].sum = tree[i * 2].tag * (tree[i * 2].r - tree[i * 2].l + 1);
  tree[i * 2 + 1].sum =
      tree[i * 2 + 1].tag * (tree[i * 2 + 1].r - tree[i * 2 + 1].l + 1);
  tree[i].tag = 0;
}
void buildtree(long long i, long long l, long long r) {
  tree[i].l = l;
  tree[i].r = r;
  tree[i].tag = 0;
  if (l == r) {
    tree[i].sum = 0;
    tree[i].v = 0;
    return;
  }
  buildtree(i * 2, l, (l + r) / 2);
  buildtree(i * 2 + 1, (r + l) / 2 + 1, r);
  tree[i].sum = tree[i * 2].sum + tree[i * 2 + 1].sum;
  tree[i].v = max(tree[i * 2].v, tree[i * 2 + 1].v);
}
void update1(long long i, long long l, long long r, long long k) {
  if (tree[i].l >= l && tree[i].r <= r) {
    tree[i].tag = k;
    tree[i].sum = k * (tree[i].r - tree[i].l + 1);
    return;
  }
  push(i);
  long long m = (tree[i].l + tree[i].r) / 2;
  if (l <= m) update1(i * 2, l, r, k);
  if (r > m) update1(i * 2 + 1, l, r, k);
  tree[i].sum = tree[i * 2].sum + tree[i * 2 + 1].sum;
  tree[i].v = max(tree[i * 2].v, tree[i * 2 + 1].v);
}
void update2(long long i, long long l, long long r, long long k) {
  if (tree[i].l >= l && tree[i].r <= r) {
    tree[i].v = k;
    return;
  }
  push(i);
  long long m = (tree[i].l + tree[i].r) / 2;
  if (l <= m) update2(i * 2, l, r, k);
  if (r > m) update2(i * 2 + 1, l, r, k);
  tree[i].sum = tree[i * 2].sum + tree[i * 2 + 1].sum;
  tree[i].v = max(tree[i * 2].v, tree[i * 2 + 1].v);
}
long long query1(long long i, long long l, long long r) {
  if (tree[i].l >= l && tree[i].r <= r) {
    return tree[i].sum;
  }
  push(i);
  long long m = (tree[i].r + tree[i].l) / 2, ans = 0;
  if (l <= m) ans += query1(i * 2, l, r);
  if (r > m) ans += query1(i * 2 + 1, l, r);
  return ans;
}
long long query2(long long i, long long l, long long r) {
  if (tree[i].l >= l && tree[i].r <= r) {
    return tree[i].v;
  }
  push(i);
  long long m = (tree[i].r + tree[i].l) / 2, ans = 0;
  if (l <= m) ans = max(ans, query2(i * 2, l, r));
  if (r > m) ans = max(ans, query2(i * 2 + 1, l, r));
  return ans;
}
int main() {
  long long n, q;
  cin >> n;
  for (long long i = 1; i < n; i++) {
    long long u, v;
    scanf("%lld%lld", &u, &v);
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  cin >> q;
  dfs(1, 0);
  buildtree(1, 1, n);
  for (long long i = 1; i <= q; i++) {
    long long op, v;
    scanf("%lld%lld", &op, &v);
    if (op == 1) {
      update1(1, tin[v], tout[v], i);
    }
    if (op == 2) {
      update2(1, tin[v], tin[v], i);
    }
    if (op == 3) {
      long long x = query1(1, tin[v], tin[v]);
      long long y = query2(1, tin[v], tout[v]);
      if (x > y)
        printf("1\n");
      else
        printf("0\n");
    }
  }
}
