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.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DWaterTree solver = new DWaterTree();
        solver.solve(1, in, out);
        out.close();
    }

    static class DWaterTree {
        int MAXN = 500005;
        PrintWriter out;
        InputReader in;
        ArrayList<Integer>[] tree = new ArrayList[MAXN];
        int[] in_t = new int[MAXN];
        int[] out_t = new int[MAXN];
        int timer = 0;

        void dfs(int v, int p) {
            in_t[v] = timer++;
            for (int u : tree[v]) {
                if (u != p)
                    dfs(u, v);
            }
            out_t[v] = timer - 1;
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            int n = ni();
            int i = 0;
            for (i = 0; i < n; i++)
                tree[i] = new ArrayList<>();
            for (i = 0; i < n - 1; i++) {
                int u = ni() - 1;
                int v = ni() - 1;
                tree[u].add(v);
                tree[v].add(u);
            }
            dfs(0, -1);
            Segment_tree st1 = new Segment_tree(n);
            Segment_tree st2 = new Segment_tree(n);
            int q = ni();
            for (i = 0; i < q; i++) {
                int type = ni();
                if (type == 1) {
                    int v = ni() - 1;
                    st1.rangeupdate(in_t[v], out_t[v], i + 1);
                } else if (type == 2) {
                    int v = ni() - 1;
                    st2.rangeupdate(in_t[v], in_t[v], i + 1);
                } else {
                    int v = ni() - 1;
                    pn(st1.query(in_t[v], in_t[v]) > st2.query(in_t[v], out_t[v]) ? 1 : 0);
                }
            }
        }

        int ni() {
            return in.nextInt();
        }

        void pn(long zx) {
            out.println(zx);
        }

        class Segment_tree {
            long INF = (long) 1e14;
            long[] sum;
            long[] lazy;
            int n;

            Segment_tree(int x) {
                n = x;
                sum = new long[4 * n];
                lazy = new long[4 * n];
                Arrays.fill(lazy, -1);
                build(1, 0, n - 1);
            }

            void build(int node, int tl, int tr) {
                if (tl == tr) { // leaf{
                    sum[node] = 0;
                } else {
                    int mid = tl + tr >> 1, left = node * 2, right = left + 1;
                    build(left, tl, mid);
                    build(right, mid + 1, tr);
                    merge(node);
                }
            }

            long query(int l, int r) {
                return query(1, 0, n - 1, l, r);
            }

            long query(int node, int tl, int tr, int l, int r) {
                if (r < tl || tr < l)
                    return -INF;
                if (tl >= l && tr <= r)
                    return sum[node];
                if (lazy[node] != -1)
                    propagate(node);
                int mid = tl + tr >> 1, left = node * 2, right = left + 1;
                return Math.max(query(left, tl, mid, l, r), query(right, mid + 1, tr, l, r));
            }

            void merge(int node) {
                sum[node] = Math.max(sum[node << 1], sum[node << 1 | 1]);
            }

            void rangeupdate(int i, int j, long val) {
                rangeupdate(1, 0, n - 1, i, j, val);
            }

            void rangeupdate(int node, int tl, int tr, int l, int r, long val) {
                if (r < tl || tr < l) {
                    return;
                }
                if (tl >= l && tr <= r) {
                    sum[node] = val;
                    lazy[node] = val;
                } else {
                    int mid = tl + tr >> 1, left = node * 2, right = left + 1;
                    if (lazy[node] != -1)
                        propagate(node);
                    rangeupdate(left, tl, mid, l, r, val);
                    rangeupdate(right, mid + 1, tr, l, r, val);
                    merge(node);
                }
            }

            void propagate(int node) {
                lazy[node * 2] = lazy[node];
                lazy[node * 2 + 1] = lazy[node];
                sum[node * 2] = lazy[node];
                sum[node * 2 + 1] = lazy[node];
                lazy[node] = -1;
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new UnknownError();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

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

        public String next() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}

