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:
/*
Keep solving problems. 
*/
import java.util.*;
import java.io.*;

public class CFA {

    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;
    final long MOD = 1000L * 1000L * 1000L + 7;

    int INDEX = 0;
    int tree[];
    boolean lazy[];

    /**
     * Increment elements within range [queryStartIndex, queryEndIndex] with value
     */
    void update_tree(int node, int nodeStartIndex, int nodeEndIndex, int queryStartIndex, int queryEndIndex) {
        if(nodeStartIndex > queryEndIndex || nodeEndIndex < queryStartIndex) // Current segment is not within range [i, j]
            return;
        if(nodeStartIndex >= queryStartIndex && nodeEndIndex <= queryEndIndex) { // Segment is fully within range
            tree[node] = (nodeEndIndex - nodeStartIndex + 1) - tree[node];
            lazy[node] = !lazy[node];
            return;
        }

        //-------------
        shift(node, nodeStartIndex, nodeEndIndex);
        //-------------
        update_tree(node * 2, nodeStartIndex, (nodeStartIndex + nodeEndIndex) / 2, queryStartIndex, queryEndIndex); // Updating left child
        update_tree(node * 2 + 1, (nodeStartIndex + nodeEndIndex) / 2 + 1, nodeEndIndex, queryStartIndex, queryEndIndex); // Updating right child

        tree[node] = tree[node * 2] + tree[node * 2 + 1]; // Updating root
    }

    /**
     * Query tree to get max element value within range [queryStartIndex, queryEndIndex]
     */
    int query_tree(int node, int nodeStartIndex, int nodeEndIndex, int queryStartIndex, int queryEndIndex) {
        if(nodeStartIndex > queryEndIndex || nodeEndIndex < queryStartIndex) return 0; // Out of range
        if(nodeStartIndex >= queryStartIndex && nodeEndIndex <= queryEndIndex) // Current segment is totally within range [i, j]
            return tree[node];

        //-------------
        shift(node, nodeStartIndex, nodeEndIndex);
        //-------------

        int q1 = query_tree(node * 2, nodeStartIndex, (nodeStartIndex + nodeEndIndex) / 2, queryStartIndex, queryEndIndex); // Query left child
        int q2 = query_tree(1 + node * 2, (nodeStartIndex + nodeEndIndex) / 2 + 1, nodeEndIndex, queryStartIndex, queryEndIndex); // Query right child

        return q1 + q2;
    }

    private void shift(int node, int nodeStartIndex, int nodeEndIndex) {
        if(lazy[node]) { // This node needs to be updated
            //tree[node] = (nodeEndIndex - nodeStartIndex + 1) - tree[node]; // Update it

            int mid = (nodeStartIndex + nodeEndIndex) / 2;
            tree[2 * node] = mid - nodeStartIndex + 1 - tree[2 * node];
            tree[2 * node + 1] = nodeEndIndex - mid - tree[2 * node + 1];

            lazy[node * 2] = !lazy[node * 2]; // Mark child as lazy
            lazy[node * 2 + 1] = !lazy[node * 2 + 1]; // Mark child as lazy
            lazy[node] = false; // Reset it
        }
    }

    void solve() throws IOException {
        INDEX = 0;
        int n = nextInt();
        List<List<Integer>> child = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            child.add(new ArrayList<>());
        }

        for (int i = 0; i < n - 1; i++) {
            int pi = nextInt();
            child.get(pi - 1).add(i + 1);
        }

        int[] startIndex = new int[n];
        int[] endIndex = new int[n];
        dfs(child, 0, startIndex, endIndex);

        int[] arr = nextIntArr(n);
        tree = new int[5 * arr.length];
        lazy = new boolean[5 * arr.length];

        for (int i = 0; i < n; i++) {
            if (arr[i] == 1) {
                update_tree(1, 0, n - 1, startIndex[i], startIndex[i]);
            }
        }

        int queries = nextInt();
        List<Integer> res = new ArrayList<>();
        for (int i = 0; i < queries; i++) {
            String str = nextToken();
            if (str.equals("get")) {
                int v = nextInt() - 1;
                int val = query_tree(1, 0, n - 1, startIndex[v], endIndex[v]);
                res.add(val);
            }
            else {
                int v = nextInt() - 1;
                update_tree(1, 0, n - 1, startIndex[v], endIndex[v]);
            }
        }

        for (int i = 0; i < res.size(); i++) {
            outln(res.get(i));
        }
    }

    void dfs(List<List<Integer>> child, int nodeIndex, int[] startIndex, int[] endIndex) {
        startIndex[nodeIndex] = INDEX;
        INDEX++;
        for (int v : child.get(nodeIndex)) {
            dfs(child, v, startIndex, endIndex);
        }
        endIndex[nodeIndex] = INDEX - 1;
    }

    void shuffle(int[] a) {
        int n = a.length;
        for(int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            int tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }

    private void outln(Object o) {
        out.println(o);
    }
    private void out(Object o) {
        out.print(o);
    }
    public CFA() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }
    public static void main(String[] args) throws IOException {
        new CFA();
    }

    public long[] nextLongArr(int n) throws IOException{
        long[] res = new long[n];
        for(int i = 0; i < n; i++)
            res[i] = nextLong();
        return res;
    }
    public int[] nextIntArr(int n) throws IOException {
        int[] res = new int[n];
        for(int i = 0; i < n; i++)
            res[i] = nextInt();
        return res;
    }
    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }
    public String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}