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 DIM = 50000;
int par[DIM], val[DIM], szt[DIM], npr[DIM], len[DIM];
char typ[DIM];
long long ptc[DIM], cnt[DIM];
bitset<DIM> oki;
set<int> mst, axs;
pair<int, int> qry[DIM];
vector<int> edg[DIM];
void dfs(int x, long long &ans) {
  szt[x] = cnt[x] = 1;
  for (int y : edg[x]) {
    dfs(y, ans);
    cnt[x] += 2LL * szt[x] * szt[y];
    szt[x] += szt[y];
  }
  ans += cnt[x] * val[x];
  return;
}
long long rebuild(int n, int l, int r) {
  fill(edg, edg + n, vector<int>());
  fill(ptc, ptc + n, 0);
  fill(len, len + n, 0);
  long long ans = 0;
  for (int i = 1; i < n; ++i) edg[par[i]].push_back(i);
  dfs(0, ans);
  mst.clear();
  axs.clear();
  for (int i = l; i < r; ++i) {
    oki[qry[i].first] = true;
    axs.insert(qry[i].first);
    if (typ[i] == 'P') {
      oki[qry[i].second] = true;
      axs.insert(qry[i].second);
    }
  }
  for (int x : axs) {
    mst.insert(x);
    for (int y = x, f = par[y]; y != -1; y = f, f = par[f]) {
      oki[y] = true;
      if (f != -1 and oki[f]) {
        mst.insert(f);
        break;
      }
    }
  }
  oki.reset();
  for (int x : mst) oki[x] = true;
  for (int x : mst) {
    if (par[x] != -1 and oki[par[x]]) npr[x] = par[x];
    for (int y = x, f = par[y]; f != -1 and !oki[f]; y = f, f = par[f]) {
      ptc[x] += 1LL * val[f] * (szt[f] - szt[y]);
      if (par[f] != -1 and oki[par[f]])
        npr[x] = par[f], len[x] = szt[f] - szt[x];
    }
  }
  oki.reset();
  return ans;
}
int main(void) {
  ios ::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  int n;
  cin >> n;
  for (int i = 1; i < n; ++i) cin >> par[i], --par[i];
  for (int i = 0; i < n; ++i) cin >> val[i];
  int q;
  cin >> q;
  int l = (int)sqrt(q);
  par[0] = npr[0] = -1;
  for (int i = 0; i < q; ++i) {
    cin >> typ[i] >> qry[i].first >> qry[i].second;
    --qry[i].first;
    if (typ[i] == 'P') --qry[i].second;
  }
  long long ans = 0;
  for (int _q = 0; _q < q; ++_q) {
    int x, y, z = -1;
    tie(x, y) = qry[_q];
    if (_q % l == 0) ans = rebuild(n, _q, min(q, _q + l));
    if (_q == 0) cout << setprecision(10) << fixed << 1.0 * ans / n / n << "\n";
    if (typ[_q] == 'P') {
      for (int _x = x; _x != -1; _x = npr[_x]) oki[_x] = true;
      for (int _y = y; _y != -1; _y = npr[_y]) {
        if (z == -1 and oki[_y]) z = _y;
        oki[_y] = true;
      }
      if (z == x) swap(y, x);
      for (int _x = x, f = npr[x]; f != -1; _x = f, f = npr[f]) {
        ans -= 2LL * szt[x] *
               (ptc[f] + 1LL * val[f] * (szt[f] - szt[_x] - len[_x]));
        cnt[f] -= 2LL * szt[x] * (szt[f] - szt[_x] - len[_x]);
      }
      for (int _x = x; _x != -1; _x = npr[_x])
        oki[_x] = false, szt[_x] -= szt[x] * (_x != x);
      for (int _y = x, f = y; f != -1; _y = f, f = npr[f]) {
        ans += 2LL * szt[x] *
               (ptc[f] +
                1LL * val[f] * (szt[f] - (_y == x ? 0 : (szt[_y] + len[_y]))));
        cnt[f] += 2LL * szt[x] * (szt[f] - (_y == x ? 0 : (szt[_y] + len[_y])));
      }
      for (int _y = y; _y != -1; _y = npr[_y])
        oki[_y] = false, szt[_y] += szt[x];
      ans -= 2LL * szt[x] * ptc[x];
      ptc[x] = len[x] = 0;
      par[x] = npr[x] = y;
    } else {
      ans += cnt[x] * (y - val[x]);
      val[x] = y;
    }
    cout << setprecision(10) << fixed << 1.0 * ans / n / n << "\n";
  }
  return 0;
}