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

public class Main3 {

    static long mod = 1000000007L;
    static FastScanner scanner;
    static Node[] nodes;
    static int[] t;

    public static void main(String[] args) {
        scanner = new FastScanner();

        int n = scanner.nextInt();
        nodes = new Node[n];
        for (int i = 0; i < n; i++) nodes[i] = new Node();
        for (int i = 1; i <= n - 1; i++) {
            nodes[scanner.nextInt() - 1].childs.add(i);
        }
        for (int i = 0; i < n; i++) nodes[i].val = scanner.nextInt();
        t = new int[n];
        dfs(0, 0);

        SegTree tree = new SegTree(t);

        int q = scanner.nextInt();
        StringBuilder res = new StringBuilder();
        for (int i = 0; i < q; i++) {
            String cmd = scanner.nextToken();
            int v = scanner.nextInt() - 1;
            if (cmd.equals("get")) {
                res.append(tree.query(nodes[v].from, nodes[v].to)).append("\n");
            }
            if (cmd.equals("pow")) {
                tree.update(nodes[v].from, nodes[v].to, 1);
            }
        }
        System.out.println(res.toString());
    }

    static int dfs(int current, int index) {
        if (nodes[current].childs.isEmpty()) {
            nodes[current].from = index;
            nodes[current].to = index;
            t[index] = nodes[current].val;
            return index;
        }
        nodes[current].from = index;
        t[index] = nodes[current].val;
        nodes[current].val = t[current];
        int to = index;
        for (int ch : nodes[current].childs) {
            to = dfs(ch, to + 1);
        }
        nodes[current].to = to;
        return to;
    }

    static class SegTree {
        SegTreeNode[] nodes;

        public SegTree(int[] data) {
            int size = (int) (2 * Math.pow(2.0, Math.floor((Math.log((double) data.length) / Math.log(2.0)) + 1)));
            nodes = new SegTreeNode[size];
            build(data, 0, data.length - 1, 1);
        }

        SegTreeNode build(int[] data, int from, int to, int idx) {
            if (from == to) {
                nodes[idx] = new SegTreeNode(from, to, data[from]);
                return nodes[idx];
            }
            int mid = (from + to) >> 1;
            SegTreeNode left = build(data, from, mid, idx << 1);
            SegTreeNode right = build(data, mid + 1, to, (idx << 1) + 1);
            nodes[idx] = new SegTreeNode(from, to, left.value + right.value);
            return nodes[idx];
        }

        void update(int from, int to, int val) {
            update(from, to, val, 1);
        }

        void update(int from, int to, int val, int idx) {
            SegTreeNode current = nodes[idx];
            SegTreeNode left = !current.leaf() ? nodes[idx << 1] : null;
            SegTreeNode right = !current.leaf() ? nodes[(idx << 1) + 1] : null;

            applyPending(current, left, right);
            if (to < current.from || from > current.to) return;
            from = Math.max(from, current.from);
            to = Math.min(to, current.to);

            if (current.from == from && current.to == to) {
                current.pending(val);
                applyPending(current, left, right);
                return;
            }
            update(from, to, val, idx << 1);
            update(from, to, val, (idx << 1) + 1);
            current.value = left.value + right.value;
        }

        long query(int from, int to) {
            return query(from, to, 1);
        }

        long query(int from, int to, int idx) {
            SegTreeNode current = nodes[idx];
            SegTreeNode left = !current.leaf() ? nodes[idx << 1] : null;
            SegTreeNode right = !current.leaf() ? nodes[(idx << 1) + 1] : null;

            applyPending(current, left, right);
            if (current.from == from && current.to == to) {
                return current.value;
            }
            if (left.to >= to) {
                return query(from, to, idx << 1);
            } else if (right.from <= from) {
                return query(from, to, (idx << 1) + 1);
            } else {
                return query(from, left.to, idx << 1) + query(right.from, to, (idx << 1) + 1);
            }
        }

        void applyPending(SegTreeNode c, SegTreeNode l, SegTreeNode r) {
            int val = c.pendingState();
            if (l != null) l.pending(val);
            if (r != null) r.pending(val);
            c.apply();
        }
    }

    static class SegTreeNode {
        int from, to;
        int value;
        int notAppliedInvert;

        public SegTreeNode(int from, int to, int value) {
            this.from = from;
            this.to = to;
            this.value = value;
        }

        public void pending(int state) {
            notAppliedInvert = notAppliedInvert ^ state;
        }

        public void apply() {
            if (notAppliedInvert == 1) {
                value = (to - from + 1) - value;
                notAppliedInvert = 0;
            }
        }

        public int pendingState() {
            return notAppliedInvert;
        }

        public boolean leaf() {
            return from == to;
        }
    }

    static class SegTreeBAAAD {
        int from, to;
        int sum;
        SegTreeBAAAD left, right;
        int inv;

        public SegTreeBAAAD(int[] data, int from, int to) {
            this.from = from;
            this.to = to;
            if (from == to) {
                sum = data[from];
            } else {
                int mid = (from + to) / 2;
                left = new SegTreeBAAAD(data, from, mid);
                right = new SegTreeBAAAD(data, mid + 1, to);
                sum = left.sum + right.sum;
            }
        }

        public int sum() {
            applyChanges();
            return sum;
        }

        public int query(int from, int to) {
            applyChanges();
            if (this.from == from && this.to == to) {
                return sum;
            }
            if (left.to >= to) {
                return left.query(from, to);
            }
            if (from >= right.from) {
                return right.query(from, to);
            }
            return left.query(from, left.to) + right.query(right.from, to);
        }

        public void update(int from, int to, int inv) {
            if (this.from == from && this.to == to) {
                this.inv = this.inv ^ inv;
                applyChanges();
                return;
            }
            applyChanges();
            if (left.to >= to) {
                left.update(from, to, inv);
                sum = left.sum() + right.sum();
                return;
            }
            if (from >= right.from) {
                right.update(from, to, inv);
                sum = left.sum() + right.sum();
                return;
            }
            left.update(from, left.to, inv);
            right.update(right.from, to, inv);
            sum = left.sum() + right.sum();
        }

        public void applyChanges() {
            if (inv == 1) {
                sum = (to - from + 1) - sum;
                if (from != to) {
                    left.inv = left.inv ^ inv;
                    right.inv = right.inv ^ inv;
                }
                inv = 0;
            }
        }
    }

    static class Node {

        int from, to;
        int val;
        List<Integer> childs = new ArrayList<>();
    }

    static class Pos implements Comparable<Pos> {
        int val, ind;

        public Pos(int val, int ind) {
            this.val = val;
            this.ind = ind;
        }

        @Override
        public int compareTo(Pos o) {
            return Integer.compare(val, o.val);
        }
    }

    static class Pt{
        long x, y;

        public Pt(long x, long y) {
            this.x = x;
            this.y = y;
        }
    }
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

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

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            try {
                return br.readLine();
            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException();
            }
        }

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

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

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

        int[] nextIntArray(int n) {
            int[] res = new int[n];
            for (int i = 0; i < n; i++) res[i] = nextInt();
            return res;
        }

        long[] nextLongArray(int n) {
            long[] res = new long[n];
            for (int i = 0; i < n; i++) res[i] = nextLong();
            return res;
        }

        String[] nextStringArray(int n) {
            String[] res = new String[n];
            for (int i = 0; i < n; i++) res[i] = nextToken();
            return res;
        }
    }

    static class PrefixSums {
        long[] sums;

        public PrefixSums(long[] sums) {
            this.sums = sums;
        }

        public long sum(int fromInclusive, int toExclusive) {
            if (fromInclusive > toExclusive) throw new IllegalArgumentException("Wrong value");
            return sums[toExclusive] - sums[fromInclusive];
        }

        public static PrefixSums of(int[] ar) {
            long[] sums = new long[ar.length + 1];
            for (int i = 1; i <= ar.length; i++) {
                sums[i] = sums[i - 1] + ar[i - 1];
            }
            return new PrefixSums(sums);
        }

        public static PrefixSums of(long[] ar) {
            long[] sums = new long[ar.length + 1];
            for (int i = 1; i <= ar.length; i++) {
                sums[i] = sums[i - 1] + ar[i - 1];
            }
            return new PrefixSums(sums);
        }
    }

    static class ADUtils {
        static void sort(int[] ar) {
            Random rnd = ThreadLocalRandom.current();
            for (int i = ar.length - 1; i > 0; i--)
            {
                int index = rnd.nextInt(i + 1);
                // Simple swap
                int a = ar[index];
                ar[index] = ar[i];
                ar[i] = a;
            }
            Arrays.sort(ar);
        }

        static void sort(long[] ar) {
            Random rnd = ThreadLocalRandom.current();
            for (int i = ar.length - 1; i > 0; i--)
            {
                int index = rnd.nextInt(i + 1);
                // Simple swap
                long a = ar[index];
                ar[index] = ar[i];
                ar[i] = a;
            }
            Arrays.sort(ar);
        }
    }

    static class MathUtils {
        static long[] FIRST_PRIMES = {
                2,     3,      5,      7,     11,     13,     17,     19,     23,     29,
                31,     37,     41,     43,     47,     53,     59,     61,     67,     71,
                73,     79,     83,     89  ,   97 ,    101,    103,    107,    109,    113,
                127,    131,    137,    139,    149,    151,    157,    163,    167,    173,
                179,    181,    191,    193,    197,    199,    211,    223,    227,    229,
                233,    239,    241,    251,    257,    263,    269,    271,    277,    281,
                283,    293,    307,    311,    313,    317,    331,    337,    347,    349,
                353,    359,    367,    373,    379,    383,    389,    397,    401,    409,
                419,    421,    431,    433,    439,    443,    449,    457,    461,    463,
                467,    479,    487,    491,    499,    503,    509,    521,    523,    541,
                547,    557,    563,    569,    571,    577,    587,    593,    599,    601,
                607,    613,    617,    619,    631,    641,    643,    647,    653,    659,
                661,    673,    677,    683,    691,    701,    709,    719,    727,    733,
                739,    743,    751,    757,    761,    769,    773,    787,    797,    809,
                811,    821,    823,    827,    829,    839,    853,    857,    859,    863,
                877,    881,    883,    887,    907,    911,    919,    929,    937,    941,
                947,    953,    967,    971,    977,    983,    991,    997,   1009,   1013,
                1019,   1021,   1031,   1033,   1039,   1049,   1051};

        static long[] primes(long to) {
            long[] result = Arrays.copyOf(FIRST_PRIMES, 10000);
            int size = FIRST_PRIMES.length;
            a:
            for (long t = 1061; t <= to; t++) {
                for (int i = 0; i < size; i++) {
                    if (t % result[i] == 0) {
                        continue a;
                    }
                }
                result[size++] = t;
            }
            return Arrays.copyOf(result, size);
        }

        static long modpow(long b, long e, long m) {
            long result = 1;

            while (e > 0) {
                if ((e & 1) == 1) {
            /* multiply in this bit's contribution while using modulus to keep
             * result small */
                    result = (result * b) % m;
                }
                b = (b * b) % m;
                e >>= 1;
            }

            return result;
        }

        static long submod(long x, long y, long m) {
            return (x - y + m) % m;
        }
    }
}