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;
long long cnt[201000], cntS[201000], tot[201000], add[201000], pairs[201000],
    rlt;
int son[201000][2], pa[201000], val[201000];
int to[201000], nxt[201000], head[201000], E;
void add_edge(int u, int v) {
  to[E] = v;
  nxt[E] = head[u];
  head[u] = E++;
  return;
}
void inti_LCT(int N) {
  for (int i = 0; i <= N; i++) {
    pa[i] = 0;
    son[i][0] = son[i][1] = 0;
    cnt[i] = cntS[i] = 0;
    tot[i] = add[i] = pairs[i] = 0;
  }
  return;
}
void Push_up(int x) {
  cntS[x] = cntS[son[x][0]] + cnt[x] + cntS[son[x][1]];
  tot[x] = tot[son[x][0]] + cnt[x] * val[x] + tot[son[x][1]];
  return;
}
void add_delta(int x, long long v) {
  if (x) {
    add[x] += v;
    pairs[x] += cnt[x] * v;
  }
  return;
}
void Push_down(int x) {
  if (add[x]) {
    add_delta(son[x][0], add[x]);
    add_delta(son[x][1], add[x]);
    add[x] = 0;
  }
}
bool isroot(int x) { return son[pa[x]][0] != x && son[pa[x]][1] != x; }
void down(int x) {
  if (!isroot(x)) down(pa[x]);
  Push_down(x);
  return;
}
void rot(int x, int d) {
  int y = pa[x], z = pa[y];
  son[y][!d] = son[x][d];
  pa[son[x][d]] = y;
  pa[x] = pa[y];
  if (son[z][0] == y)
    son[z][0] = x;
  else if (son[z][1] == y)
    son[z][1] = x;
  pa[y] = x;
  son[x][d] = y;
  Push_up(y);
  return;
}
void splay(int x) {
  down(x);
  while (!isroot(x)) {
    if (isroot(pa[x]))
      rot(x, son[pa[x]][0] == x);
    else {
      int y = pa[x], z = pa[y];
      int d = (son[z][0] == y);
      son[y][d] == x ? rot(x, !d) : rot(y, d);
      rot(x, d);
    }
  }
  Push_up(x);
  return;
}
void access(int x) {
  for (int y = 0; x; x = pa[x]) {
    splay(x);
    int z = son[x][1];
    cnt[x] += cntS[z];
    cnt[x] -= cntS[y];
    son[x][1] = y;
    Push_up(y = x);
  }
  return;
}
int getPa(int y) {
  splay(y);
  if (!son[y][0]) return pa[y];
  for (y = son[y][0]; son[y][1]; y = son[y][1])
    ;
  return y;
}
void calc1(int x, int y) {
  access(y);
  splay(x);
  if (!pa[x]) swap(x, y);
  int p = getPa(x);
  if (y == p) return;
  access(p);
  splay(p);
  cnt[p] -= cntS[x];
  Push_up(p);
  rlt -= 2 * tot[p] * cntS[x];
  add_delta(p, -2 * cntS[x]);
  access(y);
  splay(y);
  rlt += 2 * tot[y] * cntS[x];
  add_delta(y, 2 * cntS[x]);
  cnt[y] += cntS[x];
  Push_up(y);
  pa[x] = y;
  return;
}
void calc2(int x, int y) {
  splay(x);
  rlt += (y - val[x]) * pairs[x];
  val[x] = y;
  Push_up(x);
  return;
}
void dfs(int u) {
  int v;
  cnt[u] = pairs[u] = 1;
  for (int ID = head[u]; ID != -1; ID = nxt[ID]) {
    v = to[ID];
    dfs(v);
    pairs[u] += 2 * cnt[u] * cnt[v];
    cnt[u] += cnt[v];
  }
  rlt += pairs[u] * val[u];
  Push_up(u);
  return;
}
int main() {
  int N, T, tp, u, v;
  char str[11];
  scanf("%d", &N);
  memset(head, 0xff, sizeof(head));
  E = 0;
  for (int i = 2; i <= N; i++) {
    scanf("%d", pa + i);
    add_edge(pa[i], i);
  }
  for (int i = 1; i <= N; i++) scanf("%d", val + i);
  rlt = 0;
  dfs(1);
  printf("%.10lf\n", 1.0 * rlt / N / N);
  for (scanf("%d", &T); T--;) {
    scanf("%s%d%d", str, &u, &v);
    if (str[0] == 'P')
      calc1(u, v);
    else
      calc2(u, v);
    printf("%.10lf\n", 1.0 * rlt / N / N);
  }
  return 0;
}