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;
bool debug = 1;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
long long ln, lk, lm;
struct SplayNode {
  long long sz01, sz11, sz02, sum, ans0, ans;
  void init(long long x) {
    sz11 = 1;
    sz01 = 1;
    ans = x;
    sum = x;
  }
} sn[100105];
const int N = 100105;
int ch[N][2];
int f[N], a[100105];
void PushUp(int p) {
  sn[p].sz11 = sn[ch[p][0]].sz11 + sn[ch[p][1]].sz11 + sn[p].sz01;
  sn[p].sum = sn[ch[p][0]].sum + sn[ch[p][1]].sum + sn[p].sz01 * a[p];
  sn[p].ans = sn[ch[p][0]].ans + sn[ch[p][1]].ans + sn[p].ans0;
  sn[p].ans += (sn[p].sz01 * sn[p].sz01 - sn[p].sz02) * a[p];
  sn[p].ans += sn[p].sz01 * sn[ch[p][1]].sz11 * a[p] * 2;
  sn[p].ans += sn[ch[p][0]].sum * (sn[p].sz11 - sn[ch[p][0]].sz11) * 2;
}
void Rotate(int x) {
  int y = f[x], z = f[y], k = (ch[f[x]][1] == x);
  if (!(ch[f[y]][0] != y && ch[f[y]][1] != y)) ch[z][ch[z][1] == y] = x;
  ch[y][k] = ch[x][!k];
  f[ch[y][k]] = y;
  ch[x][!k] = y;
  f[y] = x;
  f[x] = z;
  PushUp(y);
  PushUp(x);
}
void Splay(int x) {
  for (int fa; (fa = f[x]) != 0 && !(ch[f[x]][0] != x && ch[f[x]][1] != x);
       Rotate(x)) {
    if (!(ch[f[fa]][0] != fa && ch[f[fa]][1] != fa))
      Rotate((ch[f[fa]][1] == fa) == (ch[f[x]][1] == x) ? fa : x);
  }
  PushUp(x);
}
int Access(int x) {
  int p;
  for (p = 0; x; p = x, x = f[x]) {
    Splay(x);
    int R = ch[x][1];
    sn[x].sz01 += sn[R].sz11;
    sn[x].sz02 += sn[R].sz11 * sn[R].sz11;
    sn[x].ans0 += sn[R].ans;
    ch[x][1] = p;
    R = p;
    sn[x].sz01 -= sn[R].sz11;
    sn[x].sz02 -= sn[R].sz11 * sn[R].sz11;
    sn[x].ans0 -= sn[R].ans;
    PushUp(x);
  }
  return p;
}
void link(int u, int v) {
  Access(v);
  Splay(v);
  Access(u);
  Splay(u);
  sn[u].sz01 += sn[v].sz11;
  sn[u].sz02 += sn[v].sz11 * sn[v].sz11;
  sn[u].ans0 += sn[v].ans;
  f[v] = u;
  PushUp(u);
}
void cut(int u, int v) {
  Access(u);
  Splay(u);
  Splay(v);
  sn[u].sz01 -= sn[v].sz11;
  sn[u].sz02 -= sn[v].sz11 * sn[v].sz11;
  sn[u].ans0 -= sn[v].ans;
  f[v] = 0;
  PushUp(u);
}
bool isAncestor(int u, int v) {
  Access(v);
  Splay(v);
  Splay(u);
  if (!(ch[f[v]][0] != v && ch[f[v]][1] != v)) return true;
  return false;
}
void pp(long long x) {
  double tmp = (double)x / n / n;
  printf("%.12lf\n", tmp);
}
char ope[3];
int par[100105];
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    scanf("%d", par + i);
  }
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    scanf("%d", a + i);
    sn[i].init(a[i]);
  }
  for (int i = 2; i <= n; i++) {
    link(par[i], i);
  }
  Access(1);
  Splay(1);
  pp(sn[1].ans);
  scanf("%d", &m);
  for (int(i) = 1; (i) <= (int)(m); (i)++) {
    scanf("%s", ope);
    if (ope[0] == 'P') {
      int x, y;
      scanf("%d%d", &x, &y);
      if (isAncestor(x, y)) swap(x, y);
      cut(par[x], x);
      par[x] = y;
      link(y, x);
      Access(1);
      Splay(1);
      pp(sn[1].ans);
    } else {
      int v, t;
      scanf("%d%d", &v, &t);
      Access(v);
      Splay(v);
      a[v] = t;
      PushUp(v);
      pp(sn[v].ans);
    }
  }
  return 0;
}