#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
inline void R(int &x) {
  char ch = getchar();
  x = 0;
  for (; ch != '-' && (ch < '0' || ch > '9'); ch = getchar())
    ;
  for (; ch <= '9' && ch >= '0'; ch = getchar()) x = x * 10 + ch - '0';
}
const int sz = 1048577, N = 500005, M = 1000005, inf = (1 << 30) - 1;
int n, m, s[N], e[M], h[M], nes = 0, cr, lst[N];
bool v[N];
struct node {
  int key, h, segn, segws, segwe, f, size;
} a[N];
int csegn, csegw;
struct SegTree {
  struct segnode {
    int skey;
    bool set;
  } a[sz];
  int tsz, tlv;
  inline void SK(int x, int key) { a[x].set = true, a[x].skey = key; }
  inline void Down(int x) {
    if (a[x].set) {
      SK(x << 1, a[x].skey);
      SK((x << 1) | 1, a[x].skey);
      a[x].set = false;
    }
  }
  inline void TgDown(int s, int e) {
    for (int lv = tlv; lv; --lv) {
      Down(s >> lv);
      if ((s >> lv) != (e >> lv)) Down(e >> lv);
    }
  }
  inline void init(int n) {
    for (++n, tsz = 1, tlv = 0; tsz <= n; tsz <<= 1, ++tlv)
      ;
  }
  inline void B() {}
  inline void C(int s, int e, int key) {
    if (s > e) swap(s, e);
    s = (s | tsz) - 1, e = (e | tsz) + 1;
    TgDown(s, e);
    for (; (s ^ e) > 1; s >>= 1, e >>= 1) {
      if (!(s & 1)) SK(s ^ 1, key);
      if (e & 1) SK(e ^ 1, key);
    }
  }
  inline int at(int w) {
    w |= tsz;
    for (int i = tlv; i; --i) Down(w >> i);
    return a[w].skey;
  }
} T;
struct Seg {
  int st, ed, f;
} S[N];
inline void pre(int x) {
  v[x] = true;
  a[x].size = 1;
  for (int w = s[x]; w; w = h[w])
    if (!v[e[w]]) {
      a[e[w]].f = x, a[e[w]].h = a[x].h + 1;
      pre(e[w]);
      a[x].size += a[e[w]].size;
    }
}
inline void dfs(int x) {
  v[x] = false;
  a[x].segn = csegn, a[x].segws = ++csegw;
  lst[csegw] = x;
  int mxw = 0;
  for (int w = s[x]; w; w = h[w])
    if (v[e[w]] && a[e[w]].size > a[mxw].size) mxw = e[w];
  if (mxw) {
    dfs(mxw);
    for (int w = s[x]; w; w = h[w])
      if (v[e[w]]) dfs(e[w]);
  } else {
    S[csegn].ed = csegw, ++csegn, S[csegn].st = csegw + 1;
  }
  a[x].segwe = csegw;
}
inline void BuildPath() {
  T.init(n);
  a[1].h = 1;
  pre(1);
  csegn = 1, csegw = 0;
  S[1].st = 1;
  dfs(1);
  T.B();
  for (int i = 1; i <= n; ++i)
    if (a[i].segws == S[a[i].segn].st) S[a[i].segn].f = a[i].f;
  --csegn;
}
inline void Change(int x, int y, int key) {
  int sx, sy;
  while (a[x].segn != a[y].segn) {
    sx = a[x].segn, sy = a[y].segn;
    if (a[S[sx].f].h > a[S[sy].f].h) {
      T.C(S[sx].st, a[x].segws, key);
      x = S[sx].f;
    } else {
      T.C(S[sy].st, a[y].segws, key);
      y = S[sy].f;
    }
  }
  T.C(a[x].segws, a[y].segws, key);
}
int main() {
  R(n);
  int x, y;
  for (int i = 1; i < n; ++i) {
    R(x);
    R(y);
    ++nes, e[nes] = y, h[nes] = s[x], s[x] = nes;
    ++nes, e[nes] = x, h[nes] = s[y], s[y] = nes;
  }
  for (int i = 1; i <= n; ++i) a[i].key = 0;
  BuildPath();
  R(m);
  int t;
  while (m--) {
    R(t);
    if (t == 1) {
      R(x);
      T.C(a[x].segws, a[x].segwe, 1);
    } else if (t == 2) {
      R(x);
      Change(1, x, 0);
    } else if (t == 3) {
      R(x);
      printf("%d\n", T.at(a[x].segws));
    }
  }
  return 0;
}
