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.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.InputMismatchException;

public class D343 {

	static class Solver {

		int ind = 0;

		void dfs(int n, int p) {
			l[n] = r[n] = ind++;
			for (int i : adj[n]) {
				if (i == p)
					continue;
				dfs(i, n);
				r[n] = r[i];
			}
		}

		int ans(int v, int t) {
			int emptied = root.emptied(l[v], r[v]);
			int filled = root.get(l[v]);
//			System.err.printf("Node %d: [%d, %d] emptied %d filled %d%n", v, l[v], r[v], emptied, filled);
			return filled > emptied ? 1 : 0;
		}

		void fill(int v, int t) {
//			System.err.printf("Filling %d: [%d, %d] time %d%n", v, l[v], r[v], t);
			root.fillrange(l[v], r[v], t);
		}

		void empty(int v, int t) {
//			System.err.printf("Emptying %d: [%d] time %d%n", v, l[v], t);
			root.empty(l[v], t);
		}

		int N, Q, l[], r[];
		ArrayList<Integer>[] adj;
		Node root;

		@SuppressWarnings("unchecked")
		void solve(FastScanner s, PrintWriter out) {
			N = s.nextInt();
			adj = new ArrayList[N];
			for (int i = 0; i < N; i++)
				adj[i] = new ArrayList<>();
			for (int i = 1; i < N; i++) {
				int u = s.nextInt() - 1, v = s.nextInt() - 1;
				adj[u].add(v);
				adj[v].add(u);
			}
			l = new int[N];
			r = new int[N];
			dfs(0, -1);
//			System.err.println(Arrays.toString(l));
//			System.err.println(Arrays.toString(r));
			root = new Node(0, N - 1);
			Q = s.nextInt();
			for (int q = 1; q <= Q; q++) {
				int c = s.nextInt(), v = s.nextInt() - 1;
				if (c == 1)
					fill(v, q);
				else if (c == 2)
					empty(v, q);
				else
					out.println(ans(v, q));
			}
		}

		class Node {

			int l, m, r;
			int emp, f;
			Node L, R;

			Node(int ll, int rr) {
				l = ll;
				r = rr;
				m = l + (r - l) / 2;
				emp = -1;
				f = -1;
				if (ll == rr)
					return;
				L = new Node(l, m);
				R = new Node(m + 1, r);
			}

			void push() {
				if (f != -1) {
					L.fillrange(l, r, f);
					R.fillrange(l, r, f);
				}
				f = -1;
			}

			void fillrange(int s, int e, int t) {
//				System.err.printf("Node [%d,%d] fill from [%d,%d] at t=%d%n", l, r, s, e, t);
				if (s <= l && r <= e) {
					f = t;
					return;
				}
//				System.err.println("(pushing)");
				push();
				if (s <= m)
					L.fillrange(s, e, t);
				if (m < e)
					R.fillrange(s, e, t);
			}

			int get(int x) {
//				System.err.printf(" -> getting Node [%d,%d] f=%d%n", l, r, f);
				if (l == r && l == x)
					return f;
				push();
				if (x <= m)
					return L.get(x);
				return R.get(x);
			}

			void empty(int x, int t) {
				if (l == r && l == x) {
					emp = t;
					return;
				}
				if (x <= m)
					L.empty(x, t);
				else
					R.empty(x, t);
				emp = max(L.emp, R.emp);
			}

			int emptied(int s, int e) {
				if (s <= l && r <= e) {
					return emp;
				}
				int mx = -1;
				if (s <= m)
					mx = max(mx, L.emptied(s, e));
				if (m < e)
					mx = max(mx, R.emptied(s, e));
				return mx;
			}

		}

	}

	static int max(int a, int b) {
		return a > b ? a : b;
	}

	public static void main(String[] args) {

		FastScanner s = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		Solver solver = new Solver();
		solver.solve(s, out);

		out.close();

	}

	static class FastScanner {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastScanner(InputStream stream) {
			this.stream = stream;
		}

		public FastScanner(File f) throws FileNotFoundException {
			this(new FileInputStream(f));
		}

		public FastScanner(String s) {
			this.stream = new ByteArrayInputStream(s.getBytes(StandardCharsets.UTF_8));
		}

		int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

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

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}

		// Jacob Garbage

		public int[] nextIntArray(int N) {
			int[] ret = new int[N];
			for (int i = 0; i < N; i++)
				ret[i] = this.nextInt();
			return ret;
		}

		public int[][] next2DIntArray(int N, int M) {
			int[][] ret = new int[N][];
			for (int i = 0; i < N; i++)
				ret[i] = this.nextIntArray(M);
			return ret;
		}

		public long[] nextLongArray(int N) {
			long[] ret = new long[N];
			for (int i = 0; i < N; i++)
				ret[i] = this.nextLong();
			return ret;
		}

		public long[][] next2DLongArray(int N, int M) {
			long[][] ret = new long[N][];
			for (int i = 0; i < N; i++)
				ret[i] = nextLongArray(M);
			return ret;
		}

		public double[] nextDoubleArray(int N) {
			double[] ret = new double[N];
			for (int i = 0; i < N; i++)
				ret[i] = this.nextDouble();
			return ret;
		}

		public double[][] next2DDoubleArray(int N, int M) {
			double[][] ret = new double[N][];
			for (int i = 0; i < N; i++)
				ret[i] = this.nextDoubleArray(M);
			return ret;
		}

	}

}