Problem: You have a root tree containing n vertexes. Let's number the tree vertexes with integers from 1 to n. The tree root is in the vertex 1.

Each vertex (except fot the tree root) v has a direct ancestor pv. Also each vertex v has its integer value sv. 

Your task is to perform following queries:

  * P v u (u ≠ v). If u isn't in subtree of v, you must perform the assignment pv = u. Otherwise you must perform assignment pu = v. Note that after this query the graph continues to be a tree consisting of n vertexes.
  * V v t. Perform assignment sv = t. 



Your task is following. Before starting performing queries and after each query you have to calculate expected value written on the lowest common ancestor of two equiprobably selected vertices i and j. Here lowest common ancestor of i and j is the deepest vertex that lies on the both of the path from the root to vertex i and the path from the root to vertex j. Please note that the vertices i and j can be the same (in this case their lowest common ancestor coincides with them).

Input

The first line of the input contains integer n (2 ≤ n ≤ 5·104) — the number of the tree vertexes. 

The second line contains n - 1 integer p2, p3, ..., pn (1 ≤ pi ≤ n) — the description of the tree edges. It is guaranteed that those numbers form a tree.

The third line contains n integers — s1, s2, ... sn (0 ≤ si ≤ 106) — the values written on each vertex of the tree.

The next line contains integer q (1 ≤ q ≤ 5·104) — the number of queries. Each of the following q lines contains the description of the query in the format described in the statement. It is guaranteed that query arguments u and v lie between 1 and n. It is guaranteed that argument t in the queries of type V meets limits 0 ≤ t ≤ 106.

Output

Print q + 1 number — the corresponding expected values. Your answer will be considered correct if its absolute or relative error doesn't exceed 10 - 9.

Examples

Input

5
1 2 2 1
1 2 3 4 5
5
P 3 4
P 4 5
V 2 3
P 5 2
P 1 4


Output

1.640000000
1.800000000
2.280000000
2.320000000
2.800000000
1.840000000

Note

Note that in the query P v u if u lies in subtree of v you must perform assignment pu = v. An example of such case is the last query in the sample.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int maxt = (1 << 20) + 10;
int n, q;
long long ans;
int p[maxn], s[maxn];
char buf[10];
int fa[maxt], ch[maxn][2], pp[maxn], sz[maxn], sumsz[maxn], tag[maxn];
long long sum[maxn], sonsz[maxn];
inline int right_son(int f, int x) { return ch[f][1] == x; }
inline void upd(int x) {
  sum[x] = sum[ch[x][0]] + sum[ch[x][1]] + s[x] * 2ll * (sumsz[x] + 1);
}
inline void modify(int x, int v) {
  sz[x] += v;
  tag[x] += v;
}
inline void pushdown(int x) {
  if (!tag[x]) return;
  if (ch[x][0]) modify(ch[x][0], tag[x]);
  if (ch[x][1]) modify(ch[x][1], tag[x]);
  tag[x] = 0;
}
inline void rotate(int x) {
  int f = fa[x], gf = fa[f];
  int p = right_son(f, x), q = p ^ 1;
  ch[f][p] = ch[x][q];
  fa[ch[x][q]] = f;
  ch[x][q] = f;
  fa[f] = x;
  fa[x] = gf;
  if (gf)
    ch[gf][right_son(gf, f)] = x;
  else {
    pp[x] = pp[f];
    pp[f] = 0;
  }
  upd(f);
  upd(x);
}
inline void splay(int x) {
  vector<int> anc;
  anc.clear();
  int tmp = x;
  while (tmp) {
    anc.push_back(tmp);
    tmp = fa[tmp];
  }
  for (int i = anc.size() - 1; i >= 0; i--) {
    pushdown(anc[i]);
  }
  while (fa[x]) {
    int f = fa[x], gf = fa[f];
    if (!gf)
      rotate(x);
    else {
      if (right_son(f, x) == right_son(gf, f)) {
        rotate(f);
        rotate(x);
      } else {
        rotate(x);
        rotate(x);
      }
    }
  }
}
inline void maketree(int x) { fa[x] = ch[x][0] = ch[x][1] = pp[x] = 0; }
inline int access(int x) {
  splay(x);
  int lst = x;
  if (ch[x][1]) {
    int tmp = ch[x][1];
    while (ch[tmp][0]) {
      pushdown(tmp);
      tmp = ch[tmp][0];
    }
    sumsz[x] += sz[tmp];
    sonsz[x] += sz[tmp] * 1ll * sz[tmp];
    pp[ch[x][1]] = x;
    fa[ch[x][1]] = 0;
    ch[x][1] = 0;
    upd(x);
  }
  while (pp[x]) {
    int y = pp[x];
    splay(y);
    lst = y;
    if (ch[y][1]) {
      int tmp = ch[y][1];
      while (ch[tmp][0]) {
        pushdown(tmp);
        tmp = ch[tmp][0];
      }
      sumsz[y] += sz[tmp];
      sonsz[y] += sz[tmp] * 1ll * sz[tmp];
      pp[ch[y][1]] = y;
      fa[ch[y][1]] = 0;
      ch[y][1] = 0;
      upd(y);
    }
    int tmp = x;
    while (ch[tmp][0]) {
      pushdown(tmp);
      tmp = ch[tmp][0];
    }
    sumsz[y] -= sz[tmp];
    sonsz[y] -= sz[tmp] * 1ll * sz[tmp];
    pp[x] = 0;
    fa[x] = y;
    ch[y][1] = x;
    upd(y);
    splay(x);
  }
  return lst;
}
inline int getpath(int x) {
  access(x);
  return sum[x];
}
inline void link(int x, int y) {
  access(x);
  access(y);
  fa[y] = x;
  ch[x][0] = y;
  upd(y);
  upd(x);
}
inline void cut(int x) {
  access(x);
  fa[ch[x][0]] = 0;
  ch[x][0] = 0;
  upd(x);
  int tmp = p[x];
  sumsz[tmp] += sz[x];
  sonsz[tmp] += sz[x] * 1ll * sz[x];
  access(tmp);
  upd(tmp);
}
inline void changeval(int x, int v) {
  access(x);
  ans += (v - s[x]) * 1ll * (sz[x] * 1ll * sz[x] - sonsz[x]);
  s[x] = v;
  upd(x);
}
inline void Printtree(int x) {
  if (ch[x][0]) Printtree(ch[x][0]);
  if (ch[x][1]) Printtree(ch[x][1]);
}
inline void changepos(int x, int y) {
  access(y);
  int lst = access(x);
  if (lst == y) swap(x, y);
  cut(y);
  int cutsz = sz[y];
  int f = p[y];
  access(f);
  ans += -cutsz * 1ll * sum[f] + 2ll * cutsz * cutsz * s[f];
  modify(f, -cutsz);
  sumsz[f] -= cutsz;
  sonsz[f] -= cutsz * 1ll * cutsz;
  upd(f);
  access(x);
  ans += cutsz * 1ll * sum[x];
  link(y, x);
  access(x);
  modify(x, cutsz);
  upd(x);
  p[y] = x;
}
vector<int> g[maxn];
void dfs(int x, int fa) {
  sz[x] = 1;
  for (int i = 0; i < g[x].size(); i++) {
    dfs(g[x][i], x);
    sz[x] += sz[g[x][i]];
  }
  ans += sz[x] * 1ll * sz[x] * (s[x] - s[fa]);
  upd(x);
  for (int i = 0; i < g[x].size(); i++) {
    link(g[x][i], x);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    scanf("%d", &p[i]);
    g[p[i]].push_back(i);
  }
  for (int i = 1; i <= n; i++) scanf("%d", &s[i]);
  scanf("%d", &q);
  dfs(1, 0);
  printf("%.10lf\n", 1.0 * ans / n / n);
  while (q--) {
    scanf("%s", buf);
    if (buf[0] == 'P') {
      int v, u;
      scanf("%d%d", &v, &u);
      changepos(u, v);
    } else {
      int v, t;
      scanf("%d%d", &v, &t);
      changeval(v, t);
    }
    printf("%.10lf\n", 1.0 * ans / n / n);
  }
  return 0;
}