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 = 50005;
const int MAXE = 100005;
struct Node* null;
struct Node {
  Node* c[2];
  Node* f;
  long long cnt;
  long long sum;
  int val;
  int siz;
  int lazy;
  int tree_siz;
  inline void new_node() {
    sum = val = 0;
    c[0] = c[1] = f = null;
    lazy = 0;
  }
  inline void add_siz(int SIZE) {
    if (this == null) return;
    tree_siz += SIZE;
    cnt += 2LL * siz * SIZE;
    lazy += SIZE;
  }
  inline void push_up() { sum = c[0]->sum + (long long)siz * val + c[1]->sum; }
  inline void push_down() {
    if (lazy) {
      c[0]->add_siz(lazy);
      c[1]->add_siz(lazy);
      lazy = 0;
    }
  }
  inline bool is_root() {
    return f == null || f->c[0] != this && f->c[1] != this;
  }
  inline void sign_down() {
    if (!is_root()) f->sign_down();
    push_down();
  }
  inline void setc(Node* o, bool d) {
    c[d] = o;
    o->f = this;
  }
  inline void rot(bool d) {
    Node* p = f;
    Node* g = f->f;
    p->setc(c[d], !d);
    if (!p->is_root())
      g->setc(this, p == g->c[1]);
    else
      f = g;
    setc(p, d);
    p->push_up();
  }
  inline void splay() {
    sign_down();
    while (!is_root()) {
      if (f->is_root())
        rot(this == f->c[0]);
      else {
        if (f == f->f->c[0]) {
          if (this == f->c[0])
            f->rot(1), rot(1);
          else
            rot(0), rot(1);
        } else {
          if (this == f->c[1])
            f->rot(0), rot(0);
          else
            rot(1), rot(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->siz = o->tree_siz - x->tree_siz;
      o->setc(x, 1);
      o->push_up();
      x = o;
      o = o->f;
    }
    splay();
  }
};
struct Edge {
  int v;
  Edge* next;
};
Node pool[MAXN];
Node* node[MAXN];
Node* curN;
Edge edge[MAXE];
Edge* H[MAXN];
Edge* curE;
long long ans;
int n, m;
void clear() {
  ans = 0;
  curE = edge;
  curN = pool;
  null = curN++;
  null->new_node();
  null->cnt = null->tree_siz = null->siz = 0;
  memset(H, 0, sizeof H);
}
void addedge(int u, int v) {
  curE->v = v;
  curE->next = H[u];
  H[u] = curE++;
}
void dfs(int u) {
  node[u]->cnt = node[u]->tree_siz = 1;
  for (Edge* e = H[u]; e; e = e->next) {
    int v = e->v;
    dfs(v);
    node[u]->cnt += 2LL * node[u]->tree_siz * node[v]->tree_siz;
    node[u]->tree_siz += node[v]->tree_siz;
  }
  ans += node[u]->cnt * node[u]->val;
  node[u]->siz = node[u]->tree_siz;
}
void solve() {
  int x, y;
  char op[2];
  double tot = (double)n * n;
  clear();
  for (int i = (1); i <= (n); ++i) {
    node[i] = curN++;
    node[i]->new_node();
  }
  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("%d", &node[i]->val);
  dfs(1);
  printf("%.10f\n", ans / tot);
  scanf("%d", &m);
  while (m--) {
    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 -= 2LL * o->sum * node[x]->tree_siz;
      o->add_siz(-node[x]->tree_siz);
      node[x]->c[0]->f = null;
      node[x]->c[0] = null;
      node[x]->push_up();
      o->push_up();
      node[y]->access();
      ans += 2LL * node[y]->sum * node[x]->tree_siz;
      node[y]->add_siz(node[x]->tree_siz);
      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;
    }
    printf("%.10f\n", ans / tot);
  }
}
int main() {
  while (~scanf("%d", &n)) solve();
  return 0;
}