#include <bits/stdc++.h>
using namespace std;
const int MAXn = 5 * 1000 * 100, MAXv = (1 << 20);
vector<int> adj[MAXn + 5];
bool mark[MAXn + 5];
int st[MAXn + 5], seg[2][MAXv + 5];
pair<int, int> baze[MAXn + 5], interv[MAXv + 5];
int cnt = 0, p, t = 0;
void DFS(int v) {
  mark[v] = true;
  st[v] = cnt;
  cnt++;
  for (int i = 0; i < (int)adj[v].size(); i++)
    if (!mark[adj[v][i]]) DFS(adj[v][i]);
  baze[v] = make_pair(st[v], cnt - 1);
}
void upd(int v) {
  seg[0][v] = -1;
  seg[1][v] = -2;
  if (v >= (1 << p)) {
    interv[v] = make_pair(v, v);
    return;
  }
  int l = v * 2, r = v * 2 + 1;
  upd(l);
  upd(r);
  interv[v] = make_pair(interv[l].first, interv[r].second);
}
void fill(int v, int l, int r) {
  int st = interv[v].first, e = interv[v].second;
  if (l == st && r == e) {
    seg[1][v] = t;
    return;
  }
  int mid = (st + e) >> 1;
  if (r <= mid)
    fill(v * 2, l, r);
  else if (l > mid)
    fill(v * 2 + 1, l, r);
  else {
    fill(v * 2, l, mid);
    fill(v * 2 + 1, mid + 1, r);
  }
}
void empty(int v, int x) {
  int st = interv[v].first, e = interv[v].second;
  if (v == x) {
    seg[0][v] = t;
    return;
  }
  int mid = (st + e) >> 1;
  if (x <= mid)
    empty(v * 2, x);
  else
    empty(v * 2 + 1, x);
  seg[0][v] = max(seg[0][v * 2], seg[0][v * 2 + 1]);
}
int check(int v, int l, int r) {
  int st = interv[v].first, e = interv[v].second;
  if (l == st && e == r) return seg[0][v];
  int mid = (st + e) >> 1;
  if (r <= mid)
    return check(v * 2, l, r);
  else if (l > mid)
    return check(v * 2 + 1, l, r);
  return max(check(v * 2, l, mid), check(v * 2 + 1, mid + 1, r));
}
int get(int v, int x) {
  int st = interv[v].first, e = interv[v].second;
  if (v == x) return seg[1][v];
  int mid = (st + e) >> 1, num;
  if (x <= mid)
    num = get(v * 2, x);
  else
    num = get(v * 2 + 1, x);
  return max(num, seg[1][v]);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  DFS(0);
  p = 32 - __builtin_clz(n);
  if (__builtin_popcount(n) == 1) p--;
  upd(1);
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int c, v;
    scanf("%d%d", &c, &v);
    v--;
    if (c == 1)
      fill(1, baze[v].first + (1 << p), baze[v].second + (1 << p));
    else if (c == 2)
      empty(1, st[v] + (1 << p));
    else {
      int zero = check(1, baze[v].first + (1 << p), baze[v].second + (1 << p)),
          one = get(1, st[v] + (1 << p));
      if (zero > one)
        printf("0\n");
      else
        printf("1\n");
    }
    t++;
  }
  return 0;
}
