#include <bits/stdc++.h>
using namespace std;
int n;
int st[500001];
int en[500001];
vector<int> v[500001];
vector<int> g[500001];
bool use[500001];
int siz = 0;
inline void dfs(int b) {
  use[b] = true;
  st[b] = siz;
  siz++;
  for (int i = 0; i < v[b].size(); i++) {
    if (use[v[b][i]]) {
      continue;
    }
    g[b].push_back(v[b][i]);
    dfs(v[b][i]);
  }
  en[b] = siz;
}
int seg[500001 * 4];
bool flag[500001];
int vv[500001];
inline void add(int b, int l, int r, int ll, int x) {
  if (r <= ll || ll < l) {
    return;
  }
  seg[b] = x;
  if (l + 1 == r) {
    return;
  }
  add(b * 2 + 1, l, (l + r) / 2, ll, x);
  add(b * 2 + 2, (l + r) / 2, r, ll, x);
}
inline int q(int b, int l, int r, int ll, int rr) {
  if (r <= ll || rr <= l) {
    return -1;
  }
  if (ll <= l && r <= rr) {
    return seg[b];
  }
  return max(q(b * 2 + 1, l, (l + r) / 2, ll, rr),
             q(b * 2 + 2, (l + r) / 2, r, ll, rr));
}
int seg2[500001 * 4];
int inf[500001 * 4];
int ty1[500001 * 4];
void upd(int b) {
  if (seg2[b] == -1) {
    return;
  }
  seg2[b * 2 + 1] = seg2[b];
  seg2[b * 2 + 2] = seg2[b];
  inf[b] = seg2[b];
  seg2[b] = -1;
}
inline void add2(int b, int l, int r, int ll, int rr, int x) {
  upd(b);
  if (ll <= l && r <= rr) {
    seg2[b] = x;
    return;
  }
  if (rr <= l || r <= ll) {
    return;
  }
  add2(b * 2 + 1, l, (l + r) / 2, ll, rr, x);
  add2(b * 2 + 2, (l + r) / 2, r, ll, rr, x);
}
inline int q2(int b, int l, int r, int ll, int rr) {
  upd(b);
  if (rr <= l || r <= ll) {
    return -1;
  }
  if (ll <= l && r <= rr) {
    return inf[b];
  }
  return max(q2(b * 2 + 1, l, (l + r) / 2, ll, rr),
             q2(b * 2 + 2, (l + r) / 2, r, ll, rr));
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  dfs(0);
  memset(seg, -1, sizeof(seg));
  memset(seg2, -1, sizeof(seg2));
  int qq;
  scanf("%d", &qq);
  int ca = 0;
  while (qq--) {
    ca++;
    int ty;
    scanf("%d", &ty);
    int v;
    scanf("%d", &v);
    v--;
    vv[ca] = v;
    if (ty == 2) {
      ty1[ca] = false;
      flag[v] = false;
      add(0, 0, siz, st[v], ca);
      continue;
    }
    if (ty == 1) {
      ty1[ca] = true;
      flag[v] = true;
      add2(0, 0, siz, st[v], en[v], ca);
      continue;
    }
    int maxt = q2(0, 0, siz, st[v], st[v] + 1);
    maxt = max(maxt, q(0, 0, siz, st[v], en[v]));
    if (maxt == -1) {
      puts("0");
      continue;
    }
    int ou = ty1[maxt];
    printf("%d\n", ou);
  }
  return 0;
}
