#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 100;
int n, q, ans[4 * N], lazy[4 * N], start, st[N], fn[N], par[N];
vector<int> adj[N];
bool mark[N];
void shift(int b, int e, int ind) {
  if (lazy[ind] == -1) return;
  int child = ind * 2;
  int mid = (b + e) / 2;
  lazy[child] = lazy[ind];
  lazy[child + 1] = lazy[ind];
  ans[child] = (mid - b) * lazy[ind];
  ans[child + 1] = (e - mid) * lazy[ind];
  lazy[ind] = -1;
}
int sum(int l, int r, int b = 0, int e = n, int ind = 1) {
  if (l <= b && e <= r) return ans[ind];
  shift(b, e, ind);
  int mid = (b + e) / 2;
  int ret = 0;
  if (l < mid) ret += sum(l, r, b, mid, ind * 2);
  if (r > mid) ret += sum(l, r, mid, e, ind * 2 + 1);
  return ret;
}
void change(int l, int r, int val, int b = 0, int e = n, int ind = 1) {
  if (l <= b && e <= r) {
    ans[ind] = (e - b) * val;
    lazy[ind] = val;
    return;
  }
  shift(b, e, ind);
  int mid = (b + e) / 2;
  if (l < mid) change(l, r, val, b, mid, ind * 2);
  if (r > mid) change(l, r, val, mid, e, ind * 2 + 1);
  ans[ind] = ans[ind * 2] + ans[ind * 2 + 1];
}
void DFS(int v) {
  mark[v] = 1;
  st[v] = start++;
  for (int i = 0; i < adj[v].size(); i++) {
    int u = adj[v][i];
    if (!mark[u]) {
      par[u] = v;
      DFS(u);
    }
  }
  fn[v] = start;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    adj[--u].push_back(--v);
    adj[v].push_back(u);
  }
  DFS(0);
  for (int i = 0; i < 4 * n + 10; i++) lazy[i] = -1;
  cin >> q;
  while (q) {
    q--;
    int c, v;
    cin >> c >> v;
    v--;
    if (c == 1) {
      int t = sum(st[v], fn[v]);
      if (t < fn[v] - st[v]) change(st[par[v]], st[par[v]] + 1, 0);
      change(st[v], fn[v], 1);
    } else if (c == 2)
      change(st[v], st[v] + 1, 0);
    else {
      int t = sum(st[v], fn[v]);
      if (t < fn[v] - st[v])
        cout << 0 << endl;
      else
        cout << 1 << endl;
    }
  }
}
