#include <bits/stdc++.h>
using namespace std;
const long long int MAXN = 5e5 + 10;
long long int n, t, tree[4 * MAXN][2], lazy[4 * MAXN];
vector<vector<long long int> > g;
vector<long long int> v, sub;
void dfs(long long int curr, long long int par) {
  v[curr] = ++t;
  for (auto it : g[curr]) {
    if (it == par) {
      continue;
    }
    dfs(it, curr);
    sub[curr] += sub[it];
  }
  sub[curr]++;
}
void pointUpdate(long long int low, long long int high, long long int pos,
                 long long int ind, long long int val) {
  if (low == high) {
    tree[pos][1] = val;
    return;
  }
  long long int mid = (low + high) / 2;
  if (ind <= mid) {
    pointUpdate(low, mid, 2 * pos, ind, val);
  } else {
    pointUpdate(mid + 1, high, 2 * pos + 1, ind, val);
  }
  tree[pos][1] = max(tree[2 * pos][1], tree[2 * pos + 1][1]);
}
long long int pointQuery(long long int low, long long int high,
                         long long int pos, long long int l, long long int r) {
  if (low > high || l > high || r < low) {
    return -1e12;
  }
  if (low >= l && high <= r) {
    return tree[pos][1];
  }
  long long int mid = (low + high) / 2;
  return max(pointQuery(low, mid, 2 * pos, l, r),
             pointQuery(mid + 1, high, 2 * pos + 1, l, r));
}
void rangeUpdate(long long int low, long long int high, long long int pos,
                 long long int l, long long int r, long long int val) {
  if (lazy[pos] != 0) {
    tree[pos][0] = lazy[pos];
    if (low != high) {
      lazy[2 * pos] = lazy[pos];
      lazy[2 * pos + 1] = lazy[pos];
    }
    lazy[pos] = 0;
  }
  if (l > high || r < low || low > high) {
    return;
  }
  if (low >= l && r >= high) {
    tree[pos][0] = val;
    if (low != high) {
      lazy[2 * pos] = val;
      lazy[2 * pos + 1] = val;
    }
    return;
  }
  long long int mid = (low + high) / 2;
  rangeUpdate(low, mid, 2 * pos, l, r, val);
  rangeUpdate(mid + 1, high, 2 * pos + 1, l, r, val);
  tree[pos][0] = max(tree[2 * pos][0], tree[2 * pos + 1][0]);
}
long long int rangeQuery(long long int low, long long int high,
                         long long int pos, long long int l, long long int r) {
  if (low > high || l > high || r < low) {
    return -1e12;
  }
  if (lazy[pos] != 0) {
    tree[pos][0] = lazy[pos];
    if (low != high) {
      lazy[2 * pos] = lazy[pos];
      lazy[2 * pos + 1] = lazy[pos];
    }
    lazy[pos] = 0;
  }
  if (l <= low && high <= r) {
    return tree[pos][0];
  }
  long long int mid = (low + high) / 2;
  return max(rangeQuery(low, mid, 2 * pos, l, r),
             rangeQuery(mid + 1, high, 2 * pos + 1, l, r));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  g.resize(n + 1);
  for (long long int i = 1, x, y; i < n; i++) {
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  v.resize(n + 1);
  sub.resize(n + 1);
  dfs(1, 0);
  long long int q;
  cin >> q;
  long long int cnt = 0;
  for (long long int i = 0, tp, ind; i < q; i++) {
    cin >> tp >> ind;
    cnt++;
    if (tp == 1) {
      rangeUpdate(1, n, 1, v[ind], v[ind] + sub[ind] - 1, cnt);
    } else if (tp == 2) {
      pointUpdate(1, n, 1, v[ind], cnt);
    } else {
      if (pointQuery(1, n, 1, v[ind], v[ind] + sub[ind] - 1) >=
          rangeQuery(1, n, 1, v[ind], v[ind])) {
        cout << "0";
      } else {
        cout << "1";
      }
      cout << '\n';
    }
  }
  return 0;
}
