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

public class Main {
    private static FastReader sc = new FastReader(System.in);
    private static OutputWriter out = new OutputWriter(System.out);
    private static int n, idx;
    private static HashMap<Integer, ArrayList<Integer>> graph = new HashMap<>();
    private static boolean[] on;
    private static int[] flattenedTree;
    private static boolean[] marked;

    public static void main(String[] args) throws Exception {
        n = sc.nextInt();
        on = new boolean[n];
        for (int i = 0; i < n; i++) graph.put(i, new ArrayList<>());
        for (int i = 1; i < n; i++) {
            int anc = sc.nextInt() - 1;
            graph.get(anc).add(i);
        }
        for (int i = 0; i < n; i++) on[i] = sc.nextInt() == 1 ? true : false;
        flatten();
        int[] start = new int[n];
        int[] end = new int[n];
        Arrays.fill(start, -1);
        for (int i = 0; i < 2 * n; i++) {
            int idx = flattenedTree[i];
            if (start[idx] == -1) start[idx] = i;
            else end[idx] = i;
        }
        SegmentTree st = new SegmentTree(on, flattenedTree, flattenedTree.length);

        int q = sc.nextInt();
        while (q-- > 0) {
            String s = sc.next();
            int v = sc.nextInt() - 1;
            if (s.equals("get")) out.printLine(st.query(0, 0, 2 * n - 1, start[v], end[v]) / 2);
            else st.update(0, 0, 2 * n - 1, start[v], end[v]);
        }
        out.close();
    }

    private static void flatten() {
        flattenedTree = new int[2 * n];
        marked = new boolean[n];
        idx = 0;
        dfs(0);
    }

    private static void dfs(int u) {
        marked[u] = true;
        flattenedTree[idx++] = u;
        for (int v : graph.get(u)) {
            if (!marked[v]) dfs(v);
        }
        flattenedTree[idx++] = u;
    }
}

class SegmentTree {
    int[] st;
    int[] lazy;
    boolean[] initial;
    int[] flattened;
    int n;

    public SegmentTree(boolean[] on, int[] flattened, int n) {
        this.n = n;
        st = new int[4 * n + 1];
        lazy = new int[4 * n + 1];
        initial = on;
        this.flattened = flattened;
        build(0, 0, n - 1);
    }

    private void build(int node, int sl, int sh) {
        if (sl == sh) {
            st[node] = initial[flattened[sl]] == true ? 1 : 0;
            return;
        }
        int mid = (sl + sh) / 2;
        build(2 * node + 1, sl, mid);
        build(2 * node + 2, mid + 1, sh);
        st[node] = st[2 * node + 1] + st[2 * node + 2];
    }

    public int query(int node, int sl, int sh, int ql, int qh) {
        if (lazy[node] % 2 != 0) {
            st[node] = sh - sl + 1 - st[node];
            if (sl != sh) {
                lazy[2 * node + 1] += lazy[node];
                lazy[2 * node + 2] += lazy[node];
            }
        }
        lazy[node] = 0;
        if (ql > sh || qh < sl) return 0;
        if (ql <= sl && qh >= sh) return st[node];
        int mid = (sl + sh) / 2;
        return query(2 * node + 1, sl, mid, ql, qh) + query(2 * node + 2, mid + 1, sh, ql, qh);
    }

    public void update(int node, int sl, int sh, int ql, int qh) {
        if (lazy[node] % 2 != 0) {
            st[node] = sh - sl + 1 - st[node];
            if (sl != sh) {
                lazy[2 * node + 1] += lazy[node];
                lazy[2 * node + 2] += lazy[node];
            }
        }
        lazy[node] = 0;
        if (ql > sh || qh < sl) return;
        if (ql <= sl && qh >= sh) {
            st[node] = sh - sl + 1 - st[node];
            if (sl != sh) {
                lazy[2 * node + 1]++;
                lazy[2 * node + 2]++;
            }
            return;
        }
        int mid = (sl + sh) / 2;
        update(2 * node + 1, sl, mid, ql, qh);
        update(2 * node + 2, mid + 1, sh, ql, qh);
        st[node] = st[2 * node + 1] + st[2 * node + 2];
    }
}

class FastReader {
    private boolean finished = false;

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

    public FastReader(InputStream stream) {
        this.stream = stream;
    }

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

        return buf[curChar++];
    }

    public int peek() {
        if (numChars == -1) {
            return -1;
        }
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                return -1;
            }
            if (numChars <= 0) {
                return -1;
            }
        }
        return buf[curChar];
    }

    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 == ',') {
                c = read();
            }
            if (c < '0' || c > '9') {
                throw new InputMismatchException();
            }
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    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 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 boolean isSpaceChar(int c) {
        if (filter != null) {
            return filter.isSpaceChar(c);
        }
        return isWhitespace(c);
    }

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

    private String readLine0() {
        StringBuilder buf = new StringBuilder();
        int c = read();
        while (c != '\n' && c != -1) {
            if (c != '\r') {
                buf.appendCodePoint(c);
            }
            c = read();
        }
        return buf.toString();
    }

    public String nextLine() {
        String s = readLine0();
        while (s.trim().length() == 0)
            s = readLine0();
        return s;
    }

    public String nextLine(boolean ignoreEmptyLines) {
        if (ignoreEmptyLines) {
            return nextLine();
        } else {
            return readLine0();
        }
    }

    public BigInteger nextBigInteger() {
        try {
            return new BigInteger(nextString());
        } catch (NumberFormatException e) {
            throw new InputMismatchException();
        }
    }

    public char nextCharacter() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        return (char) c;
    }

    public double nextDouble() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        double res = 0;
        while (!isSpaceChar(c) && c != '.') {
            if (c == 'e' || c == 'E') {
                return res * Math.pow(10, nextInt());
            }
            if (c < '0' || c > '9') {
                throw new InputMismatchException();
            }
            res *= 10;
            res += c - '0';
            c = read();
        }
        if (c == '.') {
            c = read();
            double m = 1;
            while (!isSpaceChar(c)) {
                if (c == 'e' || c == 'E') {
                    return res * Math.pow(10, nextInt());
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                m /= 10;
                res += (c - '0') * m;
                c = read();
            }
        }
        return res * sgn;
    }

    public boolean isExhausted() {
        int value;
        while (isSpaceChar(value = peek()) && value != -1)
            read();
        return value == -1;
    }

    public String next() {
        return nextString();
    }

    public SpaceCharFilter getFilter() {
        return filter;
    }

    public void setFilter(SpaceCharFilter filter) {
        this.filter = filter;
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object... objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }

    public void flush() {
        writer.flush();
    }

}