#include <bits/stdc++.h>
using namespace std;
const int maxn = 500010;
int lft[maxn << 2], rht[maxn << 2], M1[maxn << 2], M2[maxn << 2];
void build(int n, int l, int r) {
  lft[n] = l, rht[n] = r;
  if (l == r) return;
  int mid = (l + r) / 2;
  build(n << 1, l, mid);
  build((n << 1) + 1, mid + 1, r);
}
void upd1(int n, int p, int k) {
  M1[n] = k;
  if (lft[n] == rht[n]) return;
  int mid = (lft[n] + rht[n]) / 2;
  if (p <= mid)
    upd1(n << 1, p, k);
  else
    upd1((n << 1) + 1, p, k);
}
int get1(int n, int l, int r) {
  if (lft[n] == l && rht[n] == r) return M1[n];
  int mid = (lft[n] + rht[n]) / 2;
  if (r <= mid)
    return get1(n << 1, l, r);
  else if (l > mid)
    return get1((n << 1) + 1, l, r);
  return max(get1(n << 1, l, mid), get1((n << 1) + 1, mid + 1, r));
}
void upd2(int n, int l, int r, int k) {
  if (lft[n] == l && rht[n] == r) {
    M2[n] = k;
    return;
  }
  int mid = (lft[n] + rht[n]) / 2;
  if (r <= mid)
    upd2(n << 1, l, r, k);
  else if (l > mid)
    upd2((n << 1) + 1, l, r, k);
  else
    upd2(n << 1, l, mid, k), upd2((n << 1) + 1, mid + 1, r, k);
}
int get2(int n, int p) {
  if (lft[n] == rht[n]) return M2[n];
  int mid = (lft[n] + rht[n]) / 2;
  int ans;
  if (p <= mid)
    ans = get2(n << 1, p);
  else
    ans = get2((n << 1) + 1, p);
  return max(ans, M2[n]);
}
int tou[maxn], wei[maxn], chuo, fa[maxn];
int first[maxn], nxt[maxn << 1], vv[maxn << 1];
void dfs(int n) {
  tou[n] = ++chuo;
  for (int e = first[n]; e; e = nxt[e])
    if (vv[e] - fa[n]) fa[vv[e]] = n, dfs(vv[e]);
  wei[n] = chuo;
}
int main() {
  int n, m, i, j, k;
  cin >> n;
  int e = 2, u, v;
  for (i = 1; i < n; i++) {
    scanf("%d%d", &u, &v);
    nxt[e] = first[u], vv[e] = v, first[u] = e++;
    nxt[e] = first[v], vv[e] = u, first[v] = e++;
  }
  dfs(1);
  cin >> m;
  build(1, 1, n);
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &j, &k);
    if (j == 1)
      upd2(1, tou[k], wei[k], i);
    else if (j == 2)
      upd1(1, tou[k], i);
    else {
      int m1 = get1(1, tou[k], wei[k]);
      int m2 = get2(1, tou[k]);
      if (m1 >= m2)
        puts("0");
      else
        puts("1");
    }
  }
}
