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

/**
 * Change the problem from a tree problem to a range query problem.
 * Construct a Euler Tour on the tree. It's like doing a preorder and
 * post order traversal at the same time. We write down the nodes
 * in the order they are visited, once when we are entering the node from
 * its parent, and once when we are exiting from a node to its parent.
 * Now each node has a left and right index, the first and 2nd time a node
 * appears in the Euler tour.
 * 
 * Now we build a segment tree from the tour values.
 * st[l[i]] = 1 and st[r[i]] = 1 if the light at node i in the tree is on.
 * Otherwise they equal 0.
 * 
 * The queries are just range sum queries. Take the sum of the range and 
 * divide by 2 since you're counting each node twice.
 * For an update on a range [l, r], let v be the current number of lights
 * that are on times two. The new number of lights turned on is then (r-l+1)-v
 * where (r-l+1) is the number of lights in the range times two.
 */
public class F {
    static ArrayList<ArrayList<Integer>> tree;
    static ArrayList<Integer> tour;
    static int[] l, r;

    // Segment Tree fields
    static int[] st;
    static int size;
    static int[] update;

    public static void main(String[] args) {
        FastReader fr = new FastReader();
        int n = fr.nextInt();
        l = new int[n];
        r = new int[n];
        tree = new ArrayList<ArrayList<Integer>>();
        for (int i = 0; i < n; i++) {
            tree.add(new ArrayList<Integer>());
        }
        for (int i = 1; i < n; i++) {
            int p = fr.nextInt() - 1;
            tree.get(p).add(i);
        }
        // Stores if the light at node i is on.
        int[] on = new int[n];
        for (int i = 0; i < n; i++) {
            on[i] = fr.nextInt();
        }
        tour = new ArrayList<Integer>(2 * n);
        dfs(0);
        ArrayList<Integer> ontour = new ArrayList<Integer>(2 * n);
        for (int i = 0; i < tour.size(); i++) {
            ontour.add(on[tour.get(i)]);
        }
        build(ontour);
        int q = fr.nextInt();
        for (int i = 0; i < q; i++) {
            String s = fr.next();
            int j = fr.nextInt() - 1;
            if (s.equals("get")) System.out.println(query(l[j], r[j]) / 2);
            else update(l[j], r[j], 1);
        }
    }

    static void dfs(int p) {
        l[p] = tour.size();
        tour.add(p);
        for (int c : tree.get(p)) {
            dfs(c);
        }
        r[p] = tour.size();
        tour.add(p);
    }

    static void build(ArrayList<Integer> list) {
        size = list.size();
        st = new int[4 * size];
        update = new int[4 * size];
        build(list, 0, size - 1, 0);
    }

    static void build(ArrayList<Integer> list, int nl, int nr, int n) {
        if (nl == nr) {
            st[n] = list.get(nl);
        } else {
            int left = left(n);
            int right = right(n);
            int mid = (nl + nr) / 2;
            build(list, nl, mid, left);
            build(list, mid + 1, nr, right);
            st[n] = st[left] + st[right];
        }
    }

    /**
     * Get left child
     */
    static int left(int n) {
        return 2 * n + 1;
    }

    /**
     * Get right child
     */
    static int right(int n) {
        return 2 * n + 2;
    }

    /**
     * Find the minimum on the range l - r.
     */
    static int query(int l, int r) {
        return query(0, size - 1, l, r, 0);
    }

    static int query(int nl, int nr, int l, int r, int n) {
        if (update[n] != 0) {
            st[n] = update[n] % 2 == 1 ? nr - nl + 1 - st[n] : st[n];
            if (nl != nr) {
                update[left(n)] += update[n];
                update[right(n)] += update[n];
            }
            update[n] = 0;
        }
        if (l == nl && r == nr) {
            return st[n];
        }
        int mid = (nl + nr) / 2;
        int left = left(n);
        int right = right(n);
        if (l <= mid && mid + 1 <= r) {
            int a = query(nl, mid, l, mid, left);
            int b = query(mid + 1, nr, mid + 1, r, right);
            return a + b;
        }
        if (r <= mid) {
            return query(nl, mid, l, r, left);
        } else if (mid + 1 <= l) {
            return query(mid + 1, nr, l, r, right);
        }
        System.out.println(l + " " + r + " " + nl + " " + mid + " " + nr);
        return -12131242;
    }

    static void update(int l, int r, int value) {
        update(0, size - 1, 0, l, r, value);
    }

    static void update(int nl, int nr, int n, int l, int r, int value) {
        if (update[n] != 0) {
            st[n] = update[n] % 2 == 1 ? nr - nl + 1 - st[n] : st[n];
            if (nl != nr) {
                update[left(n)] += update[n];
                update[right(n)] += update[n];
            }
            update[n] = 0;
        }
        if (l == nl && r == nr) {
            st[n] = value % 2 == 1 ? nr - nl + 1 - st[n] : st[n];
            if (l != r) {
                update[left(n)] += value;
                update[right(n)] += value;
            }
            return;
        }
        int mid = (nl + nr) / 2;
        int left = left(n);
        int right = right(n);
        if (l <= mid && mid + 1 <= r) {
            update(nl, mid, left, l, mid, value);
            update(mid + 1, nr, right, mid + 1, r, value);
            int a = query(nl, mid, nl, mid, left);
            int b = query(mid + 1, nr, mid + 1, nr, right);
            st[n] = a + b;
            return;
        }
        if (r <= mid) {
            update(nl, mid, left, l, r, value);
            int a = query(nl, mid, nl, mid, left);
            int b = query(mid + 1, nr, mid + 1, nr, right);
            st[n] = a + b;
            return;
        } else if (mid + 1 <= l) {
            update(mid + 1, nr, right, l, r, value);
            int a = query(nl, mid, nl, mid, left);
            int b = query(mid + 1, nr, mid + 1, nr, right);
            st[n] = a + b;
            return;
        }
        System.out.println(l + " " + r + " " + nl + " " + mid + " " + nr);
    }
}

class FastReader {
    BufferedReader br;
    StringTokenizer st;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

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

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    String nextLine() {
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }
}

//source: http://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/