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.util.*;
import java.io.*;
import java.math.BigInteger;
 
/**
 *
 * @author usquare
 *
 */

public class ProblemA {
 
    public static int mod = (int) (1e9+7);
    public static InputReader in;
    public static PrintWriter out;
    public static ArrayList<Integer>[] g;
    public static int[] start;
    public static int[] end;
    public static int[] level;
    public static int[] par;
    public static int time;
    
    public static class SegmentTree {
        long st[];
        long lazy[];
 
        SegmentTree(int n)  {
            st = new long[4*n];
            lazy = new long[4*n];
            build(0, n - 1, 1);
        }
        
        public int getMid(int s, int e) {
            return (s+e)>>1;
        }

        public void lazyupdate(int ss,int ee,int si){
            if(lazy[si]!=-1){
                if(ss!=ee){
                    lazy[2*si]=lazy[si];
                    lazy[2*si+1]=lazy[si];
                }
                st[si]=lazy[si];
                lazy[si]=-1;
            }
        }

        public long merge(long a,long b){
            return a+b;
        }
        
        public void update(int s, int e, int x, int y, long c, int si){
            if(s == x && e == y){
                lazy[si]=c;
            }
            else{
                lazyupdate(s, e, si);
                int mid = getMid(s, e);
                if(y <= mid)    
                    update(s, mid, x, y, c, 2*si);
                else if(x > mid)
                    update(mid + 1, e, x ,y ,c ,2*si + 1);
                else{
                    update(s, mid, x, mid, c, 2*si);
                    update(mid + 1, e, mid + 1, y, c, 2*si + 1);
                }
                lazyupdate(s, mid, 2*si);
                lazyupdate(mid + 1, e, 2*si + 1);
                st[si]=merge(st[2*si],st[2*si+1]);
            }
        }

        public long  get(int s, int e, int x, int y, int si){

            lazyupdate(s, e,si);
            if(s == x && e == y){
                return st[si];
            }
            int mid = getMid(s, e);
            if(y <= mid)
                return get(s, mid, x, y, 2*si);
            else if(x > mid)
                return get(mid + 1, e, x, y, 2*si + 1);
            return merge(get(s, mid, x, mid, 2*si), get(mid + 1, e, mid + 1, y, 2*si + 1));
        }

        public void build(int ss, int se, int si){
            if (ss == se) {
                st[si] = 1;
                lazy[si]=-1;
                return;
            }

            int mid = getMid(ss, se);
            build(ss, mid, si * 2 );
            build(mid + 1, se, si * 2 + 1);
            lazy[si]=-1;
            st[si]=merge(st[2*si],st[2*si+1]);
        }
        
    }
    
    public static void dfs(int u,int p){
        start[u]=time++;
        par[u]=p;
        for(int v:g[u]){
            if(v==p) continue;
            level[v]=1+level[u];
            dfs(v, u);
        }
        
        end[u]=time-1;
    }
    
    public static void main(String[] args) throws FileNotFoundException {
 
        in = new InputReader(System.in);
        out = new PrintWriter(System.out);            
        
        int n=in.nextInt();

        g=new ArrayList[n];
        start=new int[n];
        end=new int[n];
        level=new int[n];
        par=new int[n];
        
        for(int i=0;i<n;i++) g[i]=new ArrayList<>();
        
        for(int i=0;i<n-1;i++){
            int u=in.nextInt()-1;
            int v=in.nextInt()-1;
            g[u].add(v);
            g[v].add(u);
        }
        time=0;
        dfs(0, 0);
        
        SegmentTree segmentTree=new SegmentTree(time);
        
        int q=in.nextInt();
        while(q-->0){
            int t=in.nextInt();
            int v=in.nextInt()-1;
            if(t==1){
                long x=segmentTree.get(0, time-1, start[v], end[v], 1);
                if(x>0 && v!=0)  segmentTree.update(0, time-1, start[par[v]], start[par[v]], 1, 1);
                segmentTree.update(0, time-1, start[v], end[v], 0, 1);
            }
            else if(t==2){
                segmentTree.update(0, time-1, start[v], start[v], 1, 1);
            }
            else{
                long x=segmentTree.get(0, time-1, start[v], end[v], 1);
                out.println(x>0?0:1);
            }
        }
        
        out.close();
    }
    
    static class Pair implements Comparable<Pair>{
 
        long x;
        int y,i;
        
	Pair (long x,int y,int i){
		this.x=x;
		this.y=y;
		this.i=i;
	}
 
	Pair (int x,int y){
		this.x=x;
		this.y=y;
	}
        
	public int compareTo(Pair o) {
                    return Long.compare(this.i,o.i);
		//return 0;
	}
 
        public boolean equals(Object o) {
            if (o instanceof Pair) {
                Pair p = (Pair)o;
                return p.x == x && p.y == y && p.i==i;
            }
            return false;
        }
    
        public int hashCode() {
            return new Long(x).hashCode() * 31 + new Long(y).hashCode()+new Long(i).hashCode()*37;
        }
 
        @Override
        public String toString() {
            return x+" "+y+" "+i;
        }
        
    } 
    public static class Merge {
        
        public static void sort(int inputArr[]) {
            int length = inputArr.length;
            doMergeSort(inputArr,0, length - 1);
        }
        
        private static void doMergeSort(int[] arr,int lowerIndex, int higherIndex) {        
            if (lowerIndex < higherIndex) {
                int middle = lowerIndex + (higherIndex - lowerIndex) / 2;
                doMergeSort(arr,lowerIndex, middle);
                doMergeSort(arr,middle + 1, higherIndex);
                mergeParts(arr,lowerIndex, middle, higherIndex);
            }
        }
        
        private static void mergeParts(int[]array,int lowerIndex, int middle, int higherIndex) {
            int[] temp=new int[higherIndex-lowerIndex+1];
            for (int i = lowerIndex; i <= higherIndex; i++) {
                temp[i-lowerIndex] = array[i];
            }
            int i = lowerIndex;
            int j = middle + 1;
            int k = lowerIndex;
            while (i <= middle && j <= higherIndex) {
                if (temp[i-lowerIndex] < temp[j-lowerIndex]) {
                    array[k] = temp[i-lowerIndex];
                    i++;
                } else {
                    array[k] = temp[j-lowerIndex];
                    j++;
                }
                k++;
            }
            while (i <= middle) {
                array[k] = temp[i-lowerIndex];
                k++;
                i++;
            }
            while(j<=higherIndex){
                array[k]=temp[j-lowerIndex];
                k++;
                j++;
            }
        }
 
    }
    
    static long[] shuffle(long[] a, Random gen){ 
        for(int i = 0, n = a.length;i < n;i++){ 
            int ind = gen.nextInt(n-i)+i; 
            long d = a[i]; 
            a[i] = a[ind]; 
            a[ind] = d; 
        } 
        return a; 
    }
 
        
    public static long add(long a,long b){
        long x=(a+b);
        while(x>=mod) x-=mod;
        return x;
    }
 
    public static long sub(long a,long b){
        long x=(a-b);
        while(x<0) x+=mod;
        return x;
    }
    
    public static long mul(long a,long b){
        a%=mod;
        b%=mod;
        long x=(a*b);
        return x%mod;
    }
    
    public static void rev(long[] a){
        for(int i=0;i<a.length/2;i++){
            long tmp=a[i];
            a[i]=a[a.length-i-1];
            a[a.length-i-1]=tmp;
        }
    }
    
    static boolean isPal(String s){
        for(int i=0, j=s.length()-1;i<=j;i++,j--){
                if(s.charAt(i)!=s.charAt(j)) return false;
        }
        return true;
    }
    static String rev(String s){
            StringBuilder sb=new StringBuilder(s);
            sb.reverse();
            return sb.toString();
    }
 
    static long gcd(long x,long y){
        if(y==0) return x;
    if(x%y==0)
            return y;
    else
            return gcd(y,x%y);
    }
 
    static int gcd(int x,int y){
        if(y==0) return x;
    if(x%y==0)
            return y;
    else 
            return gcd(y,x%y);
    }
 
    static long gcdExtended(long a,long b,long[] x){
 
        if(a==0){
            x[0]=0;
            x[1]=1;
            return b;
        }
        long[] y=new long[2];
        long gcd=gcdExtended(b%a, a, y);
 
        x[0]=y[1]-(b/a)*y[0];
        x[1]=y[0];
 
        return gcd;
    }
 
    static int abs(int a,int b){
    return (int)Math.abs(a-b);
    }
 
    static long abs(long a,long b){
    return (long)Math.abs(a-b);
    }
 
    static int max(int a,int b){
    if(a>b)
            return a;
    else
            return b;
    }
 
    static int min(int a,int b){
    if(a>b)
            return b;
    else 
            return a;
    }
 
    static long max(long a,long b){
    if(a>b)
            return a;
    else
            return b;
    }
 
    static long min(long a,long b){
    if(a>b)
            return b;
    else 
            return a;
    }
 
 
    public static long pow(long n,long p,long m){
	 long  result = 1;
	  if(p==0)
	    return 1;
          
	while(p!=0)
	{
	    if(p%2==1)
	        result *= n;
	    if(result>=m)
	    result%=m;
	    p >>=1;
	    n*=n;
	    if(n>=m)
	    n%=m;
	}
	return result;
    }
    
    public static long pow(long n,long p){
	long  result = 1;
	  if(p==0)
	    return 1;
          
	while(p!=0)
	{
	    if(p%2==1)
	        result *= n;	    
	    p >>=1;
	    n*=n;	    
	}
	return result;
    }
    
     static void debug(Object... o) {
            System.out.println(Arrays.deepToString(o));
    }
 
    static class InputReader {
 
            private final InputStream stream;
            private final byte[] buf = new byte[8192];
            private int curChar, snumChars;
            private SpaceCharFilter filter;
 
            InputReader(InputStream stream) {
                    this.stream = stream;
            }
 
            int snext() {
                    if (snumChars == -1)
                            throw new InputMismatchException();
                    if (curChar >= snumChars) {
                            curChar = 0;
                            try {
                                    snumChars = stream.read(buf);
                            } catch (IOException e) {
                                    throw new InputMismatchException();
                            }
                            if (snumChars <= 0)
                                    return -1;
                    }
                    return buf[curChar++];
            }
 
            int nextInt() {
                    int c = snext();
                    while (isSpaceChar(c)) {
                            c = snext();
                    }
                    int sgn = 1;
                    if (c == '-') {
                            sgn = -1;
                            c = snext();
                    }
                    int res = 0;
                    do {
                            if (c < '0' || c > '9')
                                    throw new InputMismatchException();
                            res *= 10;
                            res += c - '0';
                            c = snext();
                    } while (!isSpaceChar(c));
                    return res * sgn;
            }
 
            long nextLong() {
                    int c = snext();
                    while (isSpaceChar(c)) {
                            c = snext();
                    }
                    int sgn = 1;
                    if (c == '-') {
                            sgn = -1;
                            c = snext();
                    }
                    long res = 0;
                    do {
                            if (c < '0' || c > '9')
                                    throw new InputMismatchException();
                            res *= 10;
                            res += c - '0';
                            c = snext();
                    } while (!isSpaceChar(c));
                    return res * sgn;
            }
 
            int[] nextIntArray(int n) {
                    int a[] = new int[n];
                    for (int i = 0; i < n; i++) {
                            a[i] = nextInt();
                    }
                    return a;
            }
 
            long[] nextLongArray(int n) {
                    long a[] = new long[n];
                    for (int i = 0; i < n; i++) {
                            a[i] = nextLong();
                    }
                    return a;
            }
 
            String readString() {
                    int c = snext();
                    while (isSpaceChar(c)) {
                            c = snext();
                    }
                    StringBuilder res = new StringBuilder();
                    do {
                            res.appendCodePoint(c);
                            c = snext();
                    } while (!isSpaceChar(c));
                    return res.toString();
            }
 
            String nextLine() {
                    int c = snext();
                    while (isSpaceChar(c))
                            c = snext();
                    StringBuilder res = new StringBuilder();
                    do {
                            res.appendCodePoint(c);
                            c = snext();
                    } while (!isEndOfLine(c));
                    return res.toString();
            }
 
            boolean isSpaceChar(int c) {
                    if (filter != null)
                            return filter.isSpaceChar(c);
                    return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
            }
 
            private boolean isEndOfLine(int c) {
                    return c == '\n' || c == '\r' || c == -1;
            }
 
            interface SpaceCharFilter {
                    boolean isSpaceChar(int ch);
            }
    }
}