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;
const int Maxn = 50010;
vector<int> G[Maxn];
int n;
struct Node* null;
struct Node {
  Node *ch[2], *p;
  int sz, del, val, lz;
  long long ps, sum;
  void push_up() {
    if (this == null) return;
    sum = ch[0]->sum + ch[1]->sum + del * (long long)val;
  }
  void add(int w) {
    if (this == null) return;
    sz += w;
    lz += w;
    ps += del * (long long)w * 2;
  }
  void push_down() {
    if (this == null) return;
    if (lz) {
      ch[0]->add(lz);
      ch[1]->add(lz);
      lz = 0;
    }
  }
  inline void setc(Node* u, int d) {
    ch[d] = u;
    u->p = this;
  }
} nd[Maxn];
inline bool isrt(Node* u) {
  return u == null || u->p == null || (u->p->ch[0] != u && u->p->ch[1] != u);
}
void rotate(Node* u, int d) {
  Node* fa = u->p;
  if (!isrt(fa))
    fa->p->setc(u, fa->p->ch[0] != fa);
  else
    u->p = fa->p;
  fa->setc(u->ch[d], d ^ 1);
  u->setc(fa, d);
  fa->push_up();
}
void splay(Node* u) {
  static Node* sta[Maxn];
  int top = 0;
  Node* y = u;
  for (; !isrt(y); y = y->p) sta[top++] = y;
  if (y != null) sta[top++] = y;
  while (top) sta[--top]->push_down();
  while (!isrt(u)) {
    Node* fa = u->p;
    int d = fa->ch[0] != u;
    if (isrt(fa))
      rotate(u, d ^ 1);
    else {
      Node* gra = fa->p;
      int d2 = gra->ch[0] != fa;
      if (d == d2)
        rotate(fa, d ^ 1);
      else
        rotate(u, d ^ 1);
      rotate(u, d2 ^ 1);
    }
  }
  u->push_up();
}
Node* access(Node* u) {
  Node* v = null;
  for (; u != null; v = u, u = u->p) {
    if (v != null) {
      while (v->ch[0] != null) v = v->ch[0];
      splay(v);
    }
    splay(u);
    u->setc(v, 1);
    u->del = u->sz - v->sz;
    u->push_up();
  }
  return v;
}
long long ans;
void dfs(int u) {
  nd[u].sz = 1;
  nd[u].ps = 0;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    dfs(v);
    nd[u].ps += nd[v].sz * (long long)nd[v].sz;
    nd[u].sz += nd[v].sz;
  }
  nd[u].ps = nd[u].sz * (long long)nd[u].sz - nd[u].ps;
  nd[u].del = nd[u].sz;
  ans += nd[u].ps * nd[u].val;
}
void move(int x, int y) {
  access(nd + y);
  splay(nd + x);
  Node* pa = nd + x;
  for (; pa->ch[0] != null; pa = pa->ch[0])
    ;
  if (pa == nd + 1) swap(x, y);
  Node *u = nd + x, *v = nd + y;
  access(u);
  splay(u);
  pa = u->ch[0];
  ans -= pa->sum * u->sz * 2;
  pa->add(-u->sz);
  u->ch[0] = pa->p = null;
  u->push_up();
  access(v);
  splay(v);
  ans += v->sum * u->sz * 2;
  v->add(u->sz);
  u->p = v;
}
int main() {
  scanf("%d", &n);
  null = new Node();
  null->ch[0] = null->ch[1] = null->p = null;
  null->sz = null->lz = null->del = null->ps = null->sum = null->val = 0;
  (nd + 1)->p = null;
  (nd + 1)->ch[0] = (nd + 1)->ch[1] = null;
  for (int i = 2; i <= n; i++) {
    int u;
    scanf("%d", &u);
    G[u].push_back(i);
    (nd + i)->p = nd + u;
    (nd + i)->ch[0] = (nd + i)->ch[1] = null;
  }
  for (int i = 1; i <= n; i++) scanf("%d", &nd[i].val);
  dfs(1);
  printf("%.12f\n", (ans + 0.0) / n / n);
  int q;
  scanf("%d", &q);
  while (q--) {
    char s[2];
    int x, y;
    scanf("%s%d%d", s, &x, &y);
    if (s[0] == 'P')
      move(x, y);
    else {
      access(nd + x);
      ans += (y - nd[x].val) * nd[x].ps;
      nd[x].val = y;
      nd[x].push_up();
    }
    printf("%.12f\n", (ans + 0.0) / n / n);
  }
}
