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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Solution{
	
	static ArrayList<Integer>[] g;
	static int[] trail, start, end;
	static int[] par;
	static int timer=0;
	
	
    public static void main(String[] args) throws IOException {
    	
		
    	FastScanner fs = new FastScanner();
    	PrintWriter out = new PrintWriter(System.out);
    		
    	int tt = 1;
    	while(tt-->0) {

    		int n = fs.nextInt();
    		g = new ArrayList[n];
    		
    		for(int i=0;i<n;i++) g[i] = new ArrayList<Integer>();
    		
    		for(int i=0;i<n-1;i++) {
    			int u = fs.nextInt()-1, v = fs.nextInt()-1;
    			g[u].add(v);
    			g[v].add(u);
    		}
    		
    		trail = new int[n];
    		start = new int[n];
    		end = new int[n];
    		par = new int[n];
    		
    		Arrays.fill(trail, 1);
    		
    		dfs(0, -1);
    		
    		SegTree tree = new SegTree(n);
    		tree.build(trail);
    		
    		int q = fs.nextInt();
    		
    		while(q-->0) {
    			int t = fs.nextInt();
    			if(t==1) {
    				int v = fs.nextInt()-1;
    				if(tree.query(start[v], end[v])>0 && par[v]!=-1) {
    					tree.update(start[par[v]], 1);
    				}
    				tree.lazyupdate(start[v], end[v]);
    			}
    			else if(t==2) {
    				int v = fs.nextInt()-1;
    				tree.update(start[v], 1);
    			}
    			else {
    				int v = fs.nextInt()-1;
    				if(tree.query(start[v], end[v])>0) {
    					out.println(0);
    				}
    				else {
    					out.println(1);
    				}
    			}
    		}
    		
    		
    		
    		
    		
    		
    		
    		
    		
    	}
    	
    	out.close();
    		
    	
    	
    }
    
   
    static void dfs(int v,int p) {
    	par[v] = p;
    	start[v] = timer;
    	timer++;
    	for(int u: g[v]) {
    		if(u==p) continue;
    		dfs(u, v);
    	}
    	end[v] = timer-1;
    }
    
    
    static class SegTree{
    	int[] tree;
    	boolean[] lazy;
    	int n;
    	
    	SegTree(int n){
    		tree = new int[4*n];
    		lazy = new boolean[4*n];
    		this.n = n;
    	}
    	
    	void build(int[] a) {
    		buildTree(a, 0, n-1, 0);
    	}
    	
    	void buildTree(int[] a, int ns, int ne, int node) {
    		if(ns==ne) {
    			tree[node] = a[ns];
    			return;
    		}
    		int mid = (ns+ne)/2;
    		buildTree(a, ns, mid, 2*node+1);
    		buildTree(a, mid+1, ne, 2*node+2);
    		tree[node] = tree[2*node+1] + tree[2*node+2];
    	}
    	
    	void propagate(int ns, int ne, int node) {
    		tree[node] = 0;
    		lazy[node] = false;
    		if(ns!=ne) {
    			lazy[2*node+1] = true;
    			lazy[2*node+2] = true;
    		}
    	}
    	
    	void lazyupdate(int qs, int qe) {
    		lazyupdateTree(qs, qe, 0, n-1, 0);
    	}
    	
    	void lazyupdateTree(int qs, int qe, int ns, int ne, int node) {
    		if(lazy[node]) propagate(ns, ne, node);
    		if(ns>qe || ne<qs) return;
    		if(ns>=qs && ne<=qe) {
    			tree[node] = 0;
    			if(ns!=ne) {
    				lazy[2*node+1] = true;
    				lazy[2*node+2] = true;
    			}
    			return;
    		}
    		int mid = (ns+ne)/2;
    		lazyupdateTree(qs, qe, ns, mid, 2*node+1);
    		lazyupdateTree(qs, qe, mid+1, ne, 2*node+2);
    		tree[node] = tree[2*node+1] + tree[2*node+2];
    	}
    	
    	void update(int ind, int val) {
    		updateTree(ind, val, 0, n-1, 0);
    	}
    	
    	void updateTree(int ind, int val, int ns,int ne, int node) {
    		if(lazy[node]) propagate(ns, ne, node);
    		if(ind<ns || ind>ne) return;
    		if(ns==ne) {
    			tree[node] = val;
    			return;
    		}
    		int mid = (ns+ne)/2;
    		updateTree(ind, val, ns, mid, 2*node+1);
    		updateTree(ind, val, mid+1, ne, 2*node+2);
    		tree[node] = tree[2*node+1] + tree[2*node+2];
    	}
    	
    	int query(int qs, int qe) {
    		return queryTree(qs, qe, 0, n-1, 0);
    	}
    	
    	int queryTree(int qs, int qe, int ns, int ne, int node	) {
    		if(lazy[node]) propagate(ns, ne, node);
    		if(ns>qe || ne<qs) return 0;
    		if(ns>=qs && ne<=qe) return tree[node];
    		int mid = (ns+ne)/2;
    		return queryTree(qs, qe, ns, mid, 2*node+1) + queryTree(qs, qe, mid+1, ne, 2*node+2);
    	}
    	
    }
    
    
    static final Random random=new Random();
    
    static <T> void shuffle(T[] arr) {
    	int n = arr.length;
    	for(int i=0;i<n;i++	) {
    		int k = random.nextInt(n);
    		T temp = arr[k]; arr[k] = arr[i]; arr[i] = temp;
    	}
    }
    
    	
    static void ruffleSort(int[] a) {
    	int n=a.length;//shuffle, then sort 
    	for (int i=0; i<n; i++) {
    		int oi=random.nextInt(n); int temp=a[oi];
    		a[oi]=a[i]; a[i]=temp;
    	}
    	Arrays.sort(a);
    }
    
    static void ruffleSort(long[] a) {
    	int n=a.length;//shuffle, then sort 
    	for (int i=0; i<n; i++) {
    		int oi=random.nextInt(n); long temp=a[oi];
    		a[oi]=a[i]; a[i]=temp;
    	}
    	Arrays.sort(a);
    }
   
  
    
    static void reverse(int[] arr, int l, int r) {
    	for(int i=l;i<l+(r-l)/2;i++){
    		int temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;
    	}
    }
    
    static void reverse(long[] arr, int l, int r) {
    	for(int i=l;i<l+(r-l)/2;i++){
    		long temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;
    	}
    }
    
    
    static <T> void reverse(T[] arr, int l, int r) {
    	for(int i=l;i<l+(r-l)/2;i++) {
    		T temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;
    	}
    }
    	
    	
    static class FastScanner{
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	StringTokenizer st = new StringTokenizer("");
     
    	public String next(){
    		while(!st.hasMoreElements()){
    			try{
    				st = new StringTokenizer(br.readLine());
    			} catch(IOException e){
    				e.printStackTrace();
    			}
    		}
    		return st.nextToken();
    	}
    		
    	public String nextLine() throws IOException {
    		return br.readLine();
    	}
    		
    	public int nextInt(){
    		return Integer.parseInt(next());
    	}
     
    	public int[] readArray(int n){
    		int[] a = new int[n];
    		for(int i=0;i<n;i++)
    			a[i] = nextInt();
    		return a;
    	}
    		
    	public long nextLong() {
    		return Long.parseLong(next());
    	}
    		
    	public char nextChar() {
    		return next().toCharArray()[0];
    	}
    }
   	
}
