Problem: Danil decided to earn some money, so he had found a part-time job. The interview have went well, so now he is a light switcher.

Danil works in a rooted tree (undirected connected acyclic graph) with n vertices, vertex 1 is the root of the tree. There is a room in each vertex, light can be switched on or off in each room. Danil's duties include switching light in all rooms of the subtree of the vertex. It means that if light is switched on in some room of the subtree, he should switch it off. Otherwise, he should switch it on.

Unfortunately (or fortunately), Danil is very lazy. He knows that his boss is not going to personally check the work. Instead, he will send Danil tasks using Workforces personal messages.

There are two types of tasks: 

  1. pow v describes a task to switch lights in the subtree of vertex v.
  2. get v describes a task to count the number of rooms in the subtree of v, in which the light is turned on. Danil should send the answer to his boss using Workforces messages.



A subtree of vertex v is a set of vertices for which the shortest path from them to the root passes through v. In particular, the vertex v is in the subtree of v.

Danil is not going to perform his duties. He asks you to write a program, which answers the boss instead of him.

Input

The first line contains a single integer n (1 ≤ n ≤ 200 000) — the number of vertices in the tree.

The second line contains n - 1 space-separated integers p2, p3, ..., pn (1 ≤ pi < i), where pi is the ancestor of vertex i.

The third line contains n space-separated integers t1, t2, ..., tn (0 ≤ ti ≤ 1), where ti is 1, if the light is turned on in vertex i and 0 otherwise.

The fourth line contains a single integer q (1 ≤ q ≤ 200 000) — the number of tasks.

The next q lines are get v or pow v (1 ≤ v ≤ n) — the tasks described above.

Output

For each task get v print the number of rooms in the subtree of v, in which the light is turned on.

Example

Input

4
1 1 1
1 0 0 1
9
get 1
get 2
get 3
get 4
pow 1
get 1
get 2
get 3
get 4


Output

2
0
0
1
2
1
1
0

Note

<image> The tree before the task pow 1.

<image> The tree after the task pow 1.

Solution (in JAVA):

Solution:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Solution{
	
	static ArrayList<Integer>[] g;
	static int pt = 0;
	static int[] start, end;
	
	
    public static void main(String[] args) throws IOException {
    	
		
    	FastScanner fs = new FastScanner();
    	PrintWriter out = new PrintWriter(System.out);
    		
    	int tt = 1;
    	while(tt-->0) {
    		
    		
    		int n = fs.nextInt();
    		g = new ArrayList[n];
    		
    		for(int i=0;i<n;i++) g[i] = new ArrayList<Integer>();
    		
    		for(int i=1;i<n;i++) {
    			int p = fs.nextInt()-1;
    			g[p].add(i);
    		}
    		
    		ArrayList<Integer>[] G = g;
    		
    		int[] a = new int[n];
    		start = new int[n]; end = new int[n];
    		
    		dfs(0);
    		
    		int[] START = start, END = end;
    		
    		for(int i=0;i<n;i++) {
    			int t = fs.nextInt();
    			a[start[i]] = t;
    		}
    		
    		SegTree tree = new SegTree(n);
    		tree.build(a, 0, n-1, 0);
    		
    		
    		int q = fs.nextInt();
    		
    		while(q-->0) {
    			String s = fs.next();
    			int v = fs.nextInt()-1;
    			
    			if(s.equals("pow")) {
    				tree.update(start[v], end[v], 0, n-1, 0);
    			}
    			else {
    				out.println(tree.query(start[v], end[v], 0, n-1, 0));
    			}
    		}
    		
    		
    		
    			
    			
    			
    			
    		
    		
    		
    		
    		
    		
    		
    	}
    	
    	out.close();
    		
    }
    
    
    static void dfs(int v) {
    	start[v] = pt++;
    	for(int u: g[v]) {
    		dfs(u);
    	}
    	end[v] = pt-1;
    }
   
    
    
    static class SegTree{
    	int[] tree;
    	int[] lazy;
    	
    	SegTree(int n){
    		tree = new int[4*n];
    		lazy = new int[4*n];
    	}
    	
    	void build(int[] a, int ns, int ne, int node) {
    		if(ns==ne) {
    			tree[node] = a[ns];
    			return;
    		}
    		int mid = (ns+ne)/2;
    		build(a, ns, mid, 2*node+1);
    		build(a, mid+1, ne, 2*node+2);
    		tree[node] = tree[2*node+1] + tree[2*node+2]; 
    	}
    	
    	void propagate(int ns, int ne, int node) {
    		if(ns!=ne) {
    			lazy[2*node+1] ^= 1;
    			lazy[2*node+2] ^= 1;
    		}
    		tree[node] = (ne-ns+1) - tree[node];
    		lazy[node] = 0;
    	}
    	
    	void update(int qs, int qe, int ns, int ne, int node) {
    		if(lazy[node]!=0) propagate(ns, ne, node);
    		if(ns>qe || ne<qs) return;
    		if(ns>=qs && ne<=qe) {
    			tree[node] = (ne-ns+1) - tree[node];
    			if(ns!=ne) {
    				lazy[2*node+1] ^= 1;
    				lazy[2*node+2] ^= 1;
    			}
    			return;
    		}
    		int mid = (ns+ne)/2;
    		update(qs, qe, ns, mid, 2*node+1);
    		update(qs, qe, mid+1, ne, 2*node+2);
    		tree[node] = tree[2*node+1] + tree[2*node+2];
    	}
    	
    	int query(int qs, int qe, int ns, int ne, int node) {
    		if(lazy[node]!=0) propagate(ns, ne, node);
    		if(ns>qe || ne<qs) return 0;
    		if(ns>=qs && ne<=qe) return tree[node];
    		int mid = (ns+ne)/2;
    		return query(qs, qe, ns, mid, 2*node+1) + query(qs, qe, mid+1, ne, 2*node+2);
    	}
    	
    	
    	
    }
   
   
    
    
    static final Random random=new Random();
    
    static <T> void shuffle(T[] arr) {
    	int n = arr.length;
    	for(int i=0;i<n;i++	) {
    		int k = random.nextInt(n);
    		T temp = arr[k]; arr[k] = arr[i]; arr[i] = temp;
    	}
    }
    
    	
    static void ruffleSort(int[] a) {
    	int n=a.length;//shuffle, then sort 
    	for (int i=0; i<n; i++) {
    		int oi=random.nextInt(n); int temp=a[oi];
    		a[oi]=a[i]; a[i]=temp;
    	}
    	Arrays.sort(a);
    }
    
    static void ruffleSort(long[] a) {
    	int n=a.length;//shuffle, then sort 
    	for (int i=0; i<n; i++) {
    		int oi=random.nextInt(n); long temp=a[oi];
    		a[oi]=a[i]; a[i]=temp;
    	}
    	Arrays.sort(a);
    }
   
  
    
    static void reverse(int[] arr, int l, int r) {
    	for(int i=l;i<l+(r-l)/2;i++){
    		int temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;
    	}
    }
    
    static void reverse(long[] arr, int l, int r) {
    	for(int i=l;i<l+(r-l)/2;i++){
    		long temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;
    	}
    }
    
    
    static <T> void reverse(T[] arr, int l, int r) {
    	for(int i=l;i<l+(r-l)/2;i++) {
    		T temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;
    	}
    }
    	
    	
    static class FastScanner{
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	StringTokenizer st = new StringTokenizer("");
     
    	public String next(){
    		while(!st.hasMoreElements()){
    			try{
    				st = new StringTokenizer(br.readLine());
    			} catch(IOException e){
    				e.printStackTrace();
    			}
    		}
    		return st.nextToken();
    	}
    		
    	public String nextLine() throws IOException {
    		return br.readLine();
    	}
    		
    	public int nextInt(){
    		return Integer.parseInt(next());
    	}
     
    	public int[] readArray(int n){
    		int[] a = new int[n];
    		for(int i=0;i<n;i++)
    			a[i] = nextInt();
    		return a;
    	}
    		
    	public long nextLong() {
    		return Long.parseLong(next());
    	}
    		
    	public char nextChar() {
    		return next().toCharArray()[0];
    	}
    }
   	
}