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.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.Arrays;


public class Main {
    static StreamTokenizer in=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));  
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));  
      
    public static int nextInt()throws IOException {in.nextToken();return (int)in.nval;}  
    public static long nextLong()throws IOException {in.nextToken(); return (long)in.nval;}
    public static String next()throws IOException {in.nextToken();return (String)in.sval;}

    static int[] jin = new int[500100], chu = new int[500100], f = new int[500100];
    static arr[] a = new arr[500100];
    static int num = 0;
    static node root;
    
    public static void main(String[] args) throws IOException {
    	int n = nextInt();
    	int x, y;
    	for (int i = 0; i <= n; i++)
    		a[i] = new arr();
    	for (int i = 1; i < n; i++) {
    		x = nextInt();
    		y = nextInt();
    		a[x].add(y);
    		a[y].add(x);
    	}
    	dfs(1, 0);
    	root = new node();
    	build(root, 1, n);
    	int q = nextInt();
    	for (int i = 0; i < q; i++) {
    		x = nextInt(); y = nextInt();
    		if (x == 1)  {
    			int v = query(root, 1, n, jin[y], chu[y]);
    			updata(root, 1, n, jin[y], chu[y], 1);
    			if (f[y] != 0 && v == 0) 
    				updata(root, 1, n, jin[f[y]], jin[f[y]], 0);
    		}
    		else if (x == 2) 
    			updata(root, 1, n, jin[y], jin[y], 0);
    		else 
    			out.println(query(root, 1, n, jin[y], chu[y]));
    	}
    	out.flush();
    	out.close();
    }
    public static int query(node now, int l, int r, int ql, int qr) {
    	if (l >= ql && r <= qr) 
    		return now.p;
    	if (now.lazy != -1) {
    		now.left.p = now.lazy;
    		now.right.p = now.lazy;
    		now.left.lazy = now.lazy;
    		now.right.lazy = now.lazy;
    		now.lazy = -1;
    	}
    	int p = 1;
    	int mid = (l + r) >> 1;
    	if (ql <= mid)
    		p = Math.min(p, query(now.left, l, mid, ql, qr));
    	if (qr > mid)
    		p = Math.min(p, query(now.right, mid + 1, r, ql, qr));
    	return p;
    }
    public static void updata(node now, int l, int r, int ql, int qr, int p) {
    	if (l >= ql && r <= qr) {
    		now.lazy = p;
    		now.p = p;
    		return;
    	}
    	if (now.lazy != -1) {
    		now.left.p = now.lazy;
    		now.right.p = now.lazy;
    		now.left.lazy = now.lazy;
    		now.right.lazy = now.lazy;
    		now.lazy = -1;
    	}
    	int mid = (l + r) >> 1;
    	if (ql <= mid)
    		updata(now.left, l, mid, ql, qr, p);
    	if (qr > mid)
    		updata(now.right, mid + 1, r, ql, qr, p);
    	now.p = Math.min(now.left.p, now.right.p);
    }
    public static void build(node now, int l, int r) {
    	if (l == r)
    		return;
    	now.left = new node();
    	now.right = new node();
    	int mid = (l + r) >> 1;
    	build(now.left, l, mid);
    	build(now.right, mid + 1, r);
    }
    public static void dfs(int now, int from) {
    	num++;
    	jin[now] = num;
    	f[now] = from;
    	for (int i = 0; i < a[now].size(); i++) {
    		int x = a[now].get(i);
    		if (x != from) 
    			dfs(x, now);
    	}
    	chu[now] = num;
    }
}
class node{
	node left, right;
	int p, lazy;
	public node(){
		p = 0;
		lazy = -1;
	}
}
class arr{
	ArrayList<Integer> a;
	public arr() {
		a = new ArrayList<Integer>();
	}
	public void add(int x) {
		a.add(x);
	}
	public int get(int x) { 
		return a.get(x);
	}
	public int size() {
		return a.size();
	}
}