#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int child[N], node[4 * N], lazy[4 * N], par[20][N], head[N], pos[N], n, q,
    st[N], en[N];
int cnt = 0;
vector<int> g[N];
void input() {
  scanf("%d", &n);
  for (int i = 1; i <= n - 1; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  memset(head, 0, sizeof(head));
}
void dfs(int u, int p) {
  child[u] = 1;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (v == p) continue;
    par[0][v] = u;
    dfs(v, u);
    child[u] += child[v];
  }
}
void prepare() {
  for (int i = 1; i < 20; i++) {
    for (int j = 1; j <= n; j++) {
      par[i][j] = par[i - 1][par[i - 1][j]];
    }
  }
}
void HLD(int u, int p) {
  if (!head[u]) head[u] = u;
  st[u] = pos[u] = ++cnt;
  int big = -1;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (v == p) continue;
    if (big == -1 || child[big] < child[v]) big = v;
  }
  if (big != -1) {
    head[big] = head[u];
    HLD(big, u);
  }
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (v == p || v == big) continue;
    HLD(v, u);
  }
  en[u] = cnt;
}
void init(int i, int l, int r) {
  if (l > r) return;
  if (l == r) {
    node[i] = 0;
    lazy[i] = -1;
    return;
  }
  int m = (l + r) >> 1;
  init(i << 1, l, m);
  init(i << 1 | 1, m + 1, r);
  node[i] = node[i << 1] + node[i << 1 | 1];
  lazy[i] = -1;
}
void dolazy(int i, int l, int r) {
  if (lazy[i] >= 0) {
    node[i] = lazy[i] * (r - l + 1);
    if (l != r) {
      lazy[i << 1] = lazy[i];
      lazy[i << 1 | 1] = lazy[i];
    }
    lazy[i] = -1;
  }
}
void update(int i, int l, int r, int a, int b, int val) {
  dolazy(i, l, r);
  if (l > r || a > r || b < l) return;
  if (a <= l && r <= b) {
    node[i] = val * (r - l + 1);
    if (l != r) {
      lazy[i << 1] = val;
      lazy[i << 1 | 1] = val;
    }
    return;
  }
  int m = (l + r) >> 1;
  update(i << 1, l, m, a, b, val);
  update(i << 1 | 1, m + 1, r, a, b, val);
  node[i] = node[i << 1] + node[i << 1 | 1];
}
int get(int i, int l, int r, int a, int b) {
  if (l > r || a > r || b < l) return 0;
  dolazy(i, l, r);
  if (a <= l && r <= b) return node[i];
  int m = (l + r) >> 1;
  return get(i << 1, l, m, a, b) + get(i << 1 | 1, m + 1, r, a, b);
}
void query(int u, int v) {
  while (head[u] != head[v]) {
    update(1, 1, cnt, pos[head[u]], pos[u], 0);
    u = par[0][head[u]];
  }
  update(1, 1, cnt, pos[v], pos[u], 0);
}
void solve() {
  scanf("%d", &q);
  while (q--) {
    int type, x;
    scanf("%d %d", &type, &x);
    if (type == 1)
      update(1, 1, cnt, st[x], en[x], 1);
    else if (type == 2)
      query(x, 1);
    else
      printf("%d\n", get(1, 1, cnt, st[x], st[x]));
  }
}
int main() {
  input();
  dfs(1, 1);
  prepare();
  HLD(1, 1);
  init(1, 1, cnt);
  solve();
  return 0;
}
