#include <bits/stdc++.h>
using namespace std;
struct Counter {
  static int k;
  Counter() { k++; }
  ~Counter() { k--; }
};
int Counter::k = 0;
template <typename T>
void pr(const string &name, T t) {
  cout << name << " = " << t << endl;
}
template <typename T, typename... Types>
void pr(const string &names, T t, Types... rest) {
  auto comma_pos = names.find(',');
  cout << names.substr(0, comma_pos) << " = " << t << ", ";
  auto next_name_pos = names.find_first_not_of(" \t\n", comma_pos + 1);
  pr(string(names, next_name_pos), rest...);
}
void mod(long long &a, long long b) {
  a %= b;
  if (a < 0) a += b;
}
const long long MOD = 1000000007;
const int MAX = 500005;
const int RIGHT = 524288;
const int SIZE = 1050000;
int L[MAX], R[MAX], N, Ord, Q;
vector<int> E[MAX], On(SIZE, 0), Off(SIZE, 0), LazyOn(SIZE, 0),
    LazyOff(SIZE, 0);
void dfs(int n, int p) {
  L[n] = ++Ord;
  for (int v : E[n])
    if (v != p) dfs(v, n);
  R[n] = Ord;
}
void update(vector<int> &t, vector<int> &lazy, int l, int r, int v, int n,
            int a, int b) {
  if (a > r || b < l) return;
  if (a >= l && b <= r) {
    lazy[n] = v;
    t[n] = v;
    return;
  }
  if (lazy[n]) {
    t[2 * n] = max(t[2 * n], lazy[n]);
    t[2 * n + 1] = max(t[2 * n + 1], lazy[n]);
    lazy[2 * n] = max(lazy[2 * n], lazy[n]);
    lazy[2 * n + 1] = max(lazy[2 * n + 1], lazy[n]);
    lazy[n] = 0;
  }
  int mid = (a + b) / 2;
  update(t, lazy, l, r, v, 2 * n, a, mid);
  update(t, lazy, l, r, v, 2 * n + 1, mid + 1, b);
  t[n] = max(t[2 * n], t[2 * n + 1]);
}
int query(vector<int> &t, vector<int> &lazy, int l, int r, int n, int a,
          int b) {
  if (a > r || b < l) return 0;
  if (a >= l && b <= r) return t[n];
  if (lazy[n]) {
    t[2 * n] = max(t[2 * n], lazy[n]);
    t[2 * n + 1] = max(t[2 * n + 1], lazy[n]);
    lazy[2 * n] = max(lazy[2 * n], lazy[n]);
    lazy[2 * n + 1] = max(lazy[2 * n + 1], lazy[n]);
    lazy[n] = 0;
  }
  int mid = (a + b) / 2;
  int ql = query(t, lazy, l, r, 2 * n, a, mid);
  int qr = query(t, lazy, l, r, 2 * n + 1, mid + 1, b);
  return max(ql, qr);
}
int main() {
  scanf("%d", &N);
  for (int i = (1); i <= (N - 1); i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    E[a].push_back(b), E[b].push_back(a);
  }
  dfs(1, 0);
  scanf("%d", &Q);
  for (int i = (1); i <= (Q); i++) {
    int t, v;
    scanf("%d%d", &t, &v);
    if (t == 1)
      update(On, LazyOn, L[v], R[v], i, 1, 1, RIGHT);
    else if (t == 2)
      update(Off, LazyOff, L[v], L[v], i, 1, 1, RIGHT);
    else {
      int on = query(On, LazyOn, L[v], L[v], 1, 1, RIGHT);
      int off = query(Off, LazyOff, L[v], R[v], 1, 1, RIGHT);
      if (on > off)
        printf("1\n");
      else
        printf("0\n");
    }
  }
}
