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.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.lang.Math;

public class Main {
    public static void main(String[] args) throws Exception {
        //InputStream in = new FileInputStream(new File("input.txt"));
        TaskD taskD = new TaskD(System.in, System.out);
        //TaskD taskD = new TaskD(in, System.out);
        taskD.process();
    }
}

class Tree {
    private int n;
    private int dfsPointer;
    private int[] st;
    private int[] ed;
    private int[] dest;
    private int[] next;
    private int[] ft;
    private int e;
    Tree(int n) {
        this.n = n;
        this.dfsPointer = 0;
        st = new int[n + 1];
        ed = new int[n + 1];
        Arrays.fill(st, 0);
        e = 0;
        ft = new int[n + 1];
        dest = new int[(n + 1) << 1];
        next = new int[(n + 1) << 1];
        Arrays.fill(ft, -1);
    }
    
    public void addEdge(int u, int v) {
        dest[e] = v;
        next[e] = ft[u];
        ft[u] = e++;
    }
    
    public void traversal() {
        dfs(1);
    }
    
    private void dfs(Integer u) {
        st[u] = ++dfsPointer;
        for (int i = ft[u]; i != -1; i = next[i]) {
            int  v = dest[i];
            if (st[v] == 0)
                dfs(v);
        }
        ed[u] = dfsPointer;
    }
    
    public int getSt(int u) {
        return st[u];
    }
    
    public int getEd(int u) {
        return ed[u];
    }
    
    public int getN() {
        return n;
    }
}

class SegTree {
    //public static int depth = 0;
    public class Node {
        private Node lc;
        private Node rc;
        private int l, r, fil, del;
        Node(int l, int r) {
            this.l = l;
            this.r = r;
            if (l < r) {
                int mid = getMid();
                lc = new Node(l, mid);
                rc = new Node(mid + 1, r);
            }
        }
        
        public void toMaxFil(int fil) {
            if (this.fil < fil)
                this.fil = fil;
        }
        
        public void toMaxDel(int del) {
            if (this.del < del)
                this.del = del;
        }
        
        public int getFil() {
            return this.fil;
        }
        
        public int getDel() {
            return this.del;
        }
        
        public int getMid() {
            return (this.r + this.l) >> 1;
        }
        
        public boolean isLeaf() {
            return this.r == this.l;
        }
        
        boolean isEqual(int l, int r) {
            return (this.l == l && this.r == r);
        }
        
        public Node getLeftChild() {
            return lc;
        }
        
        public Node getRightChild() {
            return rc;
        }
        
        public void downFil() {
            this.lc.toMaxFil(this.fil);
            this.rc.toMaxFil(this.fil);
        }
        
        /*
        public void show() {
            System.out.println("this node is ( " + this.l + " , " + this.r + " )");
        }
        */
    }
    
    private Node root;
    
    SegTree(int len) {
        root = new Node(1, len);
    }
    
    public Node getRoot() {
        return this.root;
    }
    
    public void filSeg (Node node, int l, int r, int seq) throws Exception {
        if (node.isEqual(l, r)) 
            node.toMaxFil(seq);
        else {
            node.downFil();
            int mid = node.getMid();
            if (r <= mid)
                filSeg(node.lc, l, r, seq);
            else if (l > mid)
                filSeg(node.rc, l, r, seq);
            else{
                filSeg(node.getLeftChild(), l, mid, seq);
                filSeg(node.getRightChild(), mid + 1, r, seq);
            }
        }
    }
    
    public void updateDel (Node node, int pos, int seq) {
        node.toMaxDel(seq);
        if (!node.isLeaf()) {
            node.downFil();
            int mid = node.getMid();
            if (pos <= mid)
                updateDel(node.getLeftChild(), pos, seq);
            else
                updateDel(node.getRightChild(), pos, seq);
        }
    }
    
    public int readFil(Node node, int pos) {
        if (node.isLeaf())
            return node.getFil();
        else {
            node.downFil();
            int mid = node.getMid();
            if (pos <= mid)
                return readFil(node.getLeftChild(), pos);
            else
                return readFil(node.getRightChild(), pos);
        }
    }
    
    public int readDel(Node node, int l, int r) {
        if (node.isEqual(l, r)) 
            return node.getDel();
        else {
            node.downFil();
            int mid = node.getMid();
            if (r <= mid)
                return readDel(node.getLeftChild(), l, r);
            else if (l > mid)
                return readDel(node.getRightChild(), l, r);
            else
                return Math.max(readDel(node.getLeftChild(), l, mid), readDel(node.getRightChild(), mid + 1, r));
        }
    }
}

class TaskD {
    //private InputStream inputStream = null;
    //private PrintStream printStream = null;
    private PrintWriter printWriter = null;
    Tree tree = null;
    //Scanner scanner = null;
    InputReaderPetre inputReaderPetre= null;
    
    TaskD(InputStream inputStream, PrintStream printStream) {
        //this.inputStream = inputStream;
        this.printWriter = new PrintWriter(printStream);
        this.inputReaderPetre = new InputReaderPetre(inputStream);
    }
    
    public void process() throws Exception {
        //scanner = new Scanner(inputStream);
        //int n = scanner.nextInt();
        int n = inputReaderPetre.nextInt();
        tree = new Tree(n);
        
        for (int i = 1; i < n; i++) {
            //int u = scanner.nextInt();
            //int v = scanner.nextInt();
            int u = inputReaderPetre.nextInt();
            int v = inputReaderPetre.nextInt();
            tree.addEdge(u, v);
            tree.addEdge(v, u);
        }
        
        tree.traversal();
        /*
        for (int i = 1; i <= n; i++)
            System.out.println("node : " + i + "\t( " + tree.getSt(i) + " , " + tree.getEd(i) + " )");
        */
        SegTree segTree = new SegTree(n);
        
        //int q = scanner.nextInt();
        int q = inputReaderPetre.nextInt();
        for (int i = 1; i <= q; i++) {
            //int optType = scanner.nextInt();
            //Integer u = new Integer(scanner.nextInt());
            int optType = inputReaderPetre.nextInt();
            int u = inputReaderPetre.nextInt();
            int stPos = tree.getSt(u);
            int edPos = tree.getEd(u);
            SegTree.Node root = segTree.getRoot();
            if (optType == 1) 
                segTree.filSeg(root, stPos, edPos, i);
            else if (optType == 2) 
                segTree.updateDel(root, stPos, i);
            else
                printWriter.println(segTree.readFil(root, stPos) > segTree.readDel(root, stPos, edPos) ? 1 : 0);
        }
        printWriter.close();
    }
}


class InputReaderPetre {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReaderPetre(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

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

}
