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

public class Main
{
    public static long pow(long a, long n, long mod) {
        //		a %= mod;
        long ret = 1;
        int x = 63 - Long.numberOfLeadingZeros(n);
        for (; x >= 0; x--) {
            ret = ret * ret % mod;
            if (n << 63 - x < 0)
                ret = ret * a % mod;
        }
        return ret;
    }
    static class InputReader {

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

        public InputReader(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 double rd() {
            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, ri());
                }
                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,ri());
                    }
                    if (c < '0' || c > '9') {
                        throw new InputMismatchException();
                    }
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }
        public int[] ra(int n)
        {
            int[] a = new int[n];
            for(int i = 0;i < n;i++)a[i] = ri();
            return a;
        }
        public long rl() {
            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 int ri() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int 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 rs() {
            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 c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
    static 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 println(Object...objects)
        {
            print(objects);
            writer.println();
        }
        public void close()
        {
            writer.close();
        }
        public void flush()
        {
            writer.flush();
        }
    }
    static class IOUtils
    {
        public static int[] readIntArray(InputReader in, int size)
        {
            int[] array = new int[size];
            for (int i = 0; i < size; i++)
                array[i] = in.ri();
            return array;
        }
    }
    static InputReader in ;
    static OutputWriter out ;
    public static void main(String [] args)
    {
        in = new InputReader(System.in);
        out = new OutputWriter(System.out);
//        int t = in.ri() ;
//        for (int i = 0; i <t ; i++)
        output();
        out.flush();
        out.close() ;
    }
    // subtree range - iord[i],right[iord[i]]+1
    // vertex - iord[i]
    static void output()
    {
        int n = in.ri() ;
        int [] from = new int[n-1] ;
        int [] to = new int[n-1] ;
        for (int i = 0; i <(n-1) ; i++)
        {
            from[i] = i+1 ;
            to[i] = in.ri()-1 ;
        }
        int [][] g = packU(n,from,to) ;
        int [][] orders = makeRights(g,parents3(g,0)[0],0) ;
        int [] iord = orders[1] ;
        int [] right = orders[2] ;
        SegmentTree st = new SegmentTree(n) ;
        for (int i = 0; i <n ; i++)
        {
            int x = in.ri() ;
            if(x==1)
            {
                st.update(iord[i], iord[i]);
            }
        }
        int q = in.ri() ;
        for (int i = 0; i <q ; i++)
        {
            String s = in.rs() ;
            int v = in.ri()-1 ;
            if(s.equals("get"))
            {
                out.println(st.query(iord[v],right[iord[v]]));
            }
            else
            {
                st.update(iord[v],right[iord[v]]);
            }
        }
    }
    static class SegmentTree
    {
        int n ;
        Node [] tree;
        SegmentTree(int n)
        {
            this.n = n ;
            tree = new Node[4*n] ;
            build(0,n-1,0) ;
        }
        void build(int l,int r,int ind)
        {
            if(l==r)
            {
                tree[ind] = new Node() ;
            }
            else
            {
                int mid = (l + r) >> 1;
                build(l,mid,2*ind+1);
                build(mid+1,r,2*ind+2);
                tree[ind] = new Node() ;
                buildCombine(tree[ind],tree[ind*2+1],tree[ind*2+2]);
            }
        }
        private void push(int l,int r,int ind)
        {
            if(tree[ind].lazy)
            {
                tree[ind].val = (r-l+1)-tree[ind].val ;
                if(l!=r)
                {
                    tree[2*ind+1].lazy ^= true ;
                    tree[2*ind+2].lazy ^= true ;
                }
                tree[ind].lazy = false ;
            }
        }
        private void buildCombine(Node l,Node left,Node right)
        {
            l.val = left.val+right.val ;
        }
        private int queryCombine(int val1,int val2)
        {
            return val1+val2  ;
        }
        private int query(int qL, int qR, int l, int r, int idx)
        {
            push(l, r, idx);
            if(l > qR || r < qL)
                return 0 ;
            if(qL <= l && r <= qR)
                return tree[idx].val;
            int ans = 0 ;
            int mid = (l + r) >> 1;
            ans =  queryCombine(ans,query(qL, qR, l, mid, 2 * idx + 1)) ;
            ans = queryCombine(ans,query(qL, qR, mid + 1, r, 2 * idx + 2));
            return ans ;
        }
        void update(int l,int r)
        {
            update(l,r,0,n-1,0) ;
        }
        int query(int l,int r)
        {
            return query(l,r,0,n-1,0) ;
        }
        void update(int qL, int qR, int l, int r, int ind)
        {
            push(l, r, ind);
            if(qL > r || l > qR)
                return;
            if(qL <= l && r <= qR)
            {
                tree[ind].lazy = true;
                push(l, r, ind);
                return;
            }
            int mid = (l + r) >> 1;
            update(qL, qR, l, mid, 2 * ind + 1);
            update(qL, qR, mid + 1, r, 2 * ind + 2);
            buildCombine(tree[ind],tree[2*ind + 1], tree[2*ind + 2]);
        }
        class Node
        {
            int val ;
            boolean lazy ;
            Node()
            {
                val = 0 ;
                lazy = false ;
            }
        }
    }
    public static int[] sortByPreorder(int[][] g, int root)
    {
        int n = g.length;
        int[] stack = new int[n];
        int[] ord = new int[n];
        boolean[] ved = new boolean[n];
        stack[0] = root;
        int p = 1;
        int r = 0;
        ved[root] = true;
        while(p > 0){
            int cur = stack[p-1];
            ord[r++] = cur;
            p--;
            for(int e : g[cur]){
                if(!ved[e]){
                    ved[e] = true;
                    stack[p++] = e;
                }
            }
        }
        return ord;
    }
    public static int[][] makeRights(int[][] g, int[] par, int root)
    {
        int n = g.length;
        int[] ord = sortByPreorder(g, root);
        int[] iord = new int[n];
        for(int i = 0;i < n;i++)iord[ord[i]] = i;
        int[] right = new int[n];
        for(int i = n-1;i >= 1;i--)
        {
            if(right[i] == 0)right[i] = i;
            int p = iord[par[ord[i]]];
            right[p] = Math.max(right[p], right[i]);
        }
        return new int[][]{ord, iord, right};
    }
    static int[][] packU(int n, int[] from, int[] to)
    {
        int[][] g = new int[n][];
        int[] p = new int[n];
        for (int f : from)
            p[f]++;
        for (int t : to)
            p[t]++;
        for (int i = 0; i < n; i++)
            g[i] = new int[p[i]];
        for (int i = 0; i < from.length; i++) {
            g[from[i]][--p[from[i]]] = to[i];
            g[to[i]][--p[to[i]]] = from[i];
        }
        return g;
    }
    public static int[][] parents3(int[][] g, int root)
    {
        int n = g.length;
        int[] par = new int[n];
        Arrays.fill(par, -1);

        int[] depth = new int[n];
        depth[0] = 0;

        int[] q = new int[n];
        q[0] = root;
        for (int p = 0, r = 1; p < r; p++) {
            int cur = q[p];
            for (int nex : g[cur]) {
                if (par[cur] != nex) {
                    q[r++] = nex;
                    par[nex] = cur;
                    depth[nex] = depth[cur] + 1;
                }
            }
        }
        return new int[][] { par, q, depth };
    }
}