#include <bits/stdc++.h>
using namespace std;
const int N = 500010;
const double pi = 4 * atan(1);
const double eps = 1e-6;
vector<int> adj[N];
int n, m, q, par[N], lv[N], stsz[N], sc[N], node_head[N], new_pos, cost[N],
    indx[N], res[N], root = 1;
int tree[4 * N], lz[4 * N];
void lazy(int l, int r, int pos) {
  if (lz[pos] == 0) return;
  tree[pos] = lz[pos];
  if (l != r) {
    lz[2 * pos] = lz[pos];
    lz[2 * pos + 1] = lz[pos];
  }
  lz[pos] = 0;
  return;
}
void update(int l, int r, int pos, int L, int R, int val) {
  lazy(l, r, pos);
  if (l > R || r < L) return;
  if (l >= L && r <= R) {
    tree[pos] = val;
    if (l != r) {
      lz[2 * pos] = val;
      lz[2 * pos + 1] = val;
    }
    return;
  }
  int mid = (l + r) / 2;
  update(l, mid, 2 * pos, L, R, val);
  update(mid + 1, r, 2 * pos + 1, L, R, val);
  tree[pos] = min(tree[2 * pos], tree[2 * pos + 1]);
  return;
}
int query(int l, int r, int pos, int L, int R) {
  lazy(l, r, pos);
  if (l > R || r < L) return 0;
  if (l >= L && r <= R) return tree[pos];
  int mid = (l + r) / 2;
  return query(l, mid, 2 * pos, L, R) + query(mid + 1, r, 2 * pos + 1, L, R);
}
int uc = 1;
pair<int, int> range[N];
int dfs(int now, int pre) {
  int cnt = 1, sz = adj[now].size(), mx = 0, special = 0;
  for (int i = 0; i < sz; i++) {
    int node = adj[now][i];
    if (node != pre) {
      lv[node] = lv[now] + 1;
      cnt += dfs(node, now);
      if (stsz[node] > mx) {
        mx = stsz[node];
        special = node;
      }
    }
  }
  sc[now] = special;
  return stsz[now] = cnt;
}
void dfs2(int now, int pre) {
  range[now].first = indx[now];
  range[now].second = indx[now];
  for (auto u : adj[now]) {
    if (u != pre) {
      dfs2(u, now);
      range[now].second = max(range[now].second, range[u].second);
    }
  }
}
void HLD(int pre, int now, int head) {
  node_head[now] = head;
  indx[now] = ++new_pos;
  par[now] = pre;
  if (sc[now] != 0) HLD(now, sc[now], head);
  int sz = adj[now].size();
  for (int i = 0; i < sz; i++) {
    int node = adj[now][i];
    if (node != sc[now] && node != pre) {
      HLD(now, node, node);
    }
  }
}
void go_up(int u, int v, int val) {
  if (node_head[u] == node_head[v]) {
    (lv[u] < lv[v] ? update(1, n, 1, indx[u], indx[v], val)
                   : update(1, n, 1, indx[v], indx[u], val));
    return;
  }
  if (lv[node_head[u]] > lv[node_head[v]]) {
    update(1, n, 1, indx[node_head[u]], indx[u], val);
    go_up(par[node_head[u]], v, val);
  } else {
    update(1, n, 1, indx[node_head[v]], indx[v], val);
    go_up(u, par[node_head[v]], val);
  }
}
int solve() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(root, 0);
  HLD(0, root, root);
  dfs2(root, 0);
  cin >> m;
  while (m--) {
    int f, x, val;
    cin >> f >> x;
    if (f == 1) {
      update(1, n, 1, range[x].first, range[x].second, 1);
    } else if (f == 2) {
      go_up(root, x, -1);
    } else {
      int res = query(1, n, 1, indx[x], indx[x]);
      if (res != 1) res = 0;
      printf("%d\n", res);
    }
  }
  return 0;
}
int main() { return solve(); }
