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;
inline int read() {
  int w = 1, s = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    s = s * 10 + ch - '0';
    ch = getchar();
  }
  return w * s;
}
struct node {
  int to, next;
} e[100010];
int tot, h[50010], n, Sum[50010], _Sum[50010], fa[50010], ch[50010][2],
    S[50010], rev[50010];
long long tag[50010];
long long V[50010], W[50010];
long long Ans = 0;
inline int getf(int x) { return ch[fa[x]][1] == x; }
inline int isroot(int x) { return ch[fa[x]][1] != x && ch[fa[x]][0] != x; }
inline void Update(int x) {
  Sum[x] = Sum[ch[x][1]] + Sum[ch[x][0]] + _Sum[x];
  W[x] = 1ll * S[x] * _Sum[x] + W[ch[x][0]] + W[ch[x][1]];
}
inline void Push(int x, long long d) {
  tag[x] += d;
  V[x] += d * _Sum[x];
}
inline void Pushdown(int x) {
  if (tag[x]) {
    if (ch[x][0]) Push(ch[x][0], tag[x]);
    if (ch[x][1]) Push(ch[x][1], tag[x]);
    tag[x] = 0;
    return;
  }
}
inline void Rotate(int x) {
  int old = fa[x], oldf = fa[old], whichx = getf(x);
  ch[old][whichx] = ch[x][whichx ^ 1];
  fa[ch[old][whichx]] = old;
  if (!isroot(old)) ch[oldf][getf(old)] = x;
  fa[x] = oldf;
  fa[old] = x;
  ch[x][whichx ^ 1] = old;
  Update(old);
  Update(x);
}
int Sta[50010], top;
inline void Splay(int x) {
  top = 0;
  Sta[top = 1] = x;
  for (register int i = x; !isroot(i); i = fa[i]) Sta[++top] = fa[i];
  for (register int i = top; i; --i) Pushdown(Sta[i]);
  for (register int f; !isroot(x); Rotate(x))
    if (!isroot(f = fa[x])) Rotate(getf(x) == getf(f) ? f : x);
}
inline void Access(int v) {
  for (register int t = 0; v; t = v, v = fa[v]) {
    Splay(v);
    _Sum[v] += Sum[ch[v][1]];
    ch[v][1] = t;
    _Sum[v] -= Sum[ch[v][1]];
    Update(v);
  }
}
inline int findrt(int v) {
  Splay(v);
  while (ch[v][0]) v = ch[v][0];
  return v;
}
inline void add(int from, int to) {
  e[++tot].next = h[from];
  h[from] = tot;
  e[tot].to = to;
}
inline void DFS(int now, int ffa) {
  Sum[now] = 1;
  fa[now] = ffa;
  Ans += S[now];
  V[now] += 1;
  for (register int i = h[now]; i; i = e[i].next) {
    int to = e[i].to;
    if (to == ffa) continue;
    DFS(to, now);
    Ans += 1ll * Sum[now] * Sum[to] * S[now] * 2;
    V[now] += 1ll * Sum[now] * Sum[to] * 2;
    Sum[now] += Sum[to];
  }
  _Sum[now] = Sum[now];
  Update(now);
}
inline void Gao(int x, int px) {
  Access(x);
  Splay(x);
  int Anc = ch[x][0];
  while (ch[Anc][1]) Anc = ch[Anc][1];
  if (Anc == px) return;
  Access(Anc);
  Splay(Anc);
  Splay(x);
  _Sum[Anc] -= Sum[x];
  Push(Anc, 1ll * (-2) * Sum[x]);
  Update(Anc);
  Ans -= W[Anc] * 2 * Sum[x];
  Access(px);
  Splay(px);
  Push(px, 1ll * 2 * Sum[x]);
  _Sum[px] += Sum[x];
  Ans += W[px] * 2 * Sum[x];
  fa[x] = px;
  Update(px);
}
int main() {
  n = read();
  for (register int i = 2; i <= n; ++i) {
    int x = read();
    add(x, i);
  }
  for (register int i = 1; i <= n; ++i) {
    S[i] = read();
  }
  DFS(1, 0);
  int Q = read();
  printf("%.10lf\n", 1.0 * Ans / (double)(1ll * n * n));
  while (Q--) {
    char s[10];
    scanf("%s", s + 1);
    if (s[1] == 'P') {
      int v = read(), u = read();
      Access(u);
      int rt = findrt(v);
      if (rt == 1)
        Gao(u, v);
      else
        Gao(v, u);
    } else {
      int u = read(), t = read();
      Splay(u);
      Ans += (t - S[u]) * V[u];
      S[u] = t;
    }
    printf("%.10lf\n", 1.0 * Ans / (double)(1ll * n * n));
  }
  return 0;
}