#include <bits/stdc++.h>
using namespace std;
const int Max = 1000000;
int n, a, b, c, q, vtime;
int start[Max], finish[Max];
bool mark[Max];
vector<int> nei[Max];
vector<pair<int, int> > ver;
int seg1[4 * Max], seg2[4 * Max];
vector<pair<int, int> >::iterator it;
void input() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    scanf("%d%d", &a, &b);
    a--;
    b--;
    nei[a].push_back(b);
    nei[b].push_back(a);
  }
}
void dfs(int u) {
  mark[u] = true;
  ver.push_back(make_pair(vtime, u));
  start[u] = vtime;
  vtime++;
  if ((int)nei[u].size())
    for (int v = nei[u][0], i = 0; i < (int)nei[u].size(); i++, v = nei[u][i])
      if (!mark[v]) dfs(v);
  finish[u] = vtime;
}
void ch1(int begin, int end, int k, int ltime, int st, int en) {
  if (begin >= en || end <= st) return;
  if (begin <= st && end >= en) {
    seg1[k] = ltime;
    return;
  }
  ch1(begin, end, 2 * k, ltime, st, ((st + en) / 2));
  ch1(begin, end, 2 * k + 1, ltime, ((st + en) / 2), en);
}
int get1(int key, int k, int st, int en) {
  if (st + 1 == en) return seg1[k];
  if (key < ((st + en) / 2))
    return max(seg1[k], get1(key, 2 * k, st, ((st + en) / 2)));
  else
    return max(seg1[k], get1(key, 2 * k + 1, ((st + en) / 2), en));
}
void fill(int u, int t) {
  int begin = start[u];
  int end = finish[u];
  ch1(begin, end, 1, t, 0, (int)ver.size());
}
void ch2(int key, int k, int ltime, int st, int en) {
  seg2[k] = ltime;
  if (st + 1 == en) return;
  if (key < ((st + en) / 2))
    ch2(key, 2 * k, ltime, st, ((st + en) / 2));
  else
    ch2(key, 2 * k + 1, ltime, ((st + en) / 2), en);
}
int get2(int begin, int end, int k, int st, int en) {
  if (begin >= en || end <= st) return 0;
  if (begin <= st && end >= en) return seg2[k];
  return max(get2(begin, end, 2 * k, st, ((st + en) / 2)),
             get2(begin, end, 2 * k + 1, ((st + en) / 2), en));
}
void empty(int u, int t) {
  int ind = start[u];
  ch2(ind, 1, t, 0, (int)ver.size());
}
void ans(int u) {
  int begin = start[u];
  int end = finish[u];
  int f = get1(begin, 1, 0, (int)ver.size());
  int e = get2(begin, end, 1, 0, (int)ver.size());
  if (e >= f)
    cout << "0" << endl;
  else
    cout << "1" << endl;
}
void solve() {
  dfs(0);
  scanf("%d", &q);
  for (int i = 1; i < q + 1; i++) {
    int v;
    scanf("%d%d", &c, &v);
    v--;
    if (c == 1)
      fill(v, i);
    else if (c == 2)
      empty(v, i);
    else
      ans(v);
  }
}
int main() {
  input();
  solve();
  return 0;
}
