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.
#include <bits/stdc++.h>
using namespace std;
typedef struct Tree {
  int n;
  int* par;
  int* fst;
  int* lst;
  int* nxt;
  int* prv;
  int* val;
  int* sz;
  long long* cnt;
  int* others;
  long long* outside;
  Tree(int n) : n(n) {
    par = new int[n];
    for (int i = (0); i < (n); ++i) par[i] = -1;
    val = new int[n];
    sz = new int[n];
    outside = new long long[n];
    cnt = new long long[n];
    others = new int[n];
    fst = new int[n];
    for (int i = (0); i < (n); ++i) fst[i] = -1;
    lst = new int[n];
    for (int i = (0); i < (n); ++i) lst[i] = -1;
    nxt = new int[n];
    for (int i = (0); i < (n); ++i) nxt[i] = -1;
    prv = new int[n];
    for (int i = (0); i < (n); ++i) fst[i] = -1;
  }
  void setPar(int v, int p) {
    assert(par[v] == -1);
    par[v] = p;
    nxt[v] = -1;
    prv[v] = lst[p];
    lst[p] = v;
    if (prv[v] != -1)
      nxt[prv[v]] = v;
    else
      fst[p] = v;
  }
  void clearPar(int v) {
    assert(par[v] != -1);
    int p = par[v];
    par[v] = -1;
    if (nxt[v] != -1)
      prv[nxt[v]] = prv[v];
    else
      lst[p] = prv[v];
    if (prv[v] != -1)
      nxt[prv[v]] = nxt[v];
    else
      fst[p] = nxt[v];
    prv[v] = nxt[v] = -1;
  }
  bool isdesc(int v, int p) {
    while (v != -1 && v != p) v = par[v];
    return v == p;
  }
} Tree;
Tree *full, *small;
long long total;
void dfscalcsz(int at, int p) {
  full->sz[at] = 1;
  for (int to = full->fst[at]; to != -1; to = full->nxt[to]) {
    dfscalcsz(to, at);
    full->sz[at] += full->sz[to];
  }
}
void dfscalcoutside(int at, int p) {
  full->cnt[at] = (long long)full->sz[at] * full->sz[at];
  full->others[at] = p == -1 ? 0 : full->sz[p] - full->sz[at];
  full->outside[at] = p == -1
                          ? 0
                          : full->outside[p] + (long long)full->val[p] *
                                                   (full->sz[p] - full->sz[at]);
  for (int to = full->fst[at]; to != -1; to = full->nxt[to]) {
    dfscalcoutside(to, at);
    full->cnt[at] -= (long long)full->sz[to] * full->sz[to];
  }
}
bool insmall[50000];
int smallid[50000];
bool dfsinsmall(int at) {
  int ret = 0;
  for (int to = full->fst[at]; to != -1; to = full->nxt[to])
    ret += dfsinsmall(to) ? 1 : 0;
  if (ret >= 2) insmall[at] = true;
  return insmall[at] || ret >= 1;
}
void dfsinitsmall(int at, int p, int others, int& N) {
  if (insmall[at]) {
    int id = smallid[at] = N++;
    if (p != -1) small->setPar(id, p);
    small->val[id] = full->val[at];
    small->sz[id] = full->sz[at];
    small->cnt[id] = full->cnt[at];
    small->others[id] = others;
    small->outside[id] = full->outside[at];
    for (int to = full->fst[at]; to != -1; to = full->nxt[to])
      dfsinitsmall(to, id, full->sz[at] - full->sz[to], N);
  } else {
    for (int to = full->fst[at]; to != -1; to = full->nxt[to])
      dfsinitsmall(to, p, others, N);
  }
}
void updatesmalltree(int at, long long delta) {
  small->outside[at] += delta;
  for (int to = small->fst[at]; to != -1; to = small->nxt[to])
    updatesmalltree(to, delta);
}
void updatesmallpath(int at, int from, int delta) {
  while (at != -1) {
    small->sz[at] += delta;
    small->cnt[at] += (long long)2 * delta * small->others[from];
    for (int to = small->fst[at]; to != -1; to = small->nxt[to])
      if (to != from) {
        small->others[to] += delta;
        updatesmalltree(to, (long long)delta * small->val[at]);
      }
    from = at;
    at = small->par[at];
  }
}
int nq;
char qtype[50000];
int qa[50000], qb[50000];
void run() {
  int n;
  scanf("%d", &n);
  full = new Tree(n);
  for (int i = (1); i < (n); ++i) {
    int p;
    scanf("%d", &p);
    --p;
    full->setPar(i, p);
  }
  for (int i = (0); i < (n); ++i) scanf("%d", &full->val[i]);
  scanf("%d", &nq);
  for (int i = (0); i < (nq); ++i) {
    scanf(" %c%d%d", &qtype[i], &qa[i], &qb[i]);
    if (qtype[i] == 'P') --qa[i], --qb[i];
    if (qtype[i] == 'V') --qa[i];
  }
  for (int a = 0, b = min(nq, a + 100); a < b; a = b, b = min(nq, a + 100)) {
    dfscalcsz(0, -1);
    dfscalcoutside(0, -1);
    total = 0;
    for (int i = (0); i < (full->n); ++i)
      total += full->outside[i] + (long long)full->val[i] * full->sz[i];
    if (a == 0) printf("%.9lf\n", 1.0 * total / full->n / full->n);
    memset(insmall, false, sizeof(insmall));
    for (int i = (a); i < (b); ++i) {
      if (qtype[i] == 'P') insmall[qa[i]] = insmall[qb[i]] = true;
      if (qtype[i] == 'V') insmall[qa[i]] = true;
    }
    dfsinsmall(0);
    int N = 0;
    for (int i = (0); i < (full->n); ++i)
      if (insmall[i]) ++N;
    small = new Tree(N);
    memset(smallid, -1, sizeof(smallid));
    N = 0;
    dfsinitsmall(0, -1, 0, N);
    for (int i = (a); i < (b); ++i) {
      if (qtype[i] == 'P') {
        int v = qa[i], u = qb[i];
        if (small->isdesc(smallid[u], smallid[v])) swap(u, v);
        full->clearPar(v);
        full->setPar(v, u);
        v = smallid[v];
        u = smallid[u];
        total -= (long long)2 * small->sz[v] * small->outside[v];
        updatesmallpath(small->par[v], v, -small->sz[v]);
        small->clearPar(v);
        small->setPar(v, u);
        small->others[v] = small->sz[u];
        updatesmallpath(small->par[v], v, +small->sz[v]);
        updatesmalltree(
            v, small->outside[u] +
                   (long long)small->val[u] * (small->sz[u] - small->sz[v]) -
                   small->outside[v]);
        total += (long long)2 * small->sz[v] * small->outside[v];
      }
      if (qtype[i] == 'V') {
        int v = qa[i], t = qb[i];
        full->val[v] = t;
        v = smallid[v];
        total += (long long)(t - small->val[v]) * small->cnt[v];
        for (int to = small->fst[v]; to != -1; to = small->nxt[to])
          updatesmalltree(to,
                          (long long)(t - small->val[v]) * small->others[to]);
        small->val[v] = t;
      }
      printf("%.9lf\n", 1.0 * total / full->n / full->n);
    }
  }
}
int main() {
  run();
  return 0;
}
