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 double pi = acos(-1);
struct LCT {
  int l, r, fa;
  int sz, sz1, sign;
  long long sz2, sum;
} t[110000];
int n, Q, s[110000], sta[110000], fa[110000];
long long ans;
vector<int> E[110000];
bool isroot(int p) {
  int x = t[p].fa;
  return (!x) || (t[x].l != p && t[x].r != p);
}
void renew(int p) {
  t[p].sum = t[t[p].l].sum + t[t[p].r].sum + 2ll * s[p] * (t[p].sz1 + 1);
}
void modify(int p, int d) {
  if (!p) return;
  t[p].sz += d;
  t[p].sign += d;
}
void updata(int p) {
  if (t[p].sign) {
    modify(t[p].l, t[p].sign);
    modify(t[p].r, t[p].sign);
    t[p].sign = 0;
  }
}
void left(int p) {
  int y = t[p].fa, x = t[y].fa;
  t[p].fa = x;
  t[y].fa = p;
  t[t[p].l].fa = y;
  t[y].r = t[p].l;
  t[p].l = y;
  renew(y);
  renew(p);
  if (t[x].l == y) t[x].l = p;
  if (t[x].r == y) t[x].r = p;
}
void right(int p) {
  int y = t[p].fa, x = t[y].fa;
  t[p].fa = x;
  t[y].fa = p;
  t[t[p].r].fa = y;
  t[y].l = t[p].r;
  t[p].r = y;
  renew(y);
  renew(p);
  if (t[x].l == y) t[x].l = p;
  if (t[x].r == y) t[x].r = p;
}
void splay(int p) {
  int x, y;
  sta[0] = 0;
  for (x = p; !isroot(x); x = t[x].fa) sta[++sta[0]] = x;
  sta[++sta[0]] = x;
  for (int i = sta[0]; i >= 1; --i) updata(sta[i]);
  while (!isroot(p)) {
    y = t[p].fa;
    x = t[y].fa;
    if (isroot(y)) {
      if (t[y].l == p)
        right(p);
      else
        left(p);
      break;
    }
    if (t[x].l == y) {
      if (t[y].l == p)
        right(y), right(p);
      else
        left(p), right(p);
    } else {
      if (t[y].l == p)
        right(p), left(p);
      else
        left(y), left(p);
    }
  }
}
int access(int p) {
  int x = 0;
  for (; p;) {
    splay(p);
    {
      int tmp = t[p].r;
      while (tmp && t[tmp].l) {
        updata(tmp);
        tmp = t[tmp].l;
      }
      t[p].sz1 += t[tmp].sz;
      t[p].sz2 += ((long long)t[tmp].sz) * ((long long)t[tmp].sz);
    }
    t[p].r = x;
    {
      int tmp = x;
      while (tmp && t[tmp].l) {
        updata(tmp);
        tmp = t[tmp].l;
      }
      t[p].sz1 -= t[tmp].sz;
      t[p].sz2 -= ((long long)t[tmp].sz) * ((long long)t[tmp].sz);
    }
    renew(p);
    x = p;
    p = t[p].fa;
  }
  return x;
}
void dfs(int x, int ff) {
  t[x].sz = 1;
  t[x].fa = ff;
  for (int i : E[x]) {
    dfs(i, x);
    t[x].sz += t[i].sz;
    t[x].sz2 += ((long long)t[i].sz) * ((long long)t[i].sz);
  }
  ans += ((long long)t[x].sz) * ((long long)t[x].sz) * (s[x] - s[ff]);
  t[x].sz1 = t[x].sz - 1;
  renew(x);
}
void move(int v, int u) {
  access(v);
  int p = access(u);
  if (p == v) swap(u, v);
  int size = t[v].sz;
  int x = fa[v];
  access(x);
  splay(x);
  ans += -size * t[x].sum + 2 * ((long long)size) * ((long long)size) * s[x];
  modify(x, -size);
  t[x].sz1 -= size;
  t[x].sz2 -= ((long long)size) * ((long long)size);
  renew(x);
  access(u);
  splay(u);
  ans += size * t[u].sum;
  modify(u, size);
  t[u].sz1 += size;
  t[u].sz2 += ((long long)size) * ((long long)size);
  renew(u);
  fa[v] = u;
  t[v].fa = u;
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    E[x].push_back(i);
    fa[i] = x;
  }
  for (int i = 1; i <= n; ++i) scanf("%d", &s[i]);
  dfs(1, 0);
  printf("%.10lf\n", (double)ans / n / n);
  scanf("%d", &Q);
  for (int i = 1; i <= Q; ++i) {
    char type[12];
    int x, y;
    scanf("%s%d%d", type, &x, &y);
    if (type[0] == 'P') {
      move(x, y);
    } else {
      access(x);
      splay(x);
      ans +=
          (y - s[x]) * (((long long)t[x].sz) * ((long long)t[x].sz) - t[x].sz2);
      s[x] = y;
      renew(x);
    }
    printf("%.10lf\n", (double)ans / n / n);
  }
}