Mad scientist Mike has constructed a rooted tree, which consists of n vertices. Each vertex is a reservoir which can be either empty or filled with water.

The vertices of the tree are numbered from 1 to n with the root at vertex 1. For each vertex, the reservoirs of its children are located below the reservoir of this vertex, and the vertex is connected with each of the children by a pipe through which water can flow downwards.

Mike wants to do the following operations with the tree: 

  1. Fill vertex v with water. Then v and all its children are filled with water. 
  2. Empty vertex v. Then v and all its ancestors are emptied. 
  3. Determine whether vertex v is filled with water at the moment. 

Initially all vertices of the tree are empty.

Mike has already compiled a full list of operations that he wants to perform in order. Before experimenting with the tree Mike decided to run the list through a simulation. Help Mike determine what results will he get after performing all the operations.

Input

The first line of the input contains an integer n (1 ≤ n ≤ 500000) — the number of vertices in the tree. Each of the following n - 1 lines contains two space-separated numbers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — the edges of the tree.

The next line contains a number q (1 ≤ q ≤ 500000) — the number of operations to perform. Each of the following q lines contains two space-separated numbers ci (1 ≤ ci ≤ 3), vi (1 ≤ vi ≤ n), where ci is the operation type (according to the numbering given in the statement), and vi is the vertex on which the operation is performed.

It is guaranteed that the given graph is a tree.

Output

For each type 3 operation print 1 on a separate line if the vertex is full, and 0 if the vertex is empty. Print the answers to queries in the order in which the queries are given in the input.

Examples

Input

5
1 2
5 1
2 3
4 2
12
1 1
2 3
3 1
3 2
3 3
3 4
1 2
2 4
3 1
3 3
3 4
3 5


Output

0
0
0
1
0
1
0
1
#include <bits/stdc++.h>
namespace myland {
using namespace std;
namespace _abbr {}
using namespace _abbr;
namespace _constant {
const double EPS(1e-8);
const double PI(acos(-1.0));
const int INF(0x3f3f3f3f);
const long long INFL(0x3f3f3f3f3f3f3f3fll);
const int MOD(1e9 + 7);
const int dx[] = {-1, 0, 1, 0, -1, 1, 1, -1},
          dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
}  // namespace _constant
using namespace _constant;
namespace _solve {}
using namespace _solve;
namespace _calculate {
bool odd(long long x) { return x & 1; }
bool even(long long x) { return (x & 1) ^ 1; }
bool posi(long long x) { return x > 0; }
bool nega(long long x) { return x < 0; }
bool zero(long long x) { return x == 0; }
bool prime(long long x) {
  if (x < 2) return 0;
  for (int i = 2; i * i <= x; i++)
    if (x % i == 0) return 0;
  return 1;
}
long long droot(long long x) { return 1 + (x - 1) % 9; }
long long upd(long long a, long long b) { return a % b ? a / b + 1 : a / b; };
long long random(long long a, long long b) {
  return a + rand() * rand() % (b - a + 1);
};
long long bitn(long long x) {
  long long c = 0;
  while (x) c++, x >>= 1;
  return c;
}
template <class T>
T sqr(T x) {
  return x * x;
}
long long qpow(long long a, long long n, long long mod = MOD) {
  long long res(1);
  while (n) {
    if (n & 1) (res *= a) %= mod;
    (a *= a) %= mod;
    n >>= 1;
  }
  return res % mod;
}
long long inv(long long a, long long mod = MOD) { return qpow(a, mod - 2); }
template <class T>
void tomin(T& a, T b) {
  if (b < a) a = b;
}
template <class T>
void tomax(T& a, T b) {
  if (b > a) a = b;
}
}  // namespace _calculate
using namespace _calculate;
namespace _simple_algo {
long long sol(const string& s) {
  long long x = 0;
  for (char c : s) x = x * 10 + c - 48;
  return x;
}
string los(long long x) {
  string s = "";
  if (x == 0) return "0";
  while (x) s = char(x % 10 + 48) + s, x /= 10;
  return s;
}
bool pal(const string& s) {
  int l = s.size();
  for (int i = 0, j = l - 1; i < j; i++, j--)
    if (s[i] != s[j]) return 0;
  return 1;
}
}  // namespace _simple_algo
using namespace _simple_algo;
namespace _io {
template <class T>
void rd(T& x) {
  cin >> x;
}
string srd() {
  string s;
  cin >> s;
  return s;
}
long long rd() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
void rd(int& x) { x = rd(); }
void rd(long long& x) { x = rd(); }
template <class A, class B>
void rd(pair<A, B>& p) {
  cin >> p.first >> p.second;
}
template <class A, class B>
void rd(A& a, B& b) {
  rd(a), rd(b);
}
template <class A, class B, class C>
void rd(A& a, B& b, C& c) {
  rd(a, b);
  rd(c);
}
template <class T>
void wt(const T& x) {
  cout << x << endl;
}
template <class T>
void wt(const T& x, char c) {
  cout << x << c;
}
template <class T>
void wt(const T& x, const string& s) {
  cout << x << s;
}
template <class T>
void wt(const T& x, int rnd) {
  cout << fixed << setprecision(rnd) << x << endl;
}
template <class T>
void wt(const vector<T>& v) {
  for (T x : v) wt(x, ' ');
  wt("");
}
template <class A, class B>
void wt(const pair<A, B>& make_pair) {
  cout << make_pair.first << ' ' << make_pair.second << endl;
}
}  // namespace _io
using namespace _io;
}  // namespace myland
using namespace myland;
const int N = 5e5 + 5;
struct segt {
  struct seg {
    int l, r;
    bool tag, col;
  };
  seg t[N << 2];
  void push_up(int x) {
    if (t[x << 1].tag && t[x << 1 | 1].tag &&
        t[x << 1].col == t[x << 1 | 1].col) {
      t[x].tag = 1;
      t[x].col = t[x << 1].col;
    } else {
      t[x].tag = 0;
    }
  }
  void push_down(int x) {
    if (t[x].tag) {
      t[x << 1].tag = t[x << 1 | 1].tag = 1;
      t[x << 1].col = t[x << 1 | 1].col = t[x].col;
    }
  }
  void build(int x, int l, int r) {
    t[x] = seg({l, r, 1, 0});
    if (l == r) return;
    build(x << 1, l, ((t[x].l + t[x].r) / 2));
    build(x << 1 | 1, ((t[x].l + t[x].r) / 2) + 1, r);
  }
  void update(int x, int l, int r, bool v) {
    int L = t[x].l, R = t[x].r;
    if (l <= L && R <= r) {
      t[x].col = v;
      t[x].tag = 1;
      return;
    }
    push_down(x);
    if (l <= ((t[x].l + t[x].r) / 2)) update(x << 1, l, r, v);
    if (r > ((t[x].l + t[x].r) / 2)) update(x << 1 | 1, l, r, v);
    push_up(x);
  }
  bool query(int x, int p) {
    if (t[x].tag) return t[x].col;
    push_down(x);
    if (p <= ((t[x].l + t[x].r) / 2))
      return query(x << 1, p);
    else
      return query(x << 1 | 1, p);
  }
};
struct e {
  int v, nxt;
};
int n(rd()), u, v, op, p;
int idx(1), head[N];
e edge[N << 1];
int fa[N], son[N], siz[N], top[N], pos_idx, pos[N], lsp[N];
segt T;
void dfs1(int u) {
  siz[u] = 1;
  son[u] = -1;
  for (int i = head[u]; i; i = edge[i].nxt) {
    int v = edge[i].v;
    if (v == fa[u]) continue;
    fa[v] = u;
    dfs1(v);
    siz[u] += siz[v];
    if (son[u] == -1 || siz[v] > siz[son[u]]) son[u] = v;
  }
}
void dfs2(int u, int top_idx) {
  lsp[u] = pos[u] = ++pos_idx;
  top[u] = top_idx;
  if (son[u] != -1) dfs2(son[u], top[u]), lsp[u] = lsp[son[u]];
  for (int i = head[u]; i; i = edge[i].nxt) {
    int v = edge[i].v;
    if (v != fa[u] && v != son[u]) dfs2(v, v), lsp[u] = lsp[v];
  }
}
void update(int p) {
  int f = top[p];
  while (f) {
    T.update(1, pos[f], pos[p], 0);
    p = fa[f];
    f = top[p];
  }
}
int main() {
  for (int cas = 1, tms = (n - 1); cas <= tms; cas++) {
    rd(u, v);
    edge[idx] = e({v, head[u]});
    head[u] = idx++;
    edge[idx] = e({u, head[v]});
    head[v] = idx++;
  }
  dfs1(1);
  dfs2(1, 1);
  T.build(1, 1, n);
  for (int cas = 1, tms = (rd()); cas <= tms; cas++) {
    rd(op, p);
    if (op == 1)
      T.update(1, pos[p], lsp[p], 1);
    else if (op == 2)
      update(p);
    else
      wt(T.query(1, pos[p]));
  }
}
