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 = 50000 + 10;
struct query {
  int type, x, y;
} qu[maxn];
int n, fa[maxn];
long long val[maxn], sz[maxn];
vector<int> v[maxn];
bool mark[maxn], have[maxn];
long long d[maxn];
int dfs(int x) {
  sz[x] = 1;
  int ret = 0;
  for (auto i : v[x]) ret += dfs(i), sz[x] += sz[i];
  for (auto i : v[x]) d[i] = (sz[x] - sz[i]) * val[x];
  have[x] = ((ret || mark[x]) ? 1 : 0);
  if (ret >= 2 || mark[x]) {
    mark[x] = 1;
    return 1;
  } else
    return ret;
}
struct P {
  int to, ssum;
  long long dsum;
};
vector<P> v2[maxn];
int fa2[maxn];
long long sz2[maxn], sz2sum[maxn];
long long pnum[maxn];
void dfs2(int x, bool isfir = 0) {
  if (v2[x].empty()) {
    if (!isfir) return;
    pnum[x] = sz[x] * sz[x];
    for (auto i : v[x]) pnum[x] -= sz[i] * sz[i];
    return;
  }
  sz[x] = 1 + sz2[x];
  pnum[x] = 0;
  for (auto i : v2[x])
    dfs2(i.to, isfir), sz[x] += sz[i.to] + i.ssum,
        pnum[x] -= (sz[i.to] + i.ssum) * (sz[i.to] + i.ssum);
  pnum[x] += sz[x] * sz[x] - sz2sum[x];
}
int getid(int x, int y) {
  for (int i = 0;; i++)
    if (v2[x][i].to == y) return i;
}
void build_graph(int num) {
  fill(mark, mark + n + 1, 0);
  fill(have, have + n + 1, 0);
  for (int i = 1; i <= n; i++) v[i].clear(), v2[i].clear();
  for (int i = 2; i <= n; i++) v[fa[i]].push_back(i);
  for (int i = 0; i < num; i++) {
    mark[qu[i].x] = 1;
    if (qu[i].type == 1) mark[qu[i].y] = 1;
  }
  mark[1] = 1;
  dfs(1);
  for (int i = 1; i <= n; i++)
    if (mark[i]) {
      sz2[i] = sz2sum[i] = 0;
      for (auto j : v[i])
        if (!have[j]) sz2[i] += sz[j], sz2sum[i] += sz[j] * sz[j];
    }
  for (int i = 2; i <= n; i++)
    if (mark[i]) {
      int j, ssum = 0;
      long long dsum = 0LL;
      for (j = i;; j = fa[j]) {
        dsum += d[j];
        if (mark[fa[j]]) break;
      }
      ssum = sz[j] - sz[i];
      j = fa[j];
      v2[j].push_back((P){i, ssum, dsum});
      fa2[i] = j;
    }
}
bool first = 1;
void process(int num) {
  build_graph(num);
  long long nowans = 0LL, tot = (long long)n * n;
  for (int i = 1; i <= n; i++) {
    long long add = sz[i] * sz[i];
    for (auto j : v[i]) add -= sz[j] * sz[j];
    nowans += add * val[i];
  }
  if (first) printf("%.15f\n", ((double)nowans) / tot), first = 0;
  dfs2(1, 1);
  for (int i = 0; i < num; i++) {
    if (qu[i].type == 2) {
      int x = qu[i].x, nval = qu[i].y;
      nowans += pnum[x] * (nval - val[x]);
      for (auto &j : v2[x])
        j.dsum += (sz[x] - j.ssum - sz[j.to]) * (nval - val[x]);
      val[x] = nval;
      printf("%.15f\n", ((double)nowans) / tot);
      continue;
    }
    int x = qu[i].y, y = qu[i].x, id;
    for (int j = x; j != 1; j = fa2[j])
      if (j == y || y == 1) {
        swap(x, y);
        break;
      }
    fa[y] = x;
    long long dif = 0LL;
    for (int j = y; j != 1; j = fa2[j]) {
      id = getid(fa2[j], j);
      dif -= v2[fa2[j]][id].dsum;
    }
    for (int j = y; j != 1; j = fa2[j]) {
      sz[fa2[j]] -= sz[y];
      for (auto &k : v2[fa2[j]])
        if (k.to != j) k.dsum -= val[fa2[j]] * sz[y];
    }
    int f = fa2[y];
    id = getid(f, y);
    sz2[f] += v2[f][id].ssum;
    sz2sum[f] += (long long)v2[f][id].ssum * v2[f][id].ssum;
    swap(v2[f][id], v2[f][v2[f].size() - 1]);
    v2[f].pop_back();
    v2[x].push_back((P){y, 0, val[x] * sz[x]});
    fa2[y] = x;
    if (v2[f].empty()) pnum[f] = sz[f] * sz[f] - sz2sum[f];
    for (int j = y; j != 1; j = fa2[j]) {
      sz[fa2[j]] += sz[y];
      for (auto &k : v2[fa2[j]])
        if (k.to != j) k.dsum += val[fa2[j]] * sz[y];
      id = getid(fa2[j], j);
      dif += v2[fa2[j]][id].dsum;
    }
    nowans += 2 * dif * sz[y];
    printf("%.15f\n", ((double)nowans) / tot);
    dfs2(1);
  }
}
int main() {
  scanf("%d", &n);
  fa[1] = 1;
  for (int i = 2; i <= n; i++) scanf("%d", &fa[i]);
  for (int i = 1; i <= n; i++) scanf("%I64d", &val[i]);
  int Q;
  scanf("%d", &Q);
  int sq = (int)sqrt(Q + 0.5);
  for (int i = 0; i < Q; i++) {
    char c[5];
    scanf("%s%d%d", c, &qu[i % sq].x, &qu[i % sq].y);
    qu[i % sq].type = (c[0] == 'P' ? 1 : 2);
    if ((i % sq) == sq - 1 || i == Q - 1) process(i % sq + 1);
  }
}