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
/*
Keep solving problems. 
*/
import java.util.*;
import java.io.*;

public class CFA {

    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;
    final long MOD = 1000L * 1000L * 1000L + 7;
    int[] dx = {1, 2, 1, 1};
    int[] dy = {0, 0, -1, 1};

    int INDEX = 0;
    int tree[];
    boolean lazy[];

    /**
     * Increment elements within range [queryStartIndex, queryEndIndex] with value
     */
    void updateTree1(int node, int nodeStartIndex, int nodeEndIndex, int queryStartIndex, int queryEndIndex) {
        if(nodeStartIndex > queryEndIndex || nodeEndIndex < queryStartIndex) // Current segment is not within range [i, j]
            return;
        if(nodeStartIndex >= queryStartIndex && nodeEndIndex <= queryEndIndex) { // Segment is fully within range
            tree[node] = (nodeEndIndex - nodeStartIndex + 1);
            lazy[node] = true;
            return;
        }

        //-------------
        shift(node, nodeStartIndex, nodeEndIndex);
        //-------------
        updateTree1(node * 2, nodeStartIndex, (nodeStartIndex + nodeEndIndex) / 2, queryStartIndex, queryEndIndex); // Updating left child
        updateTree1(node * 2 + 1, (nodeStartIndex + nodeEndIndex) / 2 + 1, nodeEndIndex, queryStartIndex, queryEndIndex); // Updating right child

        tree[node] = tree[node * 2] + tree[node * 2 + 1]; // Updating root
    }

    /**
     * Increment elements within range [queryStartIndex, queryEndIndex] with value
     */
    void updateTree2(int node, int nodeStartIndex, int nodeEndIndex, int queryIndex) {
        if(nodeStartIndex > queryIndex || nodeEndIndex < queryIndex) // Current segment is not within range [i, j]
            return;
        if(nodeStartIndex >= queryIndex && nodeEndIndex <= queryIndex) { // Segment is fully within range
            tree[node] = 0;
            return;
        }

        //-------------
        shift(node, nodeStartIndex, nodeEndIndex);
        //-------------
        updateTree2(node * 2, nodeStartIndex, (nodeStartIndex + nodeEndIndex) / 2, queryIndex); // Updating left child
        updateTree2(node * 2 + 1, (nodeStartIndex + nodeEndIndex) / 2 + 1, nodeEndIndex, queryIndex); // Updating right child

        tree[node] = tree[node * 2] + tree[node * 2 + 1]; // Updating root
    }

    /**
     * Query tree to get max element value within range [queryStartIndex, queryEndIndex]
     */
    int query_tree(int node, int nodeStartIndex, int nodeEndIndex, int queryStartIndex, int queryEndIndex) {
        if(nodeStartIndex > queryEndIndex || nodeEndIndex < queryStartIndex) return 0; // Out of range
        if(nodeStartIndex >= queryStartIndex && nodeEndIndex <= queryEndIndex) // Current segment is totally within range [i, j]
            return tree[node];

        //-------------
        shift(node, nodeStartIndex, nodeEndIndex);
        //-------------

        int q1 = query_tree(node * 2, nodeStartIndex, (nodeStartIndex + nodeEndIndex) / 2, queryStartIndex, queryEndIndex); // Query left child
        int q2 = query_tree(1 + node * 2, (nodeStartIndex + nodeEndIndex) / 2 + 1, nodeEndIndex, queryStartIndex, queryEndIndex); // Query right child

        return q1 + q2;
    }

    private void shift(int node, int nodeStartIndex, int nodeEndIndex) {
        if(lazy[node]) { // This node needs to be updated

            int mid = (nodeStartIndex + nodeEndIndex) / 2;
            tree[2 * node] = mid - nodeStartIndex + 1;
            tree[2 * node + 1] = nodeEndIndex - mid;

            lazy[node * 2] = true; // Mark child as lazy
            lazy[node * 2 + 1] = true; // Mark child as lazy
            lazy[node] = false; // Reset it
        }
    }

    void solve() throws IOException {
        INDEX = 0;
        int n = nextInt();
        List<List<Integer>> child = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            child.add(new ArrayList<>());
        }

        for (int i = 0; i < n - 1; i++) {
            int a = nextInt() - 1;
            int b = nextInt() - 1;
            child.get(a).add(b);
            child.get(b).add(a);
        }

        int[] startIndex = new int[n];
        int[] endIndex = new int[n];
        int[] par = new int[n];
        dfs(child, 0, -1, startIndex, endIndex, par);

        int[] arr = new int[n];
        tree = new int[5 * arr.length];
        lazy = new boolean[5 * arr.length];

        //0 -> empty, 1 -> full
        int queries = nextInt();
        List<Integer> res = new ArrayList<>();
        for (int i = 0; i < queries; i++) {
            int q = nextInt();
            int v = nextInt() - 1;
            if (q == 1) { //fill v and all its children
                int sum = query_tree(1, 0, n - 1, startIndex[v], endIndex[v]);
                int cnt = endIndex[v] - startIndex[v] + 1;
                if (sum != cnt && par[v] != -1) {
                    updateTree2(1, 0, n - 1, startIndex[par[v]]);
                }

                updateTree1(1, 0, n - 1, startIndex[v], endIndex[v]); //make the range value to all ones.
            }
            else if (q == 2) { //empty v
                updateTree2(1, 0, n - 1, startIndex[v]); //make the point value to zero
            }
            else { //check
                int sum = query_tree(1, 0, n - 1, startIndex[v], endIndex[v]);
                int cnt = endIndex[v] - startIndex[v] + 1;
                if (sum < cnt) {
                    res.add(0);
                }
                else {
                    res.add(1);
                }
            }
        }

        for (int i = 0; i < res.size(); i++) {
            outln(res.get(i));
        }
    }

    void dfs(List<List<Integer>> child, int nodeIndex, int parent, int[] startIndex, int[] endIndex, int[] par) {
        startIndex[nodeIndex] = INDEX;
        INDEX++;
        par[nodeIndex] = parent;
        for (int nxt : child.get(nodeIndex)) {
            if (nxt == parent) {
                continue;
            }
            dfs(child, nxt, nodeIndex, startIndex, endIndex, par);
        }
        endIndex[nodeIndex] = INDEX - 1;
    }

    void shuffle(int[] a) {
        int n = a.length;
        for(int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            int tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }

    long gcd(long a, long b) {
        while(a != 0 && b != 0) {
            long c = b;
            b = a % b;
            a = c;
        }
        return a + b;
    }

    private void outln(Object o) {
        out.println(o);
    }
    private void out(Object o) {
        out.print(o);
    }
    public CFA() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }
    public static void main(String[] args) throws IOException {
        new CFA();
    }

    public long[] nextLongArr(int n) throws IOException{
        long[] res = new long[n];
        for(int i = 0; i < n; i++)
            res[i] = nextLong();
        return res;
    }
    public int[] nextIntArr(int n) throws IOException {
        int[] res = new int[n];
        for(int i = 0; i < n; i++)
            res[i] = nextInt();
        return res;
    }
    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }
    public String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}

