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;
typedef int Arr[50005];
typedef long long Arrr[50005];
int N;
long long Ans;
Arr fa, l, r, st, sz, szz, jia_sz, jia_szz;
Arrr val, V, VS, VSS, SZ;
vector<int> Ed[50005];
inline int IN() {
  register int x = 0;
  char c;
  while ((c = getchar()) < 48)
    ;
  for (; c > 47; (c = getchar())) x = x * 10 + c - 48;
  return x;
}
inline void Link(int u, int v) { Ed[fa[v] = u].push_back(v); }
void dfs(int u) {
  for (int v : Ed[u]) dfs(v), sz[u] += sz[v], SZ[u] += 1ll * sz[v] * sz[v];
  long long _ = sz[u]++;
  for (int v : Ed[u]) _ += sz[v] * (1ll * sz[u] - sz[v]);
  Ans += val[u] * _;
  VS[u] = val[u] * sz[u];
  V[u] = val[u];
}
inline void upd(int u) {
  V[u] = V[l[u]] + V[r[u]] + val[u];
  VS[u] = VS[l[u]] + VS[r[u]] + val[u] * sz[u];
  VSS[u] = VSS[l[u]] + VSS[r[u]] + val[u] * szz[u];
}
inline void Mdy(int u, int x, int op) {
  if (!u) return;
  if (op == 0) {
    VS[u] += V[u] * x;
    sz[u] += x;
    jia_sz[u] += x;
  }
  if (op == 1) {
    SZ[u] += 2ll * szz[u] * x + 1ll * x * x;
    szz[u] += x;
    VSS[u] += V[u] * x;
    jia_szz[u] += x;
  }
}
inline void Dn(int u) {
  if (jia_sz[u]) {
    Mdy(l[u], jia_sz[u], 0);
    Mdy(r[u], jia_sz[u], 0);
    jia_sz[u] = 0;
  }
  if (jia_szz[u]) {
    Mdy(l[u], jia_szz[u], 1);
    Mdy(r[u], jia_szz[u], 1);
    jia_szz[u] = 0;
  }
}
inline void zig(int x) {
  int y = fa[x], z = fa[y], t = r[x];
  if (!(l[fa[y]] ^ y && r[fa[y]] ^ y))
    if (l[z] == y)
      l[z] = x;
    else
      r[z] = x;
  fa[x] = z;
  if (t) fa[t] = y;
  l[y] = t;
  fa[y] = x;
  r[x] = y;
  upd(y);
}
inline void zag(int x) {
  int y = fa[x], z = fa[y], t = l[x];
  if (!(l[fa[y]] ^ y && r[fa[y]] ^ y))
    if (l[z] == y)
      l[z] = x;
    else
      r[z] = x;
  fa[x] = z;
  if (t) fa[t] = y;
  r[y] = t;
  fa[y] = x;
  l[x] = y;
  upd(y);
}
inline void splay(int x) {
  int u = x;
  for (; !(l[fa[u]] ^ u && r[fa[u]] ^ u); u = fa[u]) st[++*st] = u;
  for (Dn(u); *st; --*st) Dn(st[*st]);
  while (!(l[fa[x]] ^ x && r[fa[x]] ^ x)) {
    int y = fa[x], z = fa[y];
    if (!(l[fa[y]] ^ y && r[fa[y]] ^ y))
      if (y == l[z])
        if (x == l[y])
          zig(y), zig(x);
        else
          zag(x), zig(x);
      else if (x == r[y])
        zag(y), zag(x);
      else
        zig(x), zag(x);
    else if (x == l[y])
      zig(x);
    else
      zag(x);
  }
  upd(x);
}
inline int Lu(int x) {
  int u = x;
  for (; l[u]; u = l[u]) Dn(u);
  return sz[u];
}
inline int access(int x) {
  int y = 0;
  for (; x; y = x, x = fa[x]) {
    splay(x);
    r[x] = y;
    szz[x] = Lu(y);
    upd(x);
  }
  return y;
}
inline int lca(int u, int v) {
  access(u);
  return access(v);
}
inline int FA(int x) {
  splay(x);
  if (!l[x]) return fa[x];
  int u = l[x];
  for (; r[u]; u = r[u])
    ;
  return u;
}
inline void Pri() { printf("%.6lf\n", 1. * Ans / N / N); }
int main() {
  N = IN();
  for (int i = 2, _r = N; i <= _r; ++i) Link(IN(), i);
  for (int i = 1, _r = N; i <= _r; ++i) Ans += (val[i] = IN());
  dfs(1);
  Pri();
  for (int Tc = IN(); Tc--; Pri())
    if (getchar() == 'P') {
      int u = IN(), v = IN(), x;
      if (lca(u, v) == u) swap(u, v);
      x = FA(u);
      access(x);
      splay(x);
      Ans -= 2 * sz[u] * (VS[x] - VSS[x] - val[x] * sz[u]);
      Mdy(x, -sz[u], 0);
      Dn(x);
      Mdy(l[x], -sz[u], 1);
      SZ[x] -= 1ll * sz[u] * sz[u];
      access(v);
      splay(v);
      Ans += 2 * sz[u] * (VS[v] - VSS[v]);
      fa[u] = v;
      Mdy(v, sz[u], 0);
      Dn(v);
      Mdy(l[v], sz[u], 1);
      SZ[v] += 1ll * sz[u] * sz[u];
    } else {
      int u = IN(), t = IN() - val[u];
      splay(u);
      Ans += t * (1ll * sz[u] * sz[u] - SZ[u]);
      val[u] += t;
      upd(u);
    }
}