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.*;
import java.util.*;
import java.math.*;
import java.lang.*;
 
import static java.lang.Math.*;

public class Main implements Runnable {
    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream) {
            this.stream = stream;
        }
        
        public int read() {
            if (numChars==-1) 
                throw new InputMismatchException();
            
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }
                
                if(numChars <= 0)               
                    return -1;
            }
            return buf[curChar++];
        }
     
        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();
            
            while(isSpaceChar(c)) 
                c = read();
            
            int sgn = 1;
            
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            
            int res = 0;
            do {
                if(c<'0'||c>'9') 
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c)); 
            
            return res * sgn;
        }
        
        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
                return res * sgn;
        }
        
        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }
        
        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } 
            while (!isSpaceChar(c));
            
            return res.toString();
        }
     
        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
     
        public String next() {
            return readString();
        }
        
        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
    public static void main(String args[]) throws Exception {
        new Thread(null, new Main(),"Main",1<<26).start();
    }
    int querySegTree(int low, int high, int pos, int[] segTree, int l, int r) {
        
        if(low > r || high < l)
            return 0;

        if(low >= l && high <= r)
            return segTree[pos];

        int mid = (low + high) >> 1;

        int val1 = querySegTree(low, mid, 2 * pos + 1, segTree, l, r);
        int val2 = querySegTree(mid + 1, high, 2 * pos + 2, segTree, l, r);

        return max(val1, val2);
    }
    int querySegTreeWithLazy(int low, int high, int pos, int[] segTree, int ind) {

        if(low != high) {
            lazy[2 * pos + 1] = max(lazy[2 * pos + 1], lazy[pos]);
            lazy[2 * pos + 2] = max(lazy[2 * pos + 2], lazy[pos]);
        }
        else
            segTree[low] = max(segTree[low], lazy[pos]);

        if(low == high)
            return segTree[low];

        int mid = (low + high) >> 1;

        if(ind > mid)
            return querySegTreeWithLazy(mid + 1, high, 2 * pos + 2, segTree, ind);
        else
            return querySegTreeWithLazy(low, mid, 2 * pos + 1, segTree, ind);
    }
    void updateSegTreeWithLazy(int low, int high, int pos, int[] segTree, int l, int r, int val) {

        if(low != high) {
            lazy[2 * pos + 1] = max(lazy[2 * pos + 1], lazy[pos]);
            lazy[2 * pos + 2] = max(lazy[2 * pos + 2], lazy[pos]);
        }
        else
            segTree[low] = max(segTree[low], lazy[pos]);

        if(low > r || high < l)
            return;

        if(low >= l && high <= r) {
            if(low != high) {
                lazy[2 * pos + 1] = val;
                lazy[2 * pos + 2] = val;
            }
            else
                segTree[low] = val;

            return;
        }

        int mid = (low + high) >> 1;

        updateSegTreeWithLazy(low, mid, 2 * pos + 1, segTree, l, r, val);
        updateSegTreeWithLazy(mid + 1, high, 2 * pos + 2, segTree, l, r, val);
    }

    void updateSegTree(int low, int high, int pos, int[] segTree, int ind, int val) {

        if(low > ind || high < ind)
            return;

        if(low == high) {
            segTree[pos] = val;
            return;
        }

        int mid = (low + high) >> 1;

        updateSegTree(low, mid, 2 * pos + 1, segTree, ind, val);
        updateSegTree(mid + 1, high, 2 * pos + 2, segTree, ind, val);

        segTree[pos] = max(segTree[2 * pos + 1], segTree[2 * pos + 2]);
    }

    void dfs(int i, int par) {
        
        startTime[i] = time++;

        for(int j : adj[i]) {

            if(j != par)
                dfs(j, i);
        }

        endTime[i] = time - 1;
    }

    ArrayList<Integer> adj[];
    int time = 0;
    int startTime[], endTime[];
    int lazy[];

    public void run() {
        InputReader sc = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);

        int n = sc.nextInt();
        
        adj = new ArrayList[n];
        for(int i = 0; i < n; ++i)
            adj[i] = new ArrayList<>();

        for(int i = 0; i < n - 1; ++i) {
            
            int u = sc.nextInt() - 1;
            int v = sc.nextInt() - 1;

            adj[u].add(v);
            adj[v].add(u);
        }

        startTime = new int[n];
        endTime = new int[n];
        dfs(0, -1);

        int q = sc.nextInt();

        int[] segTree = new int[4 * n];
        int[] segTreeLazy = new int[n];
        lazy = new int[4 * n];

        for(int x = 0; x < q; ++x) {

            int type = sc.nextInt();
            int v = sc.nextInt() - 1;

            if(type == 1) 
                updateSegTreeWithLazy(0, n - 1, 0, segTreeLazy, startTime[v], endTime[v], x + 1);
            else if(type == 2) 
                updateSegTree(0, n - 1, 0, segTree, startTime[v], x + 1);
            else {

                int val1 = querySegTreeWithLazy(0, n - 1, 0, segTreeLazy, startTime[v]);
                int val2 = querySegTree(0, n - 1, 0, segTree, startTime[v], endTime[v]);

                if(val2 >= val1)
                    w.println("0");
                else
                    w.println("1");
            }
        }

        w.close();      
    }
}