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.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;

public class D343_2 {

	int n;
	IntList[] vs;
	int[] first, last;
	int idx = 0;
	
	void dfs(int node, int par) {
		first[node] = idx++;
		for(int j = 0; j < vs[node].size(); ++j) {
			int i = vs[node].get(j);
			if(i != par) {
				dfs(i, node);
			}
		}
		last[node] = idx - 1;
	}
	
	public void solve(JS in, PrintWriter out) {
		n = in.nextInt();
		first = new int[n];
		last = new int[n];
		vs = new IntList[n];
		for(int i = 0; i < n; ++i) vs[i] = new IntList();
		for(int i = 0; i < n - 1; ++i) {
			int u = in.nextInt() - 1;
			int v = in.nextInt() - 1;
			vs[u].add(v);
			vs[v].add(u);
		}
		dfs(0, -1);
		Node filled = new Node(0, n - 1);
		Node empty = new Node(0, n - 1);
		int q = in.nextInt();
		for(int time = 1; time <= q; ++time) {
			int type = in.nextInt();
			int node = in.nextInt() - 1;
			if(type == 1) {
				filled.fill(first[node], last[node], time);
			} else if(type == 2) {
				empty.fill(first[node], first[node], time);
			} else {
				int lastEmpty = empty.query(first[node], last[node]);
				int lastFilled = filled.query(first[node], first[node]);
				out.println(lastFilled > lastEmpty ? 1 : 0);
			}
		}
	}
	
	class Node {
		int l, r;
		Node left, right;
		
		int max, lazy;
		
		Node(int ll, int rr) {
			l = ll; r = rr; lazy = -1;
			if(l == r) return;
			int m = l + r >> 1;
			left = new Node(ll, m);
			right = new Node(m + 1, rr);
		}
		
		int get() {
			if(lazy != -1) return lazy;
			return max;
		}
		
		void push() {
			if(lazy == -1) return;
			max = lazy;
			left.lazy = right.lazy = lazy;
			lazy = -1;
		}
		
		void fill(int ll, int rr, int x) {
			if(rr < l || ll > r) return;
			if(ll <= l && r <= rr) {
				lazy = x;
				return;
			}
			push();
			left.fill(ll, rr, x);
			right.fill(ll, rr, x);
			max = Math.max(left.get(), right.get());
		}
		
		int query(int ll, int rr) {
			if(rr < l || ll > r) return -1;
			if(ll <= l && r <= rr) return get();
			push();
			return Math.max(left.query(ll, rr), right.query(ll, rr));
		}
	}
	
	public static void main(String[] args) {
		JS in = new JS();
		PrintWriter out = new PrintWriter(System.out);
		new D343_2().solve(in, out);
		out.close();
	}
	
	static class IntList {
		static int[] EMPTY = {};
		int n = 0, a[] = EMPTY;
		void add(int v) {
			if (n >= a.length)
				a = Arrays.copyOf(a, (n << 2) + 8);
			a[n++] = v;
		}
		int get(int idx) { return a[idx]; }
		int size() { return n; }
	}
	
	static class JS {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public JS() {
			in = new BufferedInputStream(System.in, BS);
		}

		public JS(String s) throws FileNotFoundException {
			in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
	}
}