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:
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */

public class Main{
	public static void main(String[] args) throws IOException{
		//Scanner scan=new Scanner(System.in);
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(br.readLine());
		
		Map memo=new HashMap();
		for(int i=1;i<=n;i++){
			memo.put(i,new ArrayList());
		}
		//System.out.println("got in");
		String[] numsp=br.readLine().split(" ");
		for(int i=2;i<=n;i++){
			int pi=Integer.parseInt(numsp[i-2]);
			ArrayList arri=(ArrayList)memo.get(i);
			ArrayList arrp=(ArrayList)memo.get(pi);
			arri.add(pi);
			arrp.add(i);
			memo.put(i,arri);
			memo.put(pi,arrp);
		}
		
		Graph gr=new Graph();
		gr.init(n,memo);
		//System.out.println("got in");
		gr.dfs(1);
		
		String[] numst=br.readLine().split(" ");
		
		int[] ti=new int[n+1];
		for(int i=1;i<=n;i++){
			ti[i]=Integer.parseInt(numst[i-1]);
			//System.out.println(ti[i]);
		}
		
		
		int[] arr=new int[n];
		for(int i=0;i<n;i++){
			arr[i]=ti[gr.ver[i]];
		}
		SegTree st=new SegTree();
		st.init(n,arr);
		int sum=st.run(1,0,n-1);
		int q=Integer.parseInt(br.readLine());
	
		for(int i=0;i<q;i++){
			String[] com=br.readLine().split(" ");
			String s=com[0];
			int v=Integer.parseInt(com[1]);
			if(s.equals("pow")){
				st.update(1,gr.left[v],gr.right[v]);
			}
			else{
				System.out.println(st.getSum(1,gr.left[v],gr.right[v]));
			}
		}
	}
}

class Node{
	int low=-1;
	int high=-1;
	int sum=-1;
	Node(){}
	Node(int l,int h){
		low=l;
		high=h;
	}
}

class SegTree{
	Node[] tree=new Node[1<<19];
	int[] lazy=new int[1<<19];
	int[] arr;
	int n;
	
	void init(int N,int[] A){
		n=N;
		arr=A;
		for(int i=0;i<(1<<19);i++){
			tree[i]=new Node();
			lazy[i]=0;
		}
	}
	
	int run(int p,int l,int h){
		tree[p].low=l;
		tree[p].high=h;
		if(l<h){
			int m=(l+h)/2;
			int res=run(2*p,l,m)+run(2*p+1,m+1,h);
			tree[p].sum=res;
			return res;
		}
		else if(l==h){
			tree[p].sum=arr[l];
			return arr[l];
		}
		else{
			return 0;
		}
	}
	
	void update(int p,int l,int r){ //invert this range
		int lo=tree[p].low;
		int hi=tree[p].high;
		if(lazy[p]==1){
			tree[p].sum=hi-lo+1-tree[p].sum;
			if(lo!=hi){
				lazy[2*p]=(lazy[2*p]+1)%2;
				lazy[2*p+1]=(lazy[2*p+1]+1)%2;
			}
			lazy[p]=0;
		}
		if(l<=lo && hi<=r){
			tree[p].sum=hi-lo+1-tree[p].sum;
			if(lo!=hi){
				lazy[2*p]=(lazy[2*p]+1)%2;
				lazy[2*p+1]=(lazy[2*p+1]+1)%2;
			}
			return;
		}
		else if(lo>r || hi<l){return;}
		else{
			if(lo!=hi){
				update(2*p,l,r);
				update(2*p+1,l,r);
				tree[p].sum=tree[2*p].sum+tree[2*p+1].sum;
			}
		}
	}
	
	int getSum(int p,int l,int r){
		int lo=tree[p].low;
		int hi=tree[p].high;
		if(lazy[p]==1){
			tree[p].sum=hi-lo+1-tree[p].sum;
			if(lo!=hi){
				lazy[2*p]=(lazy[2*p]+1)%2;
				lazy[2*p+1]=(lazy[2*p+1]+1)%2; 
			}
			lazy[p]=0;
		}
		if(lo>r || hi<l){return 0;}
		else if(l<=lo && hi<=r){
			return tree[p].sum;
		}
		else{
			int res=0;
			if(lo!=hi){
				res=getSum(2*p,l,r)+getSum(2*p+1,l,r);
			}
			return res;
		}
	}
}

class Graph{
	Map memo; //edges
	int[] ver;
	int[] left;
	int[] right;
	int[] vis;
	int n;
	int tot;
	
	void init(int N,Map mp){
		n=N;
		ver=new int[n];
		left=new int[n+1];
		right=new int[n+1];
		vis=new int[n+1];
		for(int i=0;i<=n;i++){vis[i]=0;}
		tot=0;
		memo=mp;
	}
	
	void dfs(int v){
		vis[v]=1;
		ver[tot]=v;
		left[v]=tot;
		tot++;
		ArrayList vi=(ArrayList)memo.get(v);
		int sz=vi.size();
		for(int i=0;i<sz;i++){
			int t=(int)vi.get(i);
			if(vis[t]==0){
				dfs(t);
			}
		}
		right[v]=tot-1;
	}
}