1 #include<cstdio>
  2 #include<algorithm>
  3 #include<cstring>
  4 using namespace std;
  5 const int N=100010;
  6 struct node{int ch[2],fa,t,num;long long v,sum,tag;}tr[N<<1];
  7 struct edge{int next,to;}e[N];
  8 int n,m,f,root,cnt;
  9 int head[N],q[N<<1],s[N<<1];
 10 int read()
 11 {
 12     int x=0,f=1;char c=getchar();
 13     while(c<‘0‘||c>‘9‘){if(c==‘-‘)f=-1;c=getchar();}
 14     while(c>=‘0‘&&c<=‘9‘){x=x*10+c-‘0‘;c=getchar();}
 15     return x*f;
 16 }
 17 void insert(int a,int b){cnt++;e[cnt].to=b;e[cnt].next=head[a];head[a]=cnt;}
 18 void dfs(int x)
 19 {
 20     q[++cnt]=x+1;
 21     for(int i=head[x];i;i=e[i].next)dfs(e[i].to);
 22     q[++cnt]=x+n+1;
 23 }
 24 void add(int x,long long tag){tr[x].sum+=tag*tr[x].num;tr[x].v+=tag*tr[x].t;}
 25 void pushup(int x)
 26 {
 27     int l=tr[x].ch[0],r=tr[x].ch[1];
 28     tr[x].num=tr[l].num+tr[r].num+tr[x].t;
 29     tr[x].sum=tr[l].sum+tr[r].sum+tr[x].v;
 30 }
 31 void pushdown(int x)
 32 {
 33     int l=tr[x].ch[0],r=tr[x].ch[1];long long tag=tr[x].tag;
 34     if(l)tr[l].tag+=tag,add(l,tag);
 35     if(r)tr[r].tag+=tag,add(r,tag);
 36     tr[x].tag=0;
 37 }
 38 void rotate(int x,int& k)
 39 {
 40     int y=tr[x].fa,z=tr[y].fa,l,r;
 41     if(tr[y].ch[0]==x)l=0;else l=1;r=l^1;
 42     if(y==k)k=x;
 43     else{if(tr[z].ch[0]==y)tr[z].ch[0]=x;else tr[z].ch[1]=x;}
 44     tr[x].fa=z;tr[y].fa=x;tr[tr[x].ch[r]].fa=y;
 45     tr[y].ch[l]=tr[x].ch[r];tr[x].ch[r]=y;
 46     pushup(y);pushup(x);
 47 }
 48 void splay(int x,int& k)
 49 {
 50     int top=0;s[++top]=x;
 51     for(int i=x;tr[i].fa;i=tr[i].fa)s[++top]=tr[i].fa;
 52     for(int i=top;i;i--)if(tr[s[i]].tag)pushdown(s[i]);
 53     while(x!=k)
 54     {
 55         int y=tr[x].fa,z=tr[y].fa;
 56         if(y!=k)
 57         {
 58             if((tr[y].ch[0]==x)^(tr[z].ch[0]==y))rotate(x,k);
 59             else rotate(y,k);
 60         }
 61         rotate(x,k);
 62     }
 63 }
 64 int find(int x){while(tr[x].ch[1])x=tr[x].ch[1];return x;}
 65 void build(int l,int r,int last)
 66 {
 67     if(l>r)return;
 68     int mid=(l+r)>>1;
 69     tr[q[mid]].fa=q[last];
 70     tr[q[last]].ch[mid>last]=q[mid];
 71     build(l,mid-1,mid);build(mid+1,r,mid);
 72     pushup(q[mid]);
 73 }
 74 int merge(int r1,int r2)
 75 {
 76     int w=find(r1);
 77     splay(w,r1);
 78     tr[w].ch[1]=r2;
 79     tr[r2].fa=w;
 80     pushup(w);
 81     return w;
 82 }
 83 void cutl(int x,int rt,int& r1,int& r2)
 84 {
 85     splay(x,rt);
 86     r1=tr[x].ch[0];r2=x;
 87     tr[x].ch[0]=0;
 88     tr[r1].fa=0;
 89     pushup(x);
 90 }
 91 void cutr(int x,int rt,int& r1,int& r2)
 92 {
 93     splay(x,rt);
 94     r1=x;r2=tr[x].ch[1];
 95     tr[x].ch[1]=0;
 96     tr[r2].fa=0;
 97     pushup(x);
 98 }
 99 void query()
100 {
101     int x=read()+1;
102     splay(x,root);
103     printf("%lld\n",tr[tr[x].ch[0]].sum+tr[x].v);
104 }
105 void change()
106 {
107     int x=read()+1,y=x+n,k=read()+1,p1,p2,p3;
108     cutl(x,root,p1,p2);
109     cutr(y,p2,p2,p3);
110     cutr(k,merge(p1,p3),p1,p3);
111     root=merge(merge(p1,p2),p3);
112 }
113 void add()
114 {
115     int x=read()+1,y=x+n;long long tag=read();
116     splay(x,root);splay(y,tr[x].ch[1]);
117     int z=tr[y].ch[0];
118     add(x,tag);add(y,tag);
119     add(z,tag);tr[z].tag+=tag;
120     pushup(y);pushup(x);
121 }
122 int main()
123 {
124     char str[5];
125     n=read();
126     for(int i=2;i<=n;i++)f=read(),insert(f,i);
127     for(int i=2;i<=n+1;i++)f=read(),tr[i].v=f,tr[i].t=1,tr[i+n].v=-f,tr[i+n].t=-1;
128     cnt=0;q[++cnt]=1;dfs(1);q[++cnt]=2*n+2;
129     build(1,2*n+2,0);root=q[n+1];
130     m=read();
131     while(m--)
132     {
133         scanf("%s",str);
134         if(str[0]==‘Q‘)query();
135         if(str[0]==‘C‘)change();
136         if(str[0]==‘F‘)add();
137     }
138     return 0;
139 }