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.math.BigInteger;
import java.util.*;

import static java.util.Arrays.*;

public class D {
    private static final int mod = (int)1e9+9;

    final IOFast io = new IOFast();
    
    static class Seg1 {
        final int n;
        final int[] seg;
        final boolean[] lazy;
        
        public Seg1(final int n) {
            this.n = Integer.highestOneBit(n) << 1;
            seg = new int[this.n << 1];
            lazy = new boolean[this.n << 1];
        }

        void update(int l, int r, int v) { update(l, r, v, 0, 0, n); }
        void update(int l, int r, int v, int k, int curL, int curR) {
//          System.err.println(l + " " + r + " " + v + " " + k + " " + curL + " " + curR);
            if(curR <= l || curL >= r) return;
            if(l <= curL && curR <= r) { lazy[k] = true; seg[k] = v; return; }
            final int curM = (curL + curR) / 2;
            
            if(lazy[k]) {
                update(curL, curM, seg[k], 2 * k + 1, curL, curM);
                update(curM, curR, seg[k], 2 * k + 2, curM, curR);
                lazy[k] = false;
            }
            
            update(l, r, v, 2 * k + 1, curL, curM);
            update(l, r, v, 2 * k + 2, curM, curR);
        }
        
        int get(int i) {
            i += n - 1;
            int ret = seg[i];
            while(i != 0) {
                i = (i - 1) / 2;
                if(lazy[i]) { ret = seg[i]; }
            }
            return ret;
        }
    }
    
    static class Seg2 {
        final int n;
        final int[] seg;
        
        public Seg2(final int n) {
            this.n = Integer.highestOneBit(n) << 1;
            seg = new int[this.n << 1];
        }

        int get(int l, int r) { return get(l, r, 0, 0, n); }
        int get(int l, int r, int k, int curL, int curR) {
//          System.err.println(l + " " + r + " " + k + " " + curL + " " + curR);
            if(curR <= l || curL >= r) return 0;
            if(l <= curL && curR <= r) { return seg[k]; }
            final int curM = (curL + curR) / 2;
            return Math.max(
                    get(l, r, 2 * k + 1, curL, curM),
                    get(l, r, 2 * k + 2, curM, curR));
        }
        
        void update(int i, int v) {
            i += n - 1;
            seg[i] = v;
//          System.err.println("update: " + i + " " + v);
            while(i != 0) {
                i = (i - 1) / 2;
                seg[i] = Math.max(seg[2*i+1], seg[2*i+2]);
            }
        }
    }
    
    public void run() throws IOException {
        int n = io.nextInt();
        
        AdjListGraph g = new AdjListGraph(n, 2 * (n - 1));
        
        for(int i = 0; i < n - 1; i++) {
            final int a = io.nextInt() - 1;
            final int b = io.nextInt() - 1;
            g.addEdge(a, b);
            g.addEdge(b, a);
        }

        Seg1 seg1 = new Seg1(n);
        Seg2 seg2 = new Seg2(n);
        int[][] eulerTour = g.eulerTour(0);
//      System.err.println(Arrays.toString(eulerTour[0]));
//      System.err.println(Arrays.toString(eulerTour[1]));
        int q = io.nextInt();
        for(int i = 0; i < q; i++) {
            final int c = io.nextInt();
            final int t = io.nextInt() - 1;
//          System.err.println(c + " " + t);
            if(c == 1) { seg1.update(eulerTour[0][t], eulerTour[1][t], i + 1); }
            else if(c == 2) { seg2.update(eulerTour[0][t], i + 1); }
            else {
//              System.err.println("1: " + seg1.get(t));
//              System.err.println("2: " + seg2.get(eulerTour[0][t], eulerTour[1][t]));
                if(seg1.get(eulerTour[0][t]) <= seg2.get(eulerTour[0][t], eulerTour[1][t])) {
                    io.out.println(0);
                }
                else {
                    io.out.println(1);
                }
            }
        }
    }
    
    static
    class AdjListGraph {
        int m, V, E;
        int[] head, next, to;

        public AdjListGraph(int V, int E) {
            head = new int[V];
            next = new int[E];
            to = new int[E];
            this.V = V;
            this.E = E;
            clear();
        }

        public void clear(int v) {
            m = 0;
            for(int i = 0; i < v; i++) {
                head[i] = -1;
            }
        }

        public void clear() {
            m = 0;
            Arrays.fill(head, -1);
        }

        public void addEdge(int s, int t) {
            next[m] = head[s];
            head[s] = m;
            to[m++] = t;
        }
        
        // vi's subtree: [retval[0][i], retval[1][i])
        int[][] eulerTour(int root) {
            int idx = 0;
            int sp = 0;
            
            final int[] st = new int[V];
            final boolean[] vis = new boolean[V];
            
            int[] s = new int[V];
            int[] t = new int[V];
            st[sp++] = root;
            while(sp != 0) {
                final int v = st[--sp];
                if(vis[v]) {
                    t[v] = idx;
                    continue;
                }
                vis[v] = true;
                s[v] = idx++;
                st[sp++] = v;
                for(int e = head[v]; e != -1; e = next[e]) {
                    final int to = this.to[e];
                    if(!vis[to]) {
                        st[sp++] = to;
                    }
                }
            }
            return new int[][] { s, t, };
        }
    }
    
    void main() throws IOException {
        //      IOFast.setFileIO("rle-size.in", "rle-size.out");
        try {
            run();
        }
        catch (EndOfFileRuntimeException e) { }
        io.out.flush();
    }

    public static void main(String[] args) throws IOException {
        new D().main();
    }
    
    static class EndOfFileRuntimeException extends RuntimeException {
        private static final long serialVersionUID = -8565341110209207657L; }

    static
    public class IOFast {
        private BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        private PrintWriter out = new PrintWriter(System.out);

        void setFileIO(String ins, String outs) throws IOException {
            in = new BufferedReader(new FileReader(ins));
            out = new PrintWriter(new FileWriter(outs));
        }

        //      private static final int BUFFER_SIZE = 50 * 200000;
        private static int pos, readLen;
        private static final char[] buffer = new char[1024 * 8];
        private static final char[] str = new char[500000*8*2];
        private static boolean[] isDigit = new boolean[256];
        private static boolean[] isSpace = new boolean[256];
        private static boolean[] isLineSep = new boolean[256];

        static {
            for(int i = 0; i < 10; i++) { isDigit['0' + i] = true; }
            isDigit['-'] = true;
            isSpace[' '] = isSpace['\r'] = isSpace['\n'] = isSpace['\t'] = true;
            isLineSep['\r'] = isLineSep['\n'] = true;
        }

        public int read() throws IOException {
            if(pos >= readLen) {
                pos = 0;
                readLen = in.read(buffer);
                if(readLen <= 0) { throw new EndOfFileRuntimeException(); }
            }
            return buffer[pos++];
        }

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

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

        public char nextChar() throws IOException {
            while(true) {
                final int c = read();
                if(!isSpace[c]) { return (char)c; }
            }
        }
        
        int reads(char[] cs, int len, boolean[] accept) throws IOException {
            try {
                while(true) {
                    final int c = read();
                    if(accept[c]) { break; }
                    str[len++] = (char)c;
                }
            }
            catch(EndOfFileRuntimeException e) { ; }
            
            return len;
        }

        public char[] nextLine() throws IOException {
            int len = 0;
            str[len++] = nextChar();
            len = reads(str, len, isLineSep);
            
            try {
                if(str[len-1] == '\r') { len--; read(); }
            }
            catch(EndOfFileRuntimeException e) { ; }
            
            return Arrays.copyOf(str, len);
        }

        public String nextString() throws IOException {
            return new String(next());
        }

        public char[] next() throws IOException {
            int len = 0;
            str[len++] = nextChar();
            len = reads(str, len, isSpace);
            return Arrays.copyOf(str, len);
        }

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

    }

}
