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;
vector<int> adj[55555];
int vis[55555], times, st, en, pa[55555], down[55555], dist[55555], up[55555];
int value[55555], n, m;
int bound;
double inf = 1e20, ans, coef[55555], change[55555], now[55555], nw, size[55555];
struct query {
  char flag;
  int v, u;
};
query qr[55555];
void dfs(int id) {
  int i, j, s, p, q, ip, only;
  size[id] = 1;
  now[id] = 0;
  only = id;
  for (i = 0; i < adj[id].size(); i++) {
    ip = adj[id][i];
    dist[ip] = dist[id] + 1;
    dfs(ip);
    size[id] += size[ip];
    ans -= (double)size[ip] * (double)size[ip] * (double)value[id];
    now[id] -= (double)size[ip] * (double)size[ip];
    if (down[ip] >= 0) {
      if (down[id] < 0) {
        down[id] = down[ip];
        only = ip;
      } else
        vis[id] = times;
    }
  }
  ans += (double)size[id] * (double)size[id] * (double)value[id];
  now[id] += (double)size[id] * (double)size[id];
  if (vis[id] == times) {
    down[id] = id;
    only = id;
  }
  if (vis[id] == times)
    coef[id] = 0;
  else
    coef[id] =
        coef[only] + 2.0 * (double)(size[only] - size[id]) * (double)value[id];
}
void perform(int st, int en) {
  int i, j, s, p, q, u, v, ip;
  double x;
  times++;
  for (i = 0; i < n; i++) {
    adj[i].clear();
    down[i] = -1;
    size[i] = 0;
    now[i] = 0;
    coef[i] = 0;
  }
  for (i = 1; i < n; i++) adj[pa[i]].push_back(i);
  for (i = st; i <= en; i++) {
    if (qr[i].flag == 'P')
      vis[qr[i].v] = vis[qr[i].u] = times;
    else
      vis[qr[i].v] = times;
  }
  dist[0] = 0;
  ans = 0;
  dfs(0);
  for (i = 0; i < n; i++) up[i] = i;
  for (i = 0; i < n; i++) {
    if (dist[i] < dist[up[down[i]]]) up[down[i]] = i;
  }
  if (st > en && en < 0) printf("%.20f\n", ans / ((double)n * (double)n));
  for (i = st; i <= en; i++) {
    u = qr[i].u;
    v = qr[i].v;
    if (qr[i].flag == 'P') {
      ip = u;
      while (true) {
        ip = pa[up[ip]];
        if (ip == v || ip == 0) break;
      }
      if (ip == v) swap(u, v);
      x = size[v];
      ip = v;
      while (true) {
        if (up[ip] != ip || ip == 0) size[ip] -= x;
        ip = up[ip];
        ans += coef[ip] * x;
        if (ip == 0) break;
        now[pa[ip]] += 2.0 * (size[ip] - size[pa[ip]]) * x;
        ans += 2 * (size[ip] - size[pa[ip]]) * x * value[pa[ip]];
        size[ip] -= x;
        ip = pa[ip];
      }
      pa[v] = u;
      up[v] = v;
      ip = v;
      while (true) {
        if (up[ip] != ip || ip == 0) size[ip] += x;
        ip = up[ip];
        ans -= coef[ip] * x;
        if (ip == 0) break;
        now[pa[ip]] += 2.0 * (size[pa[ip]] - size[ip]) * x;
        ans += 2 * (size[pa[ip]] - size[ip]) * x * value[pa[ip]];
        size[ip] += x;
        ip = pa[ip];
      }
    } else {
      v = qr[i].v;
      ans += (double)(u - value[v]) * now[v];
      value[v] = u;
    }
    printf("%.20f\n", ans / ((double)n * (double)n));
  }
}
int main() {
  int nt, i, j, s, p, q, id, u, v, h, k, ip, siz;
  char flag;
  scanf("%d", &n);
  for (i = 1; i < n; i++) {
    scanf("%d", &pa[i]);
    pa[i]--;
  }
  for (i = 0; i < n; i++) scanf("%d", &value[i]);
  memset(vis, -1, sizeof(vis));
  times = 0;
  scanf("%d", &m);
  bound = 500;
  st = 0;
  for (i = 0; i < m; i++) {
    flag = getchar();
    while (flag != 'P' && flag != 'V') flag = getchar();
    scanf("%d%d", &v, &u);
    v--;
    if (flag == 'P') u--;
    qr[i].v = v;
    qr[i].u = u;
    qr[i].flag = flag;
    if (i % bound == 0) {
      perform(st, i - 1);
      st = i;
    }
  }
  perform(st, i - 1);
  return 0;
}