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.*;
import java.util.*;

public class DFSTreeArrayAndSegTree {

	public static void main(String[] args) throws Exception {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		run(sc, out);
		out.close();
	}

	public static void run(FastScanner sc, PrintWriter out) throws Exception {
		int N = sc.nextInt();
		int[] pos = new int[N];
		int[] size = new int[N];
		ArrayList<Integer>[] tree = new ArrayList[N];
		for (int i = 1; i < N; i++) {
			int parent = sc.nextInt() - 1;
			if (tree[parent] == null) {
				tree[parent] = new ArrayList<>();
			}
			tree[parent].add(i);
		}
		createDFSArray(0, 0, tree, pos, size);
		int[] init = new int[N];
		for (int i = 0; i < N; i++) {
			init[pos[i]] = sc.nextInt();
		}
		SegTree seg = new SegTree(init);
		int Q = sc.nextInt();
		StringBuilder ans = new StringBuilder();
		for (int i = 0; i < Q; i++) {
			boolean get = sc.readOutSpaces() == 'g';
			sc.read();
			sc.read();
			int node = sc.nextInt() - 1;
			int start = pos[node] + 1;
			int end = pos[node] + size[node];
			if (get) {
				ans.append(seg.query(start, end));
				ans.append('\n');
			} else {
				seg.update(start, end);
			}
		}
		out.print(ans);
	}

	private static class SegTree {
		int[] arr, seg, lazy;
		int n;

		public SegTree(int[] arr) {
			this.arr = arr;
			this.n = arr.length;
			seg = new int[4 * n];
			lazy = new int[4 * n];
			build(1, 1, n);
		}

		public SegTree(int n) {
			this.n = n;
			seg = new int[4 * n];
			lazy = new int[4 * n];
		}

		private void build(int node, int l, int r) {
			if (l == r) {
				// CAREFUL! THIS ASSUMES THE ARRAY IS 0 INDEXED(which it probably is)
				seg[node] = arr[l - 1];
				return;
			}
			int mid = (l + r) / 2;
			build(node * 2, l, mid);
			build(node * 2 + 1, mid + 1, r);
			// change this
			seg[node] = seg[node * 2] + seg[node * 2 + 1];

		}

		private int query(int a, int b) {
			return query(1, 1, n, a, b);
		}

		private int query(int node, int l, int r, int a, int b) {
			if (a <= l && r <= b) {
				return seg[node];
			}
			prop(node, l, r);
			int ans = 0;
			int mid = (l + r) / 2;
			if (a <= mid) {
				// change this
				ans += query(node * 2, l, mid, a, b);
			}
			if (b > mid) {
				// change this
				ans += query(node * 2 + 1, mid + 1, r, a, b);
			}
			return ans;
		}

		private void update(int a, int b) {
			update(1, 1, n, a, b);
		}

		private void update(int node, int l, int r, int a, int b) {
			int numElements = r - l + 1;
			if (a <= l && r <= b) {
				lazy[node]++;
				// change this
				seg[node] = numElements - seg[node];
				return;
			}
			prop(node, l, r);
			int mid = (l + r) / 2;
			if (a <= mid) {
				// change this
				update(node * 2, l, mid, a, b);
			}
			if (b > mid) {
				// change this
				update(node * 2 + 1, mid + 1, r, a, b);
			}
			// change this
			seg[node] = seg[node * 2] + seg[node * 2 + 1];

		}

		private void prop(int node, int l, int r) {
			if (lazy[node] != 0) {
				int mid = (l + r) / 2;
				if (lazy[node] % 2 == 1) {
					// change this
					int s1 = mid - l + 1;
					int s2 = r - mid ;
					seg[node * 2] = s1 - seg[node * 2];
					seg[node * 2 + 1] = s2 - seg[node * 2 + 1];
				}
				lazy[node * 2] += lazy[node];
				lazy[node * 2 + 1] += lazy[node];
				lazy[node] = 0;
			}
		}

	}

	private static int createDFSArray(int node, int curPos, ArrayList<Integer>[] tree, int[] pos, int[] size) {
		pos[node] = curPos;
		if (tree[node] == null) {
			size[node] = 1;
			return curPos + 1;
		}
		int newPos = curPos + 1;
		for (int child : tree[node]) {
			newPos = createDFSArray(child, newPos, tree, pos, size);
		}
		size[node] = newPos - curPos;
		return newPos;
	}

	static class FastScanner {
		final private int BUFFER_SIZE = 1 << 20;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		public FastScanner(InputStream stream) {
			din = new DataInputStream(stream);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public FastScanner(String file_name) throws IOException {
			din = new DataInputStream(new FileInputStream(file_name));
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		String nextLine() throws IOException {
			int c = read();
			while (c != -1 && isEndline(c))
				c = read();
			if (c == -1) {
				return null;
			}
			StringBuilder res = new StringBuilder();
			do {
				if (c >= 0) {
					res.appendCodePoint(c);
				}
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}

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

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

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

		public int nextInt() throws IOException {
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (neg)
				return -ret;
			return ret;
		}

		public long nextLong() throws IOException {
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public double nextDouble() throws IOException {
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();

			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (c == '.') {
				while ((c = read()) >= '0' && c <= '9') {
					ret += (c - '0') / (div *= 10);
				}
			}

			if (neg)
				return -ret;
			return ret;
		}

		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		private byte read() throws IOException {
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		private int readOutSpaces() throws IOException {
			while (true) {
				if (bufferPointer == bytesRead)
					fillBuffer();
				int c = buffer[bufferPointer++];
				if (!isSpaceChar(c)) {
					return c;
				}
			}
		}

		public void close() throws IOException {
			if (din == null)
				return;
			din.close();
		}
	}

}