#include <bits/stdc++.h>
using namespace std;
struct node {
  int sta, lz;
};
const int INF = 1061109567;
const int MAXN = 500005;
int n, t;
vector<vector<int> > adj;
vector<int> par;
node seg[MAXN * 4];
vector<pair<int, int> > currSeg;
void makePairs(int curr, int past) {
  currSeg[curr].first = ++t;
  par[curr] = past;
  for (int node : adj[curr]) {
    if (node != past) makePairs(node, curr);
  }
  currSeg[curr].second = t;
}
void down(int node, int l, int r) {
  if (seg[node].lz == -1) return;
  seg[node].sta = seg[node].lz;
  if (l != r) {
    seg[node * 2].lz = seg[node].lz;
    seg[node * 2 + 1].lz = seg[node].lz;
  }
  seg[node].lz = -1;
}
void fillRange(int a, int b, int val, int node = 1, int l = 1, int r = t) {
  down(node, l, r);
  if (l > b || r < a) return;
  if (l >= a && r <= b) {
    seg[node].lz = val;
    down(node, l, r);
    return;
  }
  int mid = (l + r) / 2;
  fillRange(a, b, val, node * 2, l, mid);
  fillRange(a, b, val, node * 2 + 1, mid + 1, r);
  seg[node].sta = seg[node * 2].sta && seg[node * 2 + 1].sta;
}
int query(int a, int b, int node = 1, int l = 1, int r = t) {
  down(node, l, r);
  if (l > b || r < a) return 1;
  if (l >= a && r <= b) return seg[node].sta;
  int mid = (l + r) / 2;
  return query(a, b, node * 2, l, mid) && query(a, b, node * 2 + 1, mid + 1, r);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.precision(20);
  cin >> n;
  adj.resize(n + 1);
  currSeg.resize(n + 1);
  par.resize(n + 1);
  for (int i = 0; i < n - 1; i++) {
    int n1, n2;
    cin >> n1 >> n2;
    adj[n1].push_back(n2);
    adj[n2].push_back(n1);
  }
  makePairs(1, 1);
  for (int i = 0; i < MAXN * 4; i++) {
    seg[i].sta = 0;
    seg[i].lz = -1;
  }
  int q;
  cin >> q;
  while (q--) {
    int n1, n2;
    cin >> n1 >> n2;
    pair<int, int> curr = currSeg[n2];
    if (n1 == 1) {
      if (!query(curr.first, curr.second)) {
        fillRange(currSeg[par[n2]].first, currSeg[par[n2]].first, 0);
      }
      fillRange(curr.first, curr.second, 1);
    } else if (n1 == 2) {
      fillRange(curr.first, curr.first, 0);
    } else {
      cout << query(curr.first, curr.second) << endl;
    }
  }
}
