#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> adj;
vector<long long> cnt;
vector<long long> pre;
vector<long long> parent;
class SegmentTree {
 public:
  vector<bool> marked;
  vector<long long> lazy;
  vector<long long> tree;
  vector<long long> sz;
  long long n;
  SegmentTree(vector<long long>& v) {
    n = v.size();
    tree = vector<long long>(4 * n, 0);
    lazy = vector<long long>(4 * n, 0);
    sz = vector<long long>(4 * n, 0);
    marked = vector<bool>(4 * n, false);
    build(v, 0, n - 1, 1);
  }
  void build(vector<long long>& v, long long left, long long right,
             long long idx) {
    if (left == right) {
      tree[idx] = v[left];
      sz[idx] = 1;
    } else {
      long long mid = left + (right - left) / 2;
      build(v, left, mid, idx * 2);
      build(v, mid + 1, right, idx * 2 + 1);
      tree[idx] = tree[idx * 2] + tree[idx * 2 + 1];
      sz[idx] = sz[idx * 2] + sz[idx * 2 + 1];
    }
  }
  void push(long long idx) {
    if (marked[idx]) {
      marked[idx] = false;
      marked[idx * 2] = marked[idx * 2 + 1] = true;
      lazy[idx * 2] = lazy[idx * 2 + 1] = lazy[idx];
      tree[idx * 2] = lazy[idx * 2] * sz[idx * 2];
      tree[idx * 2 + 1] = lazy[idx * 2 + 1] * sz[idx * 2 + 1];
    }
  }
  long long query(long long idx, long long left, long long right, long long lo,
                  long long hi) {
    if (lo > hi) return 0;
    if (left == lo && right == hi)
      return tree[idx];
    else {
      push(idx);
      long long mid = left + (right - left) / 2;
      return query(idx * 2, left, mid, lo, min(mid, hi)) +
             query(idx * 2 + 1, mid + 1, right, max(mid + 1, lo), hi);
    }
  }
  void update(long long idx, long long left, long long right, long long lo,
              long long hi, long long val) {
    if (lo > hi) return;
    if (left == lo && right == hi) {
      marked[idx] = true;
      lazy[idx] = val;
      tree[idx] = lazy[idx] * sz[idx];
    } else {
      push(idx);
      long long mid = left + (right - left) / 2;
      update(idx * 2, left, mid, lo, min(hi, mid), val);
      update(idx * 2 + 1, mid + 1, right, max(lo, mid + 1), hi, val);
      tree[idx] = tree[idx * 2] + tree[idx * 2 + 1];
    }
  }
};
long long dfs(long long idx, long long prev) {
  long long ret = 1;
  pre.push_back(idx);
  parent[idx] = prev;
  for (auto nidx : adj[idx]) {
    if (nidx == prev) continue;
    ret += dfs(nidx, idx);
  }
  cnt[idx] = ret;
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long n;
  cin >> n;
  adj = vector<vector<long long>>(n + 1);
  cnt = vector<long long>(n + 1, 0);
  parent = vector<long long>(n + 1, 0);
  pre.clear();
  for (long long i = 0; i < n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  dfs(1, 0);
  unordered_map<long long, long long> mp;
  for (long long i = 0; i < pre.size(); i++) mp[pre[i]] = i;
  vector<long long> tmp(n, 0);
  SegmentTree st(tmp);
  long long q;
  cin >> q;
  while (q--) {
    long long c, v;
    cin >> c >> v;
    long long lo = mp[v];
    long long hi = lo + cnt[v] - 1;
    if (c == 1) {
      long long sum = st.query(1, 0, n - 1, lo, hi);
      if (sum != cnt[v]) {
        long long p = mp[parent[v]];
        st.update(1, 0, n - 1, p, p, 0);
      }
      st.update(1, 0, n - 1, lo, hi, 1);
    } else if (c == 2) {
      st.update(1, 0, n - 1, lo, lo, 0);
    } else {
      long long sum = st.query(1, 0, n - 1, lo, hi);
      if (sum == cnt[v])
        cout << 1 << endl;
      else
        cout << 0 << endl;
    }
  }
  return 0;
}
