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
import java.util.*;
import java.math.*;
import java.io.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class Hello {
  static ArrayList<Integer> a[] = new ArrayList[2300000];
  static int din[] = new int[600000];
  static int dout[] = new int[600000];
  
  static int tree1[] = new int[2300000];
  static int tree2[] = new int[2300000];
  static int cnt = 0;
  static int sz = 0;

  public static void DFS(int n, int prev)
  {
    din[n] = ++cnt;
    for (int v:a[n]) {
      if (v == prev) continue;
      DFS(v, n);
    }
    dout[n] = cnt;
  }
  public static void update1(int node, int l, int r, int s, int e, int x)
  {
    //System.out.print("node:"+node+" ");
    //System.out.print("l:"+l+" ");
    //System.out.print("r:"+r+" ");
    //System.out.print("s:"+s+" ");
    //System.out.print("e:"+e+" ");
    //System.out.print("x:"+x+"\n");
    if (s <= l && e >= r) {
      tree1[node] = x;
      return;
    }
    if (e < l || s > r) return;
    int mid = (l + r) / 2;
    update1(node * 2    , l, mid, s, e, x);
    update1(node * 2 + 1, mid + 1, r, s, e, x);
  }
  public static int query1(int e)
  {
    int i = sz + e - 1;
    int ans = 0;
    while (i > 0) {
      ans = Math.max(tree1[i], ans);
      i /= 2;
    }
    return ans;
  }
  public static void update2(int s, int x)
  {
    int i = sz + s - 1;
    while (i > 0) {
      tree2[i] = x;
      i /= 2;
    }
  }
  public static int query2(int node, int l, int r, int s, int e)
  {
    if (s <= l && e >= r) {
      return tree2[node];
    }
    if (e < l || s > r) return -1;
    int mid = (l + r) / 2;
    int ans1 = query2(node * 2    , l, mid, s, e);
    int ans2 = query2(node * 2 + 1, mid + 1, r, s, e);
    return Math.max(ans1, ans2);
  }

  public static void main(String[] args) {
    try {
      MScanner in = new MScanner(System.in);
      BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out, "UTF-8"));
      //FastReader in = new FastReader(System.in);

      int n = in.nextInt();
      for (int i = 0;i <= n;++i) {
        a[i] = new ArrayList<Integer>();
      }
      for (int i = 1;i <= n - 1;++i) {
        int i1 = in.nextInt();
        int i2 = in.nextInt();
        a[i1].add(i2);
        a[i2].add(i1);
      }
      DFS(1, 0);

      sz = 1;
      while (sz < n) sz *= 2;

      int q = in.nextInt();
      for (int i = 1;i <= q;++i) {
        int type = in.nextInt();
        int v = in.nextInt();

        if (type == 1) {
          update1(1, 1, sz, din[v], dout[v], i);
        } else if (type == 2) {
          update2(din[v], i);
        } else if (type == 3) {
          int res1 = query1(din[v]);
          int res2 = query2(1, 1, sz, din[v], dout[v]);
          if (res1 == 0 && res2 == 0) {
            out.write("0\n");
            continue;
          }
          if (res1 > res2) out.write("1\n");
          else out.write("0\n");
        }
      }
      out.flush();
      out.close();


    } catch (Exception e) {
      e.printStackTrace();
      //System.out.print(e);
      System.exit(0);
    }
  }
}

class MScanner {
  StringTokenizer st;
  BufferedReader br;
  public MScanner(InputStream system) {
    br = new BufferedReader(new InputStreamReader(system));
  }

  public MScanner(String file) throws Exception {
    br = new BufferedReader(new FileReader(file));
  }

  public String next() throws IOException {
    while (st == null || !st.hasMoreTokens())
      st = new StringTokenizer(br.readLine());
    return st.nextToken();
  }
  public int[] takearr(int n) throws IOException {
    int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
    return in;
  }
  public long[] takearrl(int n) throws IOException {
    long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
    return in;
  }
  public Integer[] takearrobj(int n) throws IOException {
    Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
    return in;
  }
  public Long[] takearrlobj(int n) throws IOException {
    Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
    return in;
  }
  public String nextLine() throws IOException {
    return br.readLine();
  }

  public int nextInt() throws IOException {
    return Integer.parseInt(next());
  }

  public double nextDouble() throws IOException {
    return Double.parseDouble(next());
  }

  public char nextChar() throws IOException {
    return next().charAt(0);
  }

  public Long nextLong() throws IOException {
    return Long.parseLong(next());
  }

  public boolean ready() throws IOException {
    return br.ready();
  }

  public void waitForInput() throws InterruptedException {
    Thread.sleep(3000);
  }
}
