#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500005;
int n, dfn[MAXN], dfsn, bn, bq;
int beg[MAXN], fin[MAXN];
vector<int> v[MAXN];
struct QUERY {
  int type, v, time;
};
vector<QUERY> query[MAXN];
void dfs(int x, int par) {
  dfn[x] = beg[x] = fin[x] = ++dfsn;
  for (auto &y : v[x]) {
    if (y == par) continue;
    dfs(y, x);
    fin[x] = max(fin[x], fin[y]);
  }
}
int bit[4 * MAXN];
vector<int> mt[4 * MAXN];
void go(int x, int par) {
  for (auto &t : query[x]) {
    if (t.type == 2) {
      mt[bn + dfn[x]].push_back(t.time);
    }
  }
  for (auto &y : v[x]) {
    if (y == par) continue;
    go(y, x);
  }
}
int ans[MAXN];
void upd(int x, int y) {
  while (x) {
    bit[x] += y;
    x /= 2;
  }
}
int sum(int l, int r) {
  int ret = 0;
  while (l <= r) {
    if (l == r) {
      ret += bit[l];
      break;
    }
    if (l & 1) ret += bit[l++];
    if (!(r & 1)) ret += bit[r--];
    l /= 2;
    r /= 2;
  }
  return ret;
}
int fnd(int x, int y) {
  int l = 0, r = mt[x].size() - 1, mid, val, ret = -1;
  while (l <= r) {
    mid = (l + r) / 2;
    val = mt[x][mid];
    if (val < y) {
      ret = max(ret, val);
      l = mid + 1;
    } else
      r = mid - 1;
  }
  return ret;
}
void f(int x, int par) {
  for (auto &t : query[x]) {
    if (t.type == 1) {
      upd(bq + t.time, 1);
    }
  }
  for (auto &t : query[x]) {
    if (t.type == 3) {
      int nt = t.time, t1 = -1, t2 = -1;
      {
        int l = bn + beg[x], r = bn + fin[x];
        while (l <= r) {
          if (l == r) {
            t2 = max(t2, fnd(l, nt));
            break;
          }
          if (l & 1) {
            t2 = max(t2, fnd(l, nt));
            l++;
          }
          if (!(r & 1)) {
            t2 = max(t2, fnd(r, nt));
            r--;
          }
          l /= 2;
          r /= 2;
        }
      }
      {
        int l = 1, r = nt - 1, md;
        while (l <= r) {
          md = (l + r) / 2;
          int s = sum(bq + md, bq + nt);
          if (s > 0) {
            t1 = max(t1, md);
            l = md + 1;
          } else
            r = md - 1;
        }
      }
      if (t1 == -1 || (t1 < t2))
        ans[nt] = 0;
      else
        ans[nt] = 1;
    }
  }
  for (auto &y : v[x]) {
    if (y == par) continue;
    f(y, x);
  }
  for (auto &t : query[x]) {
    if (t.type == 1) {
      upd(bq + t.time, -1);
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs(1, 0);
  int Q;
  scanf("%d", &Q);
  vector<int> ask;
  for (int q = 1; q <= Q; q++) {
    int a, b;
    scanf("%d%d", &a, &b);
    if (a == 1) query[b].push_back({1, b, q});
    if (a == 2) query[b].push_back({2, b, q});
    if (a == 3) query[b].push_back({3, b, q}), ask.push_back(q);
  }
  bn = 1;
  while (bn < n) bn *= 2;
  bn--;
  bq = 1;
  while (bq < Q) bq *= 2;
  bq--;
  go(1, 0);
  for (int i = bn + 1; i <= bn + n; i++) sort(mt[i].begin(), mt[i].end());
  for (int i = bn; i >= 1; i--) {
    auto &L = mt[i * 2];
    auto &R = mt[i * 2 + 1];
    int lp = 0, rp = 0;
    while (lp < L.size() && rp < R.size()) {
      if (L[lp] < R[rp])
        mt[i].push_back(L[lp++]);
      else
        mt[i].push_back(R[rp++]);
    }
    while (lp < L.size()) mt[i].push_back(L[lp++]);
    while (rp < R.size()) mt[i].push_back(R[rp++]);
  }
  f(1, 0);
  for (auto &t : ask) printf("%d\n", ans[t]);
}
