#include <bits/stdc++.h>
namespace fastIO {
bool IOerror = 0;
inline char nc() {
  static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000;
  if (p1 == pend) {
    p1 = buf;
    pend = buf + fread(buf, 1, 100000, stdin);
    if (pend == p1) {
      IOerror = 1;
      return -1;
    }
  }
  return *p1++;
}
inline bool blank(char ch) {
  return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
}
template <class T>
inline bool read(T& x) {
  bool sign = 0;
  char ch = nc();
  x = 0;
  for (; blank(ch); ch = nc())
    ;
  if (IOerror) return false;
  if (ch == '-') sign = 1, ch = nc();
  for (; ch >= '0' && ch <= '9'; ch = nc()) x = x * 10 + ch - '0';
  if (sign) x = -x;
  return true;
}
inline bool read(double& x) {
  bool sign = 0;
  char ch = nc();
  x = 0;
  for (; blank(ch); ch = nc())
    ;
  if (IOerror) return false;
  if (ch == '-') sign = 1, ch = nc();
  for (; ch >= '0' && ch <= '9'; ch = nc()) x = x * 10 + ch - '0';
  if (ch == '.') {
    double tmp = 1;
    ch = nc();
    for (; ch >= '0' && ch <= '9'; ch = nc())
      tmp /= 10.0, x += tmp * (ch - '0');
  }
  if (sign) x = -x;
  return true;
}
inline bool read(char* s) {
  char ch = nc();
  for (; blank(ch); ch = nc())
    ;
  if (IOerror) return false;
  for (; !blank(ch) && !IOerror; ch = nc()) *s++ = ch;
  *s = 0;
  return true;
}
inline bool read(char& c) {
  for (c = nc(); blank(c); c = nc())
    ;
  if (IOerror) {
    c = -1;
    return false;
  }
  return true;
}
template <class T, class... U>
bool read(T& h, U&... t) {
  return read(h) && read(t...);
}
template <typename T>
void out(T x) {
  char s[65];
  int32_t cnt = 0;
  if (x > 0)
    while (x > 0) s[cnt++] = (x - (x / 10 * 10)) + '0', x /= 10;
  else if (x < 0) {
    while (x < 0) s[cnt++] = (x / 10 * 10) - x + '0', x /= 10;
    s[cnt++] = '-';
  }
  if (cnt == 0)
    putchar('0');
  else
    for (int32_t i = cnt - 1; ~i; i--) putchar(s[i]);
}
template <typename T>
void print(T x) {
  out(x);
  putchar('\n');
}
template <typename T, typename... types>
void print(T x, types... oth) {
  out(x);
  putchar(' ');
  print(oth...);
}
}  // namespace fastIO
using namespace std;
const int32_t MAXN = 1e6 + 5;
namespace TCP {
int _N, TC_ROOT;
int eCnt, head[MAXN], nex[MAXN << 1], to[MAXN << 1];
long long w[MAXN], wt[MAXN];
int son[MAXN], id[MAXN], fa[MAXN], dfsCnt, dep[MAXN], siz[MAXN], top[MAXN];
inline void add(int x, int y) {
  to[++eCnt] = y;
  nex[eCnt] = head[x];
  head[x] = eCnt;
}
template <typename T>
inline void swap(T& a, T& b) {
  T c = a;
  a = b;
  b = c;
}
long long sum[MAXN << 2];
long long lazy[MAXN << 2];
void push_up(int rt) { sum[rt] = sum[rt << 1] + sum[rt << 1 | 1]; }
void build(int l, int r, int rt) {
  lazy[rt] = -1;
  if (l == r) {
    sum[rt] = wt[l];
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, rt << 1);
  build(mid + 1, r, rt << 1 | 1);
  push_up(rt);
}
void push_down(int l, int r, int rt) {
  if (~lazy[rt]) {
    int mid = (l + r) >> 1;
    sum[rt << 1] = (mid - l + 1) * lazy[rt];
    sum[rt << 1 | 1] = (r - mid) * lazy[rt];
    lazy[rt << 1] = lazy[rt];
    lazy[rt << 1 | 1] = lazy[rt];
    lazy[rt] = -1;
  }
}
void update(int L, int R, long long c, int l, int r, int rt) {
  if (L <= l && r <= R) {
    sum[rt] = c * (r - l + 1);
    lazy[rt] = c;
    return;
  }
  int mid = (l + r) >> 1;
  push_down(l, r, rt);
  if (L <= mid) update(L, R, c, l, mid, rt << 1);
  if (R >= mid + 1) update(L, R, c, mid + 1, r, rt << 1 | 1);
  push_up(rt);
}
long long query(int L, int R, int l, int r, int rt) {
  long long res = 0;
  if (L <= l && r <= R) {
    return sum[rt];
  }
  int mid = (l + r) >> 1;
  push_down(l, r, rt);
  if (L <= mid) res += query(L, R, l, mid, rt << 1);
  if (R >= mid + 1) res += query(L, R, mid + 1, r, rt << 1 | 1);
  return res;
}
inline long long qRange(int x, int y) {
  long long ans = 0;
  while (top[x] != top[y]) {
    if (dep[top[x]] < dep[top[y]]) swap(x, y);
    ans += query(id[top[x]], id[x], 1, _N, 1);
    x = fa[top[x]];
  }
  if (dep[x] > dep[y]) swap(x, y);
  ans += query(id[x], id[y], 1, _N, 1);
  return ans;
}
inline void updRange(int x, int y, long long k) {
  while (top[x] != top[y]) {
    if (dep[top[x]] < dep[top[y]]) swap(x, y);
    update(id[top[x]], id[x], k, 1, _N, 1);
    x = fa[top[x]];
  }
  if (dep[x] > dep[y]) swap(x, y);
  update(id[x], id[y], k, 1, _N, 1);
}
inline void dfs1(int x, int f, int deep) {
  dep[x] = deep;
  fa[x] = f;
  siz[x] = 1;
  int maxson = -1;
  for (int i = head[x]; i; i = nex[i]) {
    int y = to[i];
    if (y == f) continue;
    dfs1(y, x, deep + 1);
    siz[x] += siz[y];
    if (siz[y] > maxson) son[x] = y, maxson = siz[y];
  }
}
inline void dfs2(int x, int topf) {
  id[x] = ++dfsCnt;
  wt[dfsCnt] = w[x];
  top[x] = topf;
  if (!son[x]) return;
  dfs2(son[x], topf);
  for (int i = head[x]; i; i = nex[i]) {
    int y = to[i];
    if (y == fa[x] || y == son[x]) continue;
    dfs2(y, y);
  }
}
inline void init(int n, int root) {
  _N = n;
  TC_ROOT = 1;
  eCnt = 0;
  memset(head, 0, sizeof(head));
  dfsCnt = 0;
  memset(son, 0, sizeof(son));
}
}  // namespace TCP
int32_t main() {
  int n;
  fastIO::read(n);
  TCP::init(n, 1);
  for (int i = 1; i < n; i++) {
    int u, v;
    fastIO::read(u, v);
    TCP::add(u, v);
    TCP::add(v, u);
  }
  TCP::dfs1(1, -1, 1);
  TCP::dfs2(1, 1);
  TCP::build(1, n, 1);
  int m;
  fastIO::read(m);
  while (m--) {
    int op = -1;
    fastIO::read(op);
    int x;
    fastIO::read(x);
    if (op == 1) {
      TCP::update(TCP::id[x], TCP::id[x] + TCP::siz[x] - 1, 1, 1, n, 1);
    } else if (op == 2) {
      TCP::updRange(1, x, 0);
    } else {
      fastIO::print(TCP::qRange(x, x));
    }
  }
  return 0;
}
