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;

public class D343 {
	
	class SegmentTree {
		int n, N;
		int[] max, lazy;
		int[] l, r;
		SegmentTree(int nn) {
			n = nn;
			N = 4 * n + 1;
			max = new int[N];
			lazy = new int[N];
			l = new int[N];
			r = new int[N];
			init(1, 0, n - 1);
		}
		void init(int node, int ll, int rr) {
			l[node] = ll; r[node] = rr;
			if(ll == rr) {
				return;
			}
			int mid = ll + rr >> 1;
			init(node * 2, ll, mid);
			init(node * 2 + 1, mid + 1, rr);
		}
		void push(int node) {
			if(lazy[node] == 0) return;
			lazy[node * 2] = lazy[node * 2 + 1] = lazy[node];
			lazy[node] = 0;
		}
		int get(int node) {
			if(lazy[node] == 0) return max[node];
			return lazy[node];
		}
		void set(int node, int ll, int rr, int val) {
			if(r[node] < ll || l[node] > rr) return;
			if(ll <= l[node] && r[node] <= rr) {
				lazy[node] = val;
				return;
			}
			push(node);
			set(node * 2, ll, rr, val);
			set(node * 2 + 1, ll, rr, val);
			max[node] = Math.max(get(node * 2), get(node * 2 + 1));
		}
		int getMax(int node, int ll, int rr) {
			if(r[node] < ll || l[node] > rr) return 0;
			if(ll <= l[node] && r[node] <= rr) return get(node);
			push(node);
			return Math.max(getMax(node * 2, ll, rr), getMax(node * 2 + 1, ll, rr));
		}
	}
	
	ArrayList<Integer>[] vs;
	
	int[] first, last;
	int idx = 0;
	void dfs(int node, int par) {
		first[node] = idx++;
		for(int i : vs[node]) if(i != par) {
			dfs(i, node);
		}
		last[node] = idx - 1;
	}
	
	public void solve(JS in, PrintWriter out) {
		int n = in.nextInt();
		vs = new ArrayList[n];
		for(int i = 0; i < n; ++i) vs[i] = new ArrayList<>();
		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);
		}
		first = new int[n];
		last = new int[n];
		dfs(0, -1);
		SegmentTree empty = new SegmentTree(n);
		SegmentTree fill = new SegmentTree(n);
		int q = in.nextInt();
		for(int time = 1; time <= q; ++time) {
			int type = in.nextInt();
			int v = in.nextInt() - 1;
			if(type == 1) {
				fill.set(1, first[v], last[v], time);
			} else if(type == 2) {
				empty.set(1, first[v], first[v], time);
			} else {
				int lastFill = fill.getMax(1, first[v], first[v]);
				int lastEmpty = empty.getMax(1, first[v], last[v]);
				if(lastFill > lastEmpty) out.println(1);
				else out.println(0);
			}
		}
	}
	
	public static void main(String[] args) {
		JS in = new JS();
		PrintWriter out = new PrintWriter(System.out);
		new D343().solve(in, out);
		out.close();
	}
	
	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;
			}
		}
	}

}
