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.
#include <bits/stdc++.h>
using namespace std;
const int N = 70000;
int l[N], r[N], fa[N];
int n, m;
long long ans = 0;
struct mes {
  long long sumS;
  int sz;
  int xu;
  long long xuS;
  long long dui;
} a[N], val[N];
inline mes operator+(const mes &a, const mes &b) {
  mes c;
  c.sumS = a.sumS + b.sumS;
  c.sz = a.sz + b.sz;
  c.xu = a.xu + b.xu;
  c.xuS = a.xuS + b.xuS;
  return c;
}
inline bool top(int x) { return (!fa[x]) || (l[fa[x]] != x && r[fa[x]] != x); }
inline void up(int x) {
  a[x] = val[x];
  if (l[x]) a[x] = a[x] + a[l[x]];
  if (r[x]) a[x] = a[x] + a[r[x]];
}
inline void left(int x) {
  int y = fa[x];
  int z = fa[y];
  r[y] = l[x];
  if (l[x]) fa[l[x]] = y;
  fa[x] = z;
  if (l[z] == y)
    l[z] = x;
  else if (r[z] == y)
    r[z] = x;
  fa[y] = x;
  l[x] = y;
  up(y);
  up(x);
}
inline void right(int x) {
  int y = fa[x];
  int z = fa[y];
  l[y] = r[x];
  if (r[x]) fa[r[x]] = y;
  fa[x] = z;
  if (l[z] == y)
    l[z] = x;
  else if (r[z] == y)
    r[z] = x;
  fa[y] = x;
  r[x] = y;
  up(y);
  up(x);
}
inline void splay(int x) {
  while (!top(x)) {
    int y = fa[x];
    int z = fa[y];
    if (top(y)) {
      if (l[y] == x)
        right(x);
      else
        left(x);
    } else {
      if (r[z] == y) {
        if (r[y] == x)
          left(y), left(x);
        else
          right(x), left(x);
      } else {
        if (l[y] == x)
          right(y), right(x);
        else
          left(x), right(x);
      }
    }
  }
}
int getL(int x) {
  while (l[x]) x = l[x];
  return x;
}
inline int access(int x) {
  int y = 0;
  for (; x; y = x, x = fa[x]) {
    splay(x);
    int rx = r[x];
    r[x] = 0;
    if (rx) {
      rx = getL(rx);
      splay(rx);
      val[x].xu += a[rx].xu + a[rx].sz;
      val[x].dui += (a[rx].xu + a[rx].sz) * 1ll * (a[rx].xu + a[rx].sz);
      val[x].xuS = val[x].xu * 1ll * val[x].sumS;
      up(x);
    }
    if (y) {
      splay(y);
      val[x].xu -= a[y].xu + a[y].sz;
      val[x].xuS = val[x].xu * 1ll * val[x].sumS;
      val[x].dui -= (a[y].xu + a[y].sz) * 1ll * (a[y].xu + a[y].sz);
      r[x] = y;
      up(x);
    }
  }
  return y;
}
int p[N];
vector<int> son[N];
void dfs(int x) {
  val[x].sz = 1;
  ans += val[x].sumS;
  for (vector<int>::iterator it = son[x].begin(); it != son[x].end(); it++) {
    dfs(*it);
    ans += val[x].sz * 2ll * val[*it].sz * val[x].sumS;
    val[x].xu += val[*it].sz;
    val[x].sz += val[*it].sz;
    val[x].dui += val[*it].sz * 1ll * val[*it].sz;
    fa[*it] = x;
  }
  val[x].xuS = val[x].xu * 1ll * val[x].sumS;
}
void duan(int x) {
  access(p[x]);
  int v = p[x];
  splay(x);
  fa[x] = 0;
  p[x] = 0;
  int SS = a[x].sz + a[x].xu;
  splay(v);
  val[v].dui -= SS * 1ll * SS;
  val[v].xu -= SS;
  val[v].xuS = val[v].xu * 1ll * val[v].sumS;
  up(v);
  ans -= a[v].xuS * 2ll * SS;
  ans -= a[v].sumS * 2ll * SS;
}
void lian(int x, int v) {
  access(x);
  access(v);
  splay(x);
  splay(v);
  fa[x] = v;
  p[x] = v;
  int SS = a[x].sz + a[x].xu;
  ans += a[v].xuS * 2ll * SS;
  ans += a[v].sumS * 2ll * SS;
  val[v].dui += 1ll * SS * SS;
  val[v].xu += SS;
  val[v].xuS = val[v].xu * 1ll * val[v].sumS;
  up(v);
}
int main() {
  scanf("%d", &n);
  for (int i = (2); i <= (int)n; i++) {
    scanf("%d", &p[i]);
    son[p[i]].push_back(i);
  }
  for (int i = (1); i <= (int)n; i++) {
    scanf("%I64d", &val[i].sumS);
  }
  dfs(1);
  for (int i = (1); i <= (int)n; i++) {
    val[i].sz = 1;
    up(i);
  }
  scanf("%d", &m);
  while (m--) {
    printf("%.10lf\n", ans / (1. * n * n));
    char opt[3];
    scanf("%s", opt + 1);
    if (opt[1] == 'P') {
      int u, v;
      scanf("%d%d", &v, &u);
      access(u);
      int lca = access(v);
      if (lca == v) {
        duan(u);
        lian(u, v);
      } else {
        duan(v);
        lian(v, u);
      }
    } else {
      int u, v;
      scanf("%d%d", &u, &v);
      access(u);
      splay(u);
      int del = v - val[u].sumS;
      val[u].sumS = v;
      val[u].xuS = val[u].sumS * 1ll * val[u].xu;
      up(u);
      ans += 1ll * del * ((1 + val[u].xu) * 1ll * (1 + val[u].xu) - val[u].dui);
    }
  }
  printf("%.10lf\n", ans / (1. * n * n));
  return 0;
}
