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;
inline void read(int &x) {
  int v = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = v * 10 + c - '0';
  while (isdigit(c = getchar())) v = v * 10 + c - '0';
  x = v * f;
}
inline void read(long long &x) {
  long long v = 0ll, f = 1ll;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = v * 10 + c - '0';
  while (isdigit(c = getchar())) v = v * 10 + c - '0';
  x = v * f;
}
inline void readc(char &x) {
  char c;
  while ((c = getchar()) == ' ')
    ;
  x = c;
}
inline void writes(string s) { puts(s.c_str()); }
inline void writeln() { writes(""); }
inline void writei(int x) {
  if (x < 0) {
    putchar('-');
    x = abs(x);
  }
  if (!x) putchar('0');
  char a[25];
  int top = 0;
  while (x) {
    a[++top] = (x % 10) + '0';
    x /= 10;
  }
  while (top) {
    putchar(a[top]);
    top--;
  }
}
inline void writell(long long x) {
  if (x < 0) {
    putchar('-');
    x = abs(x);
  }
  if (!x) putchar('0');
  char a[25];
  int top = 0;
  while (x) {
    a[++top] = (x % 10) + '0';
    x /= 10;
  }
  while (top) {
    putchar(a[top]);
    top--;
  }
}
long long n, m, i, j, lsz[50005], tsz[50005], x, y, ans[50005], sz[50005],
    v[50005], sum[50005];
long long fa[500005], lc[50005], rc[50005], tag[50005];
vector<long long> e[50005];
double all;
char op;
void dfs(long long x) {
  tsz[x] = ans[x] = 1;
  for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end(); it++) {
    fa[*it] = x;
    dfs(*it);
    ans[x] += 2 * tsz[x] * tsz[*it];
    tsz[x] += tsz[*it];
  }
  all += ans[x] * v[x];
  lsz[x] = tsz[x];
}
void print() { printf("%.18f\n", all / n / n); }
void pushup(long long x) { sum[x] = sum[lc[x]] + sum[rc[x]] + v[x] * lsz[x]; }
void upd(long long x, long long y) {
  if (!x) return;
  tsz[x] += y;
  tag[x] += y;
  ans[x] += 2 * lsz[x] * y;
}
void pushdo(long long x) {
  if (tag[x]) {
    if (lc[x]) upd(lc[x], tag[x]);
    if (rc[x]) upd(rc[x], tag[x]);
    tag[x] = 0;
  }
}
bool isrt(long long x) { return lc[fa[x]] != x && rc[fa[x]] != x; }
void rot(long long x) {
  long long y = fa[x];
  if (!isrt(y)) {
    long long z = fa[y];
    if (lc[z] == y)
      lc[z] = x;
    else
      rc[z] = x;
  }
  fa[x] = fa[y];
  fa[y] = x;
  if (lc[y] == x) {
    lc[y] = rc[x];
    if (lc[y]) fa[lc[y]] = y;
    rc[x] = y;
  } else {
    rc[y] = lc[x];
    if (rc[y]) fa[rc[y]] = y;
    lc[x] = y;
  }
  pushup(y);
  pushup(x);
}
void pushall(long long x) {
  if (!isrt(x)) pushall(fa[x]);
  pushdo(x);
}
void splay(long long x) {
  pushall(x);
  while (!isrt(x)) {
    long long y = fa[x];
    if (!isrt(y)) {
      long long z = fa[y];
      if ((lc[z] == y) == (lc[y] == x))
        rot(y);
      else
        rot(x);
    }
    rot(x);
  }
}
void access(long long x) {
  long long y = 0;
  while (x) {
    if (y) {
      while (lc[y]) y = lc[y];
      splay(y);
    }
    splay(x);
    lsz[x] = tsz[x] - tsz[y];
    rc[x] = y;
    pushup(x);
    y = x;
    x = fa[x];
  }
}
void cut(long long x) {
  access(x);
  splay(x);
  all -= 2 * sum[lc[x]] * tsz[x];
  upd(lc[x], -tsz[x]);
  fa[lc[x]] = 0;
  lc[x] = 0;
  pushup(x);
}
void link(long long x, long long y) {
  access(y);
  splay(y);
  all += 2 * sum[y] * tsz[x];
  upd(y, tsz[x]);
  fa[x] = y;
}
int main() {
  read(n);
  for (((i)) = (1); ((i)) <= ((n - 1)); ((i))++) {
    read(x);
    e[x].push_back(i + 1);
  }
  for (((i)) = (1); ((i)) <= ((n)); ((i))++) {
    read(v[i]);
  }
  dfs(1);
  read(m);
  print();
  while (m--) {
    scanf(" %c", &op);
    if (op == 'V') {
      read(x);
      read(y);
      access(x);
      splay(x);
      all -= ans[x] * v[x];
      v[x] = y;
      all += ans[x] * v[x];
    } else {
      read(x);
      read(y);
      access(y);
      splay(y);
      splay(x);
      if (!fa[x]) swap(x, y);
      cut(x);
      link(x, y);
    }
    print();
  }
  return 0;
}