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 int N = 100100;
int c[2][N], *lc = c[0], *rc = c[1], fa[N];
long long sm0[N], sm1[N], sm2[N], val[N], dval[N], a[N], dsm2[N];
bool it(int o) { return c[0][fa[o]] != o && c[1][fa[o]] != o; }
void ps(int o) {
  sm0[o] = sm0[lc[o]] + sm0[rc[o]] + val[o];
  sm1[o] = sm1[lc[o]] + sm1[rc[o]] + a[o] * val[o];
  sm2[o] = sm2[lc[o]] + sm2[rc[o]] + dsm2[o] +
           a[o] * (val[o] * (val[o] + 2 * sm0[rc[o]]) - dval[o]) +
           2 * sm1[lc[o]] * (sm0[rc[o]] + val[o]);
}
void rot(int o) {
  int x = fa[o], k = c[0][x] == o;
  fa[c[!k][x] = c[k][o]] = x;
  fa[o] = fa[x];
  if (!it(x)) c[c[1][fa[x]] == x][fa[x]] = o;
  fa[c[k][o] = x] = o;
  ps(x);
}
void sy(int o) {
  for (; !it(o); rot(o))
    if (!it(fa[o]))
      rot(c[0][fa[o]] == o ^ c[0][fa[fa[o]]] == fa[o] ? o : fa[o]);
  ps(o);
}
void upd(int o, int t) {
  dsm2[fa[o]] += t * sm2[o];
  dval[fa[o]] += t * sm0[o] * sm0[o];
  val[fa[o]] += t * sm0[o];
}
void acs(int o) {
  for (int y = 0; o; upd(rc[o], 1), upd(y, -1), rc[o] = y, ps(y = o), o = fa[o])
    sy(o);
}
void set_fa(int x, int y) {
  acs(x);
  sy(x);
  acs(y);
  sy(y);
  fa[x] = y;
  upd(x, 1);
  ps(y);
}
void cut_fa(int x) {
  acs(x);
  sy(x);
  fa[lc[x]] = 0;
  lc[x] = 0;
  ps(x);
}
bool is_anc(int x, int y) {
  acs(y);
  sy(y);
  sy(x);
  return !it(y);
}
int n;
void output() {
  acs(1);
  sy(1);
  cout << (double)sm2[1] / ((long long)n * n) << '\n';
}
int m, fat[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(10);
  cin >> n;
  for (int i = 2; i <= n; ++i) cin >> fat[i];
  for (int i = 1; i <= n; ++i)
    cin >> a[i], sm0[i] = val[i] = 1, sm2[i] = sm1[i] = a[i];
  for (int i = 2; i <= n; ++i) set_fa(i, fat[i]);
  output();
  for (cin >> m; m-- > 0; output()) {
    char c;
    int x, y;
    cin >> c >> x >> y;
    if (c == 'V')
      acs(x), sy(x), a[x] = y, ps(x);
    else if (is_anc(x, y))
      cut_fa(y), set_fa(y, x);
    else
      cut_fa(x), set_fa(x, y);
  }
  return 0;
}