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;
  long long ssz, dsum;
};
vector<P> v2[maxn];
int fa2[maxn];
long long 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;
  }
  pnum[x] = sz[x] * sz[x] - sz2sum[x];
  for (auto i : v2[x]) dfs2(i.to, isfir), pnum[x] -= i.ssz * i.ssz;
}
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]) {
      sz2sum[i] = 0;
      for (auto j : v[i])
        if (!have[j]) sz2sum[i] += sz[j] * sz[j];
      if (i == 1) continue;
      int j;
      long long ssz = 0LL, dsum = 0LL;
      for (j = i;; j = fa[j]) {
        dsum += d[j];
        if (mark[fa[j]]) break;
      }
      ssz = sz[j];
      j = fa[j];
      v2[j].push_back((P){i, ssz, dsum});
      fa2[i] = j;
    }
}
long long nowans;
void process_query(int qid) {
  if (qu[qid].type == 2) {
    int x = qu[qid].x, nval = qu[qid].y;
    nowans += pnum[x] * (nval - val[x]);
    for (auto &i : v2[x]) i.dsum += (sz[x] - i.ssz) * (nval - val[x]);
    val[x] = nval;
    printf("%.15f\n", ((double)nowans) / n / n);
    return;
  }
  int x = qu[qid].y, y = qu[qid].x, id;
  for (int i = x; i != 1; i = fa2[i])
    if (i == y || y == 1) {
      swap(x, y);
      break;
    }
  fa[y] = x;
  long long dif = 0LL;
  for (int i = y; i != 1; i = fa2[i]) {
    sz[fa2[i]] -= sz[y];
    for (auto &k : v2[fa2[i]])
      if (k.to != i)
        k.dsum -= val[fa2[i]] * sz[y];
      else
        dif -= k.dsum, k.ssz -= sz[y];
  }
  int f = fa2[y];
  P &e = v2[f][getid(f, y)];
  sz2sum[f] += e.ssz * e.ssz;
  swap(e, v2[f].back());
  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 i = y; i != 1; i = fa2[i]) {
    sz[fa2[i]] += sz[y];
    for (auto &k : v2[fa2[i]])
      if (k.to != i)
        k.dsum += val[fa2[i]] * sz[y];
      else
        dif += k.dsum, k.ssz += sz[y];
  }
  nowans += 2 * dif * sz[y];
  printf("%.15f\n", ((double)nowans) / n / n);
  dfs2(1);
}
bool first = 1;
void process(int num) {
  build_graph(num);
  nowans = 0LL;
  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) / n / n), first = 0;
  dfs2(1, 1);
  for (int i = 0; i < num; i++) process_query(i);
}
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);
  }
}