#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
long long int bigmod(long long int B, long long int P, long long int M) {
  long long int R = 1;
  while (P > 0) {
    if (P & 1) {
      R = (R * B) % M;
    }
    P /= 2;
    B = (B * B) % M;
  }
  return R;
}
const int N = 5e5 + 5;
long long int tree[4 * N], lazy[4 * N], sub[N], par[N], tym, start[N], fin[N];
vector<int> g[N];
void dfs(int u, int p) {
  par[u] = p;
  sub[u] = 1;
  start[u] = ++tym;
  for (int v : g[u]) {
    if (v != p) {
      dfs(v, u);
      sub[u] += sub[v];
    }
  }
  fin[u] = tym;
}
void node_update(long long int node, long long int b, long long int e,
                 long long int v) {
  tree[node] = (e - b + 1) * v;
  lazy[node] = v;
}
void push_down(long long int node, long long int b, long long int e) {
  long long int mid = (b + e) / 2;
  if (b != e) {
    node_update(2 * node, b, mid, lazy[node]);
    node_update(2 * node + 1, mid + 1, e, lazy[node]);
  }
  lazy[node] = 0;
}
void update(long long int node, long long int b, long long int e,
            long long int i, long long int j, long long int v) {
  if (lazy[node] != 0) push_down(node, b, e);
  if (e < i || b > j) return;
  if (b >= i && e <= j) {
    node_update(node, b, e, v);
    return;
  }
  long long int lft = 2 * node, rt = lft + 1, mid = (b + e) / 2;
  update(lft, b, mid, i, j, v);
  update(rt, mid + 1, e, i, j, v);
  tree[node] = (tree[lft] + tree[rt]);
}
long long int query(long long int node, long long int b, long long int e,
                    long long int i, long long int j) {
  if (lazy[node] != 0) push_down(node, b, e);
  if (e < i || b > j) return 0;
  if (b >= i && e <= j) {
    return tree[node];
  }
  long long int lft = 2 * node, rt = lft + 1, mid = (b + e) / 2;
  long long int p = query(lft, b, mid, i, j);
  long long int q = query(rt, mid + 1, e, i, j);
  return (p + q);
}
void reset() {
  for (__typeof(N - 2) i = 0; i <= N - 2; i++) {
    g[i].clear();
    sub[i] = start[i] = fin[i] = 0;
  }
  memset(tree, 0, sizeof(tree));
  memset(lazy, 0, sizeof(lazy));
}
int main() {
  int n, q, u, v, t;
  while (scanf("%d", &n) != EOF) {
    reset();
    for (__typeof(n - 1) i = 1; i <= n - 1; i++) {
      scanf("%d%d", &u, &v);
      g[u].push_back(v);
      g[v].push_back(u);
    }
    tym = 0;
    dfs(1, 1);
    scanf("%d", &q);
    while (q--) {
      scanf("%d%d", &t, &u);
      if (t == 1) {
        if (query(1, 1, tym, start[u], fin[u]) < sub[u]) {
          update(1, 1, tym, start[u], fin[u], 1);
          if (u != 1) update(1, 1, tym, start[par[u]], start[par[u]], 0);
        }
      } else if (t == 2) {
        update(1, 1, tym, start[u], start[u], 0);
      } else {
        printf("%d\n", query(1, 1, tym, start[u], fin[u]) == sub[u] ? 1 : 0);
      }
    }
  }
  return 0;
}
