#include <bits/stdc++.h>
long long q_pow(long long x, long long n, long long mod) {
  long long ret = 1;
  while (n) {
    if (n & 1) ret = x * ret % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return ret;
}
long long __gcd(long long x, long long y) {
  if (!y) return x;
  return __gcd(y, x % y);
}
long long getbit(long long now) {
  int cnt = 0;
  while (now) {
    cnt++;
    now -= (now) & (-now);
  }
  return cnt;
}
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
using namespace std;
const long long maxn = 500000 + 10;
const long long INF = 0x3f3f3f3f;
const long long IINF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
const int mod = 1e9 + 7;
vector<int> edge[maxn];
int top[maxn], f[maxn], dep[maxn], son[maxn];
int n, m, r, p;
int sz[maxn], id[maxn];
int cnt;
struct Segment {
  struct node {
    int l, r;
    long long lazy, sum;
    int len() { return this->r - this->l + 1; }
  };
  node tree[maxn * 4 + 555];
  void push_up(int i) { tree[i].sum = tree[2 * i].sum + tree[i * 2 + 1].sum; }
  void push_down(int i) {
    if (tree[i].lazy != -INF) {
      tree[i * 2].lazy = tree[i].lazy;
      tree[i * 2 + 1].lazy = tree[i].lazy;
      tree[i * 2].sum = tree[i].lazy * tree[2 * i].len();
      tree[2 * i + 1].sum = tree[i].lazy * tree[2 * i + 1].len();
      tree[i].lazy = -INF;
    }
  }
  void build(int i, int l, int r) {
    tree[i].l = l, tree[i].r = r;
    tree[i].lazy = -INF;
    if (l == r) {
      tree[i].sum = 0;
      return;
    }
    int mid = l + r >> 1;
    build(2 * i, l, mid);
    build(2 * i + 1, mid + 1, r);
    push_up(i);
  }
  void update(int i, int l, int r, int val) {
    if (tree[i].l >= l && tree[i].r <= r) {
      tree[i].sum = 1LL * val * tree[i].len();
      tree[i].lazy = val;
      return;
    }
    push_down(i);
    int mid = tree[i].l + tree[i].r >> 1;
    if (l <= mid) update(2 * i, l, r, val);
    if (r > mid) update(2 * i + 1, l, r, val);
    push_up(i);
  }
  long long query(int i, int l, int r) {
    if (l > r) return 0;
    if (tree[i].l >= l && tree[i].r <= r) {
      return tree[i].sum;
    }
    push_down(i);
    int mid = tree[i].l + tree[i].r >> 1;
    long long ans = 0;
    if (l <= mid) ans += query(2 * i, l, r);
    if (r > mid) ans += query(2 * i + 1, l, r);
    return ans;
  }
  long long query_tree(int x, int y) {
    if (!x || !y) return 0;
    long long ans = 0;
    while (top[x] != top[y]) {
      if (dep[top[x]] < dep[top[y]]) swap(x, y);
      ans += query(1, id[top[x]], id[x]);
      x = f[top[x]];
    }
    if (dep[x] > dep[y]) swap(x, y);
    ans += query(1, id[x], id[y]);
    return ans;
  }
  void update_tree(int x, int y, int k) {
    while (top[x] != top[y]) {
      if (dep[top[x]] < dep[top[y]]) swap(x, y);
      update(1, id[top[x]], id[x], k);
      x = f[top[x]];
    }
    if (dep[x] > dep[y]) swap(x, y);
    update(1, id[x], id[y], k);
  }
};
Segment A;
void dfs(int pos, int fa) {
  f[pos] = fa;
  sz[pos] = 1;
  dep[pos] = dep[fa] + 1;
  for (auto to : edge[pos]) {
    if (to == fa) continue;
    dfs(to, pos);
    sz[pos] += sz[to];
    if (sz[to] > sz[son[pos]]) son[pos] = to;
  }
}
void dfs2(int pos, int topf) {
  id[pos] = ++cnt;
  top[pos] = topf;
  if (!son[pos]) return;
  dfs2(son[pos], topf);
  for (auto to : edge[pos]) {
    if (to == f[pos]) continue;
    if (to == son[pos]) continue;
    dfs2(to, to);
  }
}
void init(int n) {
  for (int i = 1; i <= n; i++) edge[i].clear(), son[i] = 0;
  cnt = 0;
}
void solve() {
  int m, n;
  scanf("%d", &n);
  int u, v;
  init(n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &u, &v);
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  r = 1;
  dep[0] = -1;
  dfs(1, 0);
  dfs2(1, 1);
  int opt;
  int pos;
  A.build(1, 1, n);
  scanf("%d", &m);
  while (m--) {
    scanf("%d", &opt);
    if (opt == 1) {
      scanf("%d", &pos);
      A.update(1, id[pos], id[pos] + sz[pos] - 1, 1);
    } else if (opt == 2) {
      scanf("%d", &pos);
      A.update_tree(1, pos, 0);
    } else {
      scanf("%d", &pos);
      printf("%lld\n", A.query(1, id[pos], id[pos]));
    }
  }
}
signed main(int argc, char *argv[]) {
  if (argc == 2 && strcmp("-debug", argv[1]) == 0) {
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
  }
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
