#include <bits/stdc++.h>
using namespace std;
double PI = acos(-1);
double EPS = 1e-7;
int INF = 1000000000;
int MOD = 1000000007;
int MAXINT = 2147483647;
long long INFLL = 1000000000000000000LL;
long long MAXLL = 9223372036854775807LL;
vector<int> adj[500005];
int st[500005], en[500005];
int par[500005];
int seg[2000005];
bool rem[2000005];
int co = 0;
void go(int pos, int prev) {
  st[pos] = ++co;
  for (int(a) = (0); (a) <= ((int)adj[pos].size() - 1); (a)++) {
    int nx = adj[pos][a];
    if (nx != prev) {
      go(nx, pos);
      par[nx] = pos;
    }
  }
  en[pos] = co;
}
int build(int n = 1, int l = 1, int r = co) {
  if (l == r) return seg[n] = 1;
  int m = (l + r) / 2;
  return seg[n] = build(2 * n, l, m) + build(2 * n + 1, m + 1, r);
}
int val(int n) {
  if (rem[n])
    return 0;
  else
    return seg[n];
}
void update(int v, int n = 1, int l = 1, int r = co) {
  if (l == r) {
    seg[n] |= 1;
    rem[n] = 0;
    return;
  }
  if (rem[n]) {
    rem[2 * n] = rem[2 * n + 1] = 1;
    rem[n] = 0;
  }
  int m = (l + r) / 2;
  if (v <= m)
    update(v, 2 * n, l, m);
  else
    update(v, 2 * n + 1, m + 1, r);
  seg[n] = val(2 * n) + val(2 * n + 1);
}
void clean(int fl, int fr, int n = 1, int l = 1, int r = co) {
  if (fr < l || fl > r || fl > fr) return;
  if (fl <= l && r <= fr) {
    rem[n] = 1;
    return;
  }
  if (rem[n]) {
    rem[2 * n] = rem[2 * n + 1] = 1;
    rem[n] = 0;
  }
  int m = (l + r) / 2;
  clean(fl, fr, 2 * n, l, m);
  clean(fl, fr, 2 * n + 1, m + 1, r);
  seg[n] = val(2 * n) + val(2 * n + 1);
}
int query(int fl, int fr, int n = 1, int l = 1, int r = co) {
  if (fr < l || fl > r || fl > fr) return 0;
  if (fl <= l && r <= fr) {
    return val(n);
  }
  if (rem[n]) {
    rem[2 * n] = rem[2 * n + 1] = 1;
    rem[n] = 0;
  }
  int m = (l + r) / 2;
  int tmp = query(fl, fr, 2 * n, l, m) + query(fl, fr, 2 * n + 1, m + 1, r);
  seg[n] = val(2 * n) + val(2 * n + 1);
  return tmp;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int(a) = (1); (a) <= (n - 1); (a)++) {
    int u, v;
    scanf("%d%d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  go(1, -1);
  build();
  int q;
  scanf("%d", &q);
  while (q--) {
    int t, v;
    scanf("%d%d", &t, &v);
    if (t == 1) {
      if (query(st[v], en[v])) {
        clean(st[v], en[v]);
        if (v != 1) {
          update(st[par[v]]);
        }
      } else
        clean(st[v], en[v]);
    } else if (t == 2) {
      update(st[v]);
    } else if (t == 3) {
      if (query(st[v], en[v]))
        puts("0");
      else
        puts("1");
    }
  }
}
