Problem: Santa has an infinite number of candies for each of m flavours. You are given a rooted tree with n vertices. The root of the tree is the vertex 1. Each vertex contains exactly one candy. The i-th vertex has a candy of flavour f_i.

Sometimes Santa fears that candies of flavour k have melted. He chooses any vertex x randomly and sends the subtree of x to the Bakers for a replacement. In a replacement, all the candies with flavour k are replaced with a new candy of the same flavour. The candies which are not of flavour k are left unchanged. After the replacement, the tree is restored.

The actual cost of replacing one candy of flavour k is c_k (given for each k). The Baker keeps the price fixed in order to make calculation simple. Every time when a subtree comes for a replacement, the Baker charges C, no matter which subtree it is and which flavour it is.

Suppose that for a given flavour k the probability that Santa chooses a vertex for replacement is same for all the vertices. You need to find out the expected value of error in calculating the cost of replacement of flavour k. The error in calculating the cost is defined as follows.

$$$ Error\ E(k) =\ (Actual Cost\ –\ Price\ charged\ by\ the\ Bakers) ^ 2.$$$

Note that the actual cost is the cost of replacement of one candy of the flavour k multiplied by the number of candies in the subtree.

Also, sometimes Santa may wish to replace a candy at vertex x with a candy of some flavour from his pocket.

You need to handle two types of operations: 

  * Change the flavour of the candy at vertex x to w. 
  * Calculate the expected value of error in calculating the cost of replacement for a given flavour k. 

Input

The first line of the input contains four integers n (2 ⩽ n ⩽ 5 ⋅ 10^4), m, q, C (1 ⩽ m, q ⩽ 5 ⋅ 10^4, 0 ⩽ C ⩽ 10^6) — the number of nodes, total number of different flavours of candies, the number of queries and the price charged by the Bakers for replacement, respectively.

The second line contains n integers f_1, f_2, ..., f_n (1 ⩽ f_i ⩽ m), where f_i is the initial flavour of the candy in the i-th node.

The third line contains n - 1 integers p_2, p_3, ..., p_n (1 ⩽ p_i ⩽ n), where p_i is the parent of the i-th node.

The next line contains m integers c_1, c_2, ... c_m (1 ⩽ c_i ⩽ 10^2), where c_i is the cost of replacing one candy of flavour i.

The next q lines describe the queries. Each line starts with an integer t (1 ⩽ t ⩽ 2) — the type of the query.

If t = 1, then the line describes a query of the first type. Two integers x and w follow (1 ⩽ x ⩽ n, 1 ⩽ w ⩽ m), it means that Santa replaces the candy at vertex x with flavour w.

Otherwise, if t = 2, the line describes a query of the second type and an integer k (1 ⩽ k ⩽ m) follows, it means that you should print the expected value of the error in calculating the cost of replacement for a given flavour k.

The vertices are indexed from 1 to n. Vertex 1 is the root.

Output

Output the answer to each query of the second type in a separate line.

Your answer is considered correct if its absolute or relative error does not exceed 10^{-6}.

Formally, let your answer be a, and the jury's answer be b. The checker program considers your answer correct if and only if (|a-b|)/(max(1,b))⩽ 10^{-6}.

Example

Input

3 5 5 7
3 1 4
1 1
73 1 48 85 89
2 1
2 3
1 2 3
2 1
2 3


Output

2920.333333333333
593.000000000000
49.000000000000
3217.000000000000

Note

For 1-st query, the error in calculating the cost of replacement for flavour 1 if vertex 1, 2 or 3 is chosen are 66^2, 66^2 and (-7)^2 respectively. Since the probability of choosing any vertex is same, therefore the expected value of error is (66^2+66^2+(-7)^2)/(3).

Similarly, for 2-nd query the expected value of error is (41^2+(-7)^2+(-7)^2)/(3).

After 3-rd query, the flavour at vertex 2 changes from 1 to 3.

For 4-th query, the expected value of error is ((-7)^2+(-7)^2+(-7)^2)/(3).

Similarly, for 5-th query, the expected value of error is (89^2+41^2+(-7)^2)/(3).

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
template <typename TP>
inline bool rd(TP& r) {
  r = 0;
  bool mns = 0;
  char tmp = getchar();
  while (tmp < '0' || tmp > '9') {
    if (tmp == '-') mns = 1;
    if (tmp == EOF) return 0;
    tmp = getchar();
  }
  while ('0' <= tmp && tmp <= '9') {
    r = (r << 3) + (r << 1) + tmp - '0';
    tmp = getchar();
  }
  if (mns) r = -r;
  return 1;
}
int n, m, nq, np;
int h[50100 * 10], t[50100 * 10 * 2], x[50100 * 10 * 2], ne;
int f[50100 * 10][22], dep[50100 * 10], z[50100 * 10];
void ade(int u, int v) {
  ++ne;
  x[ne] = h[u];
  h[u] = ne;
  t[ne] = v;
}
vector<int> ks[50100], ns[50100];
inline int get(int i, int k) {
  return lower_bound(ks[i].begin(), ks[i].end(), k) - ks[i].begin();
}
struct query {
  int type, x, w, k;
  inline void read() {
    rd(type);
    if (type == 1)
      rd(x), rd(w);
    else
      rd(k);
  }
};
query qs[50100];
int flvr[50100];
vector<int> fl[50100];
long long C, c[50100], ans[50100];
inline int LCA(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  if (dep[u] != dep[v])
    for (int k = 20; k >= 0; --k)
      if (dep[f[u][k]] >= dep[v]) u = f[u][k];
  if (u == v) return u;
  for (int k = 20; k >= 0; --k)
    if (f[u][k] != f[v][k]) u = f[u][k], v = f[v][k];
  return f[u][0];
}
namespace voidtree {
int dfn[50100 * 10], df;
bool cmp(int a, int b) { return dfn[a] < dfn[b]; }
void dfs(int now) {
  dep[now] = dep[f[now][0]] + 1;
  dfn[now] = ++df;
  for (int j = h[now]; j; j = x[j])
    if (t[j] != f[now][0]) dfs(t[j]);
}
int stk[50100 * 10], tp;
int tmp[50100 * 10];
inline void work(int k) {
  sort(fl[k].begin(), fl[k].end(), cmp);
  int lth = unique(fl[k].begin(), fl[k].end()) - fl[k].begin();
  fl[k].resize(lth);
  tp = 0;
  stk[++tp] = 1;
  tmp[1] = ++np;
  int now, lca;
  for (int i = 0; i < fl[k].size(); ++i) {
    now = fl[k][i];
    if (now == 1) {
      ks[now].push_back(k);
      ns[now].push_back(tmp[now]);
      continue;
    }
    tmp[now] = ++np;
    ks[now].push_back(k);
    ns[now].push_back(tmp[now]);
    lca = LCA(now, stk[tp]);
    if (lca == stk[tp]) {
      stk[++tp] = now;
      continue;
    }
    while (tp > 1) {
      if (dfn[stk[tp - 1]] > dfn[lca]) {
        ade(tmp[stk[tp]], tmp[stk[tp - 1]]),
            ade(tmp[stk[tp - 1]], tmp[stk[tp]]);
        z[tmp[stk[tp]]] = dep[stk[tp]] - dep[stk[tp - 1]];
        --tp;
      } else if (dfn[stk[tp - 1]] == dfn[lca]) {
        ade(tmp[stk[tp]], tmp[stk[tp - 1]]),
            ade(tmp[stk[tp - 1]], tmp[stk[tp]]);
        z[tmp[stk[tp]]] = dep[stk[tp]] - dep[lca];
        --tp;
        break;
      } else if (dfn[stk[tp - 1]] < dfn[lca]) {
        tmp[lca] = ++np;
        ade(tmp[stk[tp]], tmp[lca]), ade(tmp[lca], tmp[stk[tp]]);
        z[tmp[stk[tp]]] = dep[stk[tp]] - dep[lca];
        --tp;
        stk[++tp] = lca;
        break;
      }
    }
    stk[++tp] = now;
  }
  while (tp > 1) {
    ade(tmp[stk[tp]], tmp[stk[tp - 1]]);
    ade(tmp[stk[tp - 1]], tmp[stk[tp]]);
    z[tmp[stk[tp]]] = dep[stk[tp]] - dep[stk[tp - 1]];
    --tp;
  }
  z[tmp[stk[1]]] = 1;
}
inline void build() {
  dfs(1);
  for (int k = 1; k <= 20; ++k)
    for (int i = 1; i <= n; ++i) f[i][k] = f[f[i][k - 1]][k - 1];
  for (int i = 1; i <= m; ++i) work(i);
}
}  // namespace voidtree
namespace pou {
int ln[50100 * 10];
namespace seg {
int l[50100 * 10 * 4], r[50100 * 10 * 4];
long long zsm[50100 * 10 * 4], sm[50100 * 10 * 4], pl[50100 * 10 * 4];
void build(int o, int ll, int rr) {
  l[o] = ll, r[o] = rr;
  sm[o] = pl[o] = 0;
  if (ll == rr) {
    zsm[o] = z[ln[ll]];
    return;
  }
  int mid = (ll + rr) >> 1;
  build((o << 1), ll, mid);
  build(((o << 1) | 1), mid + 1, rr);
  zsm[o] = zsm[(o << 1)] + zsm[((o << 1) | 1)];
}
inline void update(int o, int pls) {
  pl[o] += pls;
  sm[o] += pls * zsm[o];
}
inline void pass(int o) {
  if (pl[o] && l[o] != r[o]) {
    update((o << 1), pl[o]);
    update(((o << 1) | 1), pl[o]);
  }
  pl[o] = 0;
}
void add(int o, int ll, int rr, int pls) {
  if (ll <= l[o] && r[o] <= rr) {
    update(o, pls);
    return;
  }
  pass(o);
  int mid = (l[o] + r[o]) >> 1;
  if (ll <= mid) add((o << 1), ll, rr, pls);
  if (mid + 1 <= rr) add(((o << 1) | 1), ll, rr, pls);
  sm[o] = sm[(o << 1)] + sm[((o << 1) | 1)];
}
long long ask(int o, int ll, int rr) {
  if (ll <= l[o] && r[o] <= rr) return sm[o];
  pass(o);
  long long re = 0;
  int mid = (l[o] + r[o]) >> 1;
  if (ll <= mid) re += ask((o << 1), ll, rr);
  if (mid + 1 <= rr) re += ask(((o << 1) | 1), ll, rr);
  return re;
}
}  // namespace seg
int hd[50100 * 10], po[50100 * 10], tot;
int sz[50100 * 10], mxson[50100 * 10];
void getsz(int now, int fa) {
  sz[now] = 1, mxson[now] = 0;
  f[now][0] = fa;
  for (int j = h[now]; j; j = x[j])
    if (t[j] != f[now][0]) {
      getsz(t[j], now);
      sz[now] += sz[t[j]];
      if (sz[t[j]] > sz[mxson[now]]) mxson[now] = t[j];
    }
}
void dfs(int now, int hed) {
  if (po[now]) printf("%d\n", now);
  if (hed == -1) hed = now;
  hd[now] = hed, po[now] = ++tot, ln[tot] = now;
  if (mxson[now]) dfs(mxson[now], hed);
  for (int j = h[now]; j; j = x[j])
    if (t[j] != f[now][0] && t[j] != mxson[now]) dfs(t[j], -1);
}
void build() {
  for (int i = 1; i <= np; ++i)
    if (!po[i]) {
      getsz(i, 0);
      dfs(i, -1);
    }
  seg::build(1, 1, np);
}
inline void add(int u, int pls) {
  while (u) {
    seg::add(1, po[hd[u]], po[u], pls);
    u = f[hd[u]][0];
  }
}
inline long long ask(int u) {
  long long re = 0;
  while (u) {
    re += seg::ask(1, po[hd[u]], po[u]);
    u = f[hd[u]][0];
  }
  return re;
}
}  // namespace pou
int main() {
  rd(n), rd(m), rd(nq), rd(C);
  np = n;
  for (int i = 1; i <= n; ++i) {
    rd(flvr[i]);
    fl[flvr[i]].push_back(i);
  }
  for (int i = 2; i <= n; ++i) {
    rd(f[i][0]);
    ade(i, f[i][0]), ade(f[i][0], i);
  }
  for (int i = 1; i <= m; ++i) rd(c[i]);
  for (int i = 1; i <= nq; ++i) {
    qs[i].read();
    if (qs[i].type == 1) fl[qs[i].w].push_back(qs[i].x);
  }
  voidtree::build();
  pou::build();
  int now;
  for (int k = 1; k <= m; ++k) {
    ans[k] = C * C * n;
    for (int i = 0; i < fl[k].size(); ++i) {
      now = fl[k][i];
      if (flvr[now] != k) continue;
      ans[k] -= 2 * C * c[k] * dep[now];
      ans[k] += c[k] * c[k] * (2 * pou::ask(ns[now][get(now, k)]) + dep[now]);
      pou::add(ns[now][get(now, k)], 1);
    }
  }
  int w, k;
  for (int i = 1; i <= nq; ++i) {
    if (qs[i].type == 1) {
      now = qs[i].x, w = qs[i].w;
      k = flvr[now];
      ans[k] += 2 * C * c[k] * dep[now];
      ans[k] += c[k] * c[k] * (-2 * pou::ask(ns[now][get(now, k)]) + dep[now]);
      pou::add(ns[now][get(now, k)], -1);
      flvr[now] = w;
      k = flvr[now];
      ans[k] -= 2 * C * c[k] * dep[now];
      ans[k] += c[k] * c[k] * (2 * pou::ask(ns[now][get(now, k)]) + dep[now]);
      pou::add(ns[now][get(now, k)], 1);
    } else {
      k = qs[i].k;
      printf("%.9lf\n", (1.0 * ans[k]) / (1.0 * n));
    }
  }
  return 0;
}