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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.function.Consumer;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScan in = new MyScan(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        public void solve(int testNumber, MyScan in, PrintWriter out) {
            int n = in.nextInt();
            Tree tree = TreeReader.byParent(n, in);

            EulerEdge eulerEdge = new EulerEdge(tree);

            int[] data = in.na(n);
            for (int i = 0; i < n; i++) {
                if (data[i] == 1) {
                    eulerEdge.invPrec(i);
                }
            }
            int q = in.nextInt();
            for (int s = 0; s < q; s++) {
                boolean g = in.next().charAt(0) == 'g';
                int node = in.nextInt() - 1;
                if (g) {
                    out.println(eulerEdge.sumRange(node));
                } else {
                    eulerEdge.invRange(node);
                }
            }

        }

    }

    static class EulerEdge {
        private Tree tree;
        private ISumSegmentTree segmentTree;
        private int[][] indexes;

        public EulerEdge(Tree tree) {
            this.tree = tree;
            segmentTree = new ISumSegmentTree(tree.data.length * 2);

            int[] index = new int[1];
            indexes = new int[tree.ct()][2];
            tree.setOnAdd(l -> indexes[l[0]][0] = index[0]++);
            tree.setOnRemove(l -> indexes[l[0]][1] = index[0]++);
            tree.dfs(0);
        }

        public void invPrec(int i) {
            segmentTree.inv(indexes[i][0], indexes[i][1]);
            segmentTree.inv(indexes[i][0] + 1, indexes[i][1] - 1);
        }

        public int sumRange(int i) {
            return segmentTree.sum(indexes[i][0], indexes[i][1]) / 2;
        }

        public void invRange(int i) {
            segmentTree.inv(indexes[i][0], indexes[i][1]);
        }

    }

    static class Tree {
        public int[][] data;
        Consumer<int[]> onAdd;
        Consumer<int[]> onRemove;

        public Tree(int[][] data) {
            this.data = data;
        }

        public void setOnAdd(Consumer<int[]> onAdd) {
            this.onAdd = onAdd;
        }

        public void setOnRemove(Consumer<int[]> onRemove) {
            this.onRemove = onRemove;
        }

        public void dfs(int start) {
            Tree.P[] n = new Tree.P[data.length * 2];
            int toVisit = 0;
            n[toVisit++] = new Tree.P(start, true, -1);
            boolean[] vis = new boolean[data.length];
            vis[start] = true;
            int[] level = new int[data.length];
            while (toVisit > 0) {
                Tree.P ppr = n[--toVisit];
                if (!ppr.b) {
                    if (onRemove != null)
                        onRemove.accept(new int[]{ppr.ind, level[ppr.ind], ppr.parent});
                    continue;
                }
                ppr.b = false;
                int i = ppr.ind;
                n[toVisit++] = ppr;
                if (onAdd != null)
                    onAdd.accept(new int[]{ppr.ind, level[ppr.ind], ppr.parent});
                for (int kk : data[i]) {
                    if (!vis[kk]) {
                        vis[kk] = true;
                        level[kk] = level[i] + 1;
                        n[toVisit++] = new Tree.P(kk, true, i);
                    }
                }
            }
        }

        public int ct() {
            return data.length;
        }

        public static class P {
            private boolean b;
            private final int ind;
            private final int parent;

            public P(int i, boolean b, int par) {
                this.ind = i;
                this.b = b;
                this.parent = par;
            }

        }

    }

    static class ISumSegmentTree {
        int[] from1;
        int[] to1;
        int[] val1;
        boolean[] inv1;

        public ISumSegmentTree(int c) {
            c = Math.max(c, 2);
            int size = Integer.highestOneBit(c);
            if (size != c) {
                size <<= 1;
            }
            int rs = size << 1;
            val1 = new int[rs];
            from1 = new int[rs];
            inv1 = new boolean[rs];
            to1 = new int[rs];

            Arrays.fill(from1, Integer.MAX_VALUE);
            for (int r = val1.length - 1; r > 1; r--) {
                if (r >= size) {
                    from1[r] = r - size;
                    to1[r] = r - size;
                }
                from1[r / 2] = Math.min(from1[r / 2], from1[r]);
                to1[r / 2] = Math.max(to1[r / 2], to1[r]);
            }
        }

        public void inv(int from, int to) {
            inv(1, from, to);
        }

        private int len(int cur) {
            return to1[cur] - from1[cur] + 1;
        }

        private void inv(int cur, int from, int to) {
            if (cur >= val1.length) return;
            if (from1[cur] > to || from > to1[cur]) {
                return;
            }
            if (from <= from1[cur] && to1[cur] <= to) {
                inv1[cur] ^= true;
                return;
            }
            int left = (cur << 1);
            int right = left + 1;

            inv(left, from, to);
            inv(right, from, to);
            val1[cur] = sum((cur << 1) + 1) + sum((cur << 1));
        }

        public int sum(int from, int to) {
            return sum(1, from, to);
        }

        private int sum(int cur) {
            return sum(cur, from1[cur], to1[cur]);
        }

        private int sum(int cur, int from, int to) {
            if (cur >= val1.length) return 0;
            propagate(cur);
            if (from <= from1[cur] && to1[cur] <= to) {
                return val1[cur];
            }
            if (from1[cur] > to || from > to1[cur]) {
                return 0;
            }
            return sum((cur << 1) + 1, from, to) + sum(cur << 1, from, to);
        }

        private void propagate(int cur) {
            if (inv1[cur]) {
                inv1[cur] = false;
                val1[cur] = len(cur) - val1[cur];
                if (len(cur) > 1) {
                    inv((cur << 1) + 1, 0, Integer.MAX_VALUE);
                    inv((cur << 1), 0, Integer.MAX_VALUE);
                }
            }
        }

    }

    static class TreeReader {
        public static Tree byParent(int l, MyScan sc) {
            return new Tree(tr2(l, sc));
        }

        private static int[][] tr2(int n, MyScan sc) {
            int[][] x = new int[2][n - 1];
            for (int i = 0; i < n - 1; i++) {
                x[0][i] = i + 1;
                x[1][i] = sc.nextInt() - 1;
            }
            return pn(x, n, sc);
        }

        private static int[][] pn(int[][] x, int n, MyScan sc) {
            int[] ct = new int[n];
            int[][] res = new int[n][];
            for (int v : x[0]) {
                ct[v]++;
            }
            for (int v : x[1]) {
                ct[v]++;
            }
            for (int l = 0; l < n; l++) {
                res[l] = new int[ct[l]];
            }
            for (int i = 0; i < x[0].length; i++) {
                res[x[0][i]][--ct[x[0][i]]] = x[1][i];
                res[x[1][i]][--ct[x[1][i]]] = x[0][i];
            }
            return res;
        }

    }

    static class MyScan {
        BufferedReader br;
        StringTokenizer st;

        MyScan(BufferedReader br) {
            this.br = br;
        }

        public MyScan(InputStream in) {
            this(new BufferedReader(new InputStreamReader(in)));
        }

        public void findToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }

        public String next() {
            findToken();
            return st.nextToken();
        }

        public int[] na(int n) {
            int[] k = new int[n];
            for (int i = 0; i < n; i++) {
                k[i] = fi();
            }
            return k;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int fi() {
            String t = next();
            int cur = 0;
            boolean n = t.charAt(0) == '-';
            for (int a = n ? 1 : 0; a < t.length(); a++) {
                cur = cur * 10 + t.charAt(a) - '0';
            }
            return n ? -cur : cur;
        }

    }
}