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.IOException;
import java.util.ArrayList;
import java.util.InputMismatchException;

public class Main {
	public static void main(String[] args) {
		FasterScanner sc = new FasterScanner();

		int N = sc.nextInt();
		
		TreeNode[] nodes = new TreeNode[N + 1];
		for (int i = 1; i <= N; ++i) {
		  nodes[i] = new TreeNode(i);
		}
		
		for (int i = 2; i <= N; ++i) {
		  int P = sc.nextInt();
		  
		  nodes[P].children.add(nodes[i]);
		}
		
		for (int i = 1; i <= N; ++i) {
		  nodes[i].val = sc.nextInt();
		}
		
		ArrayList<Integer> lst = new ArrayList<>();
		int[] L = new int[N + 1];
		int[] R = new int[N + 1];
		makePath(nodes[1], lst, L, R);

		LightNode ln = new LightNode(0, (N + 1) << 1);
		for (int i = 1; i <= N; ++i) {
			if (nodes[i].val == 1) {
				ln.flip(L[i], L[i]);
				ln.flip(R[i], R[i]);
			}
		}

		int Q = sc.nextInt();

		StringBuilder sb = new StringBuilder();
		for (int q = 0; q < Q; ++q) {
			String OP = sc.nextString();
			int V = sc.nextInt();

			if (OP.equals("get")) {
				sb.append((ln.getOn(L[V], R[V]) >> 1) + "\n");
			} else {
				ln.flip(L[V], R[V]);
			}
		}
		System.out.print(sb.toString());
	}

	private static class LightNode {
		public int L, R;
		public boolean inverted;
		public long val;
		public LightNode left, right;

		public LightNode(int lo, int hi) {
			L = lo;
			R = hi;
			if (lo < hi) {
				int mid = (lo + hi) >> 1;
				left = new LightNode(lo, mid);
				right = new LightNode(mid + 1, hi);
			}
		}

		public long getCoverage(int lo, int hi) {
			if (R < lo || L > hi) {
				return 0;
			}
			return 1 + Math.min(hi, R) - Math.max(lo, L);
		}

		public long getOn(int lo, int hi) {
			if (R < lo || L > hi) {
				return 0;
			}
			if (L >= lo && R <= hi) {
				return val;
			}
			long total = getCoverage(lo, hi);
			long on = left.getOn(lo, hi) + right.getOn(lo, hi);
			if (inverted) {
				on = total - on;
			}
			return on;
		}

		public void flip(int lo, int hi) {
			if (R < lo || L > hi) {
				return;
			}
			if (L >= lo && R <= hi) {
				inverted = !inverted;
			} else {
				left.flip(lo, hi);
				right.flip(lo, hi);
			}
			if (L == R) {
				val = 0;
			} else {
				val = left.val + right.val;
			}
			if (inverted) {
				val = (R - L + 1) - val;
			}
		}
	}
	
	public static void makePath(TreeNode u, ArrayList<Integer> lst, int[] L, int[] R) {
	  if (u == null) {
	    return;
	  }
	  
	  L[u.id] = lst.size();
	  lst.add(u.val);
	  
	  for (TreeNode v : u.children) {
	    makePath(v, lst, L, R);
	  }
	  
	  R[u.id] = lst.size();
	  lst.add(u.val);
	}
	
	public static class TreeNode {
	  public int id;
	  public ArrayList<TreeNode> children = new ArrayList<>();
	  public int val;
	  
	  public TreeNode(int i) {
	    this.id = i;
	  }
	}

	public static class FasterScanner {
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

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

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

		public String nextString() {
			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 long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n) {
			return nextIntArray(n, 0);
		}

		public int[] nextIntArray(int n, int off) {
			int[] arr = new int[n + off];
			for (int i = 0; i < n; i++) {
				arr[i + off] = nextInt();
			}
			return arr;
		}

		public long[] nextLongArray(int n) {
			return nextLongArray(n, 0);
		}

		public long[] nextLongArray(int n, int off) {
			long[] arr = new long[n + off];
			for (int i = 0; i < n; i++) {
				arr[i + off] = nextLong();
			}
			return arr;
		}

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

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