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 long long MAXN = 100010;
long long read() {
  long long kkk = 0, x = 1;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') c = getchar(), x = -1;
  while (c >= '0' && c <= '9') kkk = kkk * 10 + (c - '0'), c = getchar();
  return kkk * x;
}
long long n, q, pre[MAXN];
struct LCT {
  long long son[2], fa, value;
  long long size, xsize;
  long long ans, xans;
  long long ctb, del;
} tree[MAXN];
long long noroot(long long x) {
  return (tree[tree[x].fa].son[0]) == x || (tree[tree[x].fa].son[1]) == x;
}
void up(long long x) {
  tree[x].size =
      tree[(tree[x].son[0])].size + tree[(tree[x].son[1])].size + tree[x].xsize;
  tree[x].ctb = tree[(tree[x].son[0])].ctb + tree[(tree[x].son[1])].ctb +
                tree[x].xsize * tree[x].value;
  tree[x].ans =
      tree[(tree[x].son[0])].ans + tree[(tree[x].son[1])].ans + tree[x].xans +
      tree[x].value * (tree[x].xsize * tree[x].xsize - tree[x].del) +
      2 * tree[x].value * tree[x].xsize * tree[(tree[x].son[1])].size +
      2 * tree[(tree[x].son[0])].ctb *
          (tree[x].size - tree[(tree[x].son[0])].size);
}
void rotate(long long x) {
  long long y = tree[x].fa, z = tree[y].fa;
  long long K = ((tree[y].son[1]) == x);
  if (noroot(y)) tree[z].son[(tree[z].son[1]) == y] = x;
  tree[tree[x].son[K ^ 1]].fa = y;
  tree[y].son[K] = tree[x].son[K ^ 1];
  tree[x].son[K ^ 1] = y;
  tree[y].fa = x;
  tree[x].fa = z;
  up(y);
}
void splay(long long x) {
  while (noroot(x)) {
    long long y = tree[x].fa, z = tree[y].fa;
    if (noroot(y))
      ((tree[y].son[1]) == x) ^ ((tree[z].son[1]) == y) ? rotate(x) : rotate(y);
    rotate(x);
  }
  up(x);
}
void access(long long x) {
  for (long long last = 0; x != 0; last = x, x = tree[x].fa) {
    splay(x);
    tree[x].xsize += tree[(tree[x].son[1])].size;
    tree[x].xans += tree[(tree[x].son[1])].ans;
    tree[x].del += tree[(tree[x].son[1])].size * tree[(tree[x].son[1])].size;
    tree[x].son[1] = last;
    tree[x].xsize -= tree[(tree[x].son[1])].size;
    tree[x].xans -= tree[(tree[x].son[1])].ans;
    tree[x].del -= tree[(tree[x].son[1])].size * tree[(tree[x].son[1])].size;
    up(x);
  }
}
void link(long long x, long long y) {
  access(y), splay(y);
  access(x), splay(x);
  tree[y].fa = x;
  tree[x].xsize += tree[y].size;
  tree[x].xans += tree[y].ans;
  tree[x].del += tree[y].size * tree[y].size;
  up(x);
}
void cut(long long x, long long y) {
  access(x);
  splay(x);
  splay(y);
  tree[x].xsize -= tree[y].size;
  tree[x].xans -= tree[y].ans;
  tree[x].del -= tree[y].size * tree[y].size;
  tree[y].fa = 0;
  up(x);
}
long long check(long long x, long long y) {
  access(y);
  splay(y);
  splay(x);
  return noroot(y);
}
signed main() {
  n = read();
  for (long long i = 2; i <= n; ++i) pre[i] = read();
  for (long long i = 1; i <= n; ++i) {
    tree[i].ans = tree[i].ctb = tree[i].value = read();
    tree[i].size = tree[i].xsize = 1;
  }
  for (long long i = 2; i <= n; ++i) link(pre[i], i);
  access(1);
  splay(1);
  printf("%.10lf\n", (double)tree[1].ans / n / n);
  q = read();
  while (q--) {
    char type[10];
    scanf("%s", type);
    long long x = read(), y = read();
    if (type[0] == 'P') {
      if (check(x, y)) swap(x, y);
      cut(pre[x], x);
      pre[x] = y;
      link(pre[x], x);
    } else {
      access(x);
      splay(x);
      tree[x].value = y;
      up(x);
    }
    access(1);
    splay(1);
    printf("%.10lf\n", (double)tree[1].ans / n / n);
  }
  return 0;
}