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 MAXN = 100005;
const int MAXE = 200005;
long long ans;
struct Node* null;
struct Node {
  Node* c[2];
  Node* f;
  long long sum;
  long long val;
  long long cnt;
  long long addv;
  long long size;
  long long tot_size;
  inline void newnode(long long value) {
    val = value;
    sum = 0;
    c[0] = c[1] = f = null;
  }
  inline void add_size(long long v) {
    if (this == null) return;
    addv += v;
    cnt += 2 * size * v;
    tot_size += v;
  }
  inline void push_up() { sum = c[0]->sum + size * val + c[1]->sum; }
  inline void push_down() {
    if (addv) {
      c[0]->add_size(addv);
      c[1]->add_size(addv);
      addv = 0;
    }
  }
  inline bool isroot() {
    return f == null || f->c[0] != this && f->c[1] != this;
  }
  inline void setc(Node* o, int d) {
    c[d] = o;
    o->f = this;
  }
  inline void rotate(int d) {
    Node* p = f;
    Node* g = p->f;
    p->setc(c[d], !d);
    if (!p->isroot())
      g->setc(this, p == g->c[1]);
    else
      f = g;
    setc(p, d);
    p->push_up();
  }
  inline void sign_down() {
    if (!isroot()) f->sign_down();
    push_down();
  }
  inline void splay() {
    sign_down();
    while (!isroot()) {
      if (f->isroot())
        rotate(this == f->c[0]);
      else {
        if (f == f->f->c[0]) {
          if (this == f->c[0])
            f->rotate(1);
          else
            rotate(0);
          rotate(1);
        } else {
          if (this == f->c[1])
            f->rotate(0);
          else
            rotate(1);
          rotate(0);
        }
      }
    }
    push_up();
  }
  inline void access() {
    Node* o = this;
    Node* x = null;
    while (o != null) {
      if (x != null) {
        while (x->c[0] != null) x = x->c[0];
        x->splay();
      }
      o->splay();
      o->size = o->tot_size - x->tot_size;
      o->setc(x, 1);
      o->push_up();
      x = o;
      o = o->f;
    }
    splay();
  }
};
struct Edge {
  int v, n;
  Edge() {}
  Edge(int v, int n) : v(v), n(n) {}
};
Edge E[MAXE];
int H[MAXN], cntE;
Node pool[MAXN];
Node* node[MAXN];
Node* cur;
long long val[MAXN];
int n, m;
void clear() {
  ans = 0;
  cntE = 0;
  memset(H, -1, sizeof H);
  cur = pool;
  null = cur++;
  null->newnode(0);
  null->size = null->tot_size = 0;
}
void addedge(int u, int v) {
  E[cntE] = Edge(v, H[u]);
  H[u] = cntE++;
}
void dfs(int u) {
  node[u]->cnt = node[u]->size = 1;
  for (int i = H[u]; ~i; i = E[i].n) {
    int v = E[i].v;
    dfs(v);
    node[u]->cnt += node[v]->size * node[u]->size * 2;
    node[u]->size += node[v]->size;
  }
  node[u]->tot_size = node[u]->size;
  ans += node[u]->cnt * node[u]->val;
  node[u]->push_up();
}
void solve() {
  char op[5];
  int x, y;
  double all = (double)n * n;
  clear();
  for (int i = (1); i <= (n); ++i) {
    node[i] = cur++;
    node[i]->newnode(0);
  }
  for (int i = (2); i <= (n); ++i) {
    scanf("%d", &x);
    addedge(x, i);
    node[i]->f = node[x];
  }
  for (int i = (1); i <= (n); ++i) scanf("%I64d", &node[i]->val);
  dfs(1);
  printf("%.10f\n", ans / all);
  scanf("%d", &m);
  for (int i = (0); i < (m); ++i) {
    scanf("%s%d%d", op, &x, &y);
    if (op[0] == 'P') {
      node[y]->access();
      node[x]->splay();
      if (node[x]->f == null) swap(x, y);
      node[x]->access();
      Node* o = node[x]->c[0];
      ans -= o->sum * node[x]->tot_size * 2;
      o->add_size(-node[x]->tot_size);
      node[x]->c[0]->f = null;
      node[x]->c[0] = null;
      o->push_up();
      node[y]->access();
      ans += node[y]->sum * node[x]->tot_size * 2;
      node[y]->add_size(node[x]->tot_size);
      node[y]->push_up();
      node[x]->f = node[y];
    } else {
      node[x]->access();
      ans += node[x]->cnt * (y - node[x]->val);
      node[x]->val = y;
      node[x]->push_up();
    }
    printf("%.10f\n", ans / all);
  }
}
int main() {
  while (~scanf("%d", &n)) solve();
  return 0;
}