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;
using mat = array<array<long long, 3>, 3>;
inline void mul(mat &a, const mat &b) {
  static mat c;
  for (int i = 0; i < 3; ++i)
    for (int j = 0; j < 3; ++j) {
      c[i][j] = 0;
      for (int k = 0; k < 3; ++k) c[i][j] += a[i][k] * b[k][j];
    }
  a = c;
  return;
}
const mat I = {array<long long, 3>{1, 0, 0}, array<long long, 3>{0, 1, 0},
               array<long long, 3>{0, 0, 1}};
const mat P = {array<long long, 3>{1, 2, 1}, array<long long, 3>{0, 1, 1},
               array<long long, 3>{0, 0, 1}};
const mat N = {array<long long, 3>{1, -2, 1}, array<long long, 3>{0, 1, -1},
               array<long long, 3>{0, 0, 1}};
struct node {
  node *ch[2];
  array<long long, 3> num;
  mat tag;
  node() {
    memset(ch, 0, sizeof ch);
    fill(num.begin(), num.end(), 0);
    tag = I;
  }
  void pull() {
    for (int i = 0; i < 3; ++i) num[i] = ch[0]->num[i] + ch[1]->num[i];
    return;
  }
  void M(mat x) {
    mul(tag, x);
    array<long long, 3> t;
    for (int i = 0; i < 3; ++i) {
      t[i] = 0;
      for (int j = 0; j < 3; ++j) t[i] += x[i][j] * num[j];
    }
    num = t;
    return;
  }
  void push() {
    for (int i = 0; i < 2; ++i) ch[i]->M(tag);
    tag = I;
    return;
  }
};
struct segment_tree {
  int n;
  node *root;
  segment_tree() { root = 0; }
  segment_tree(vector<array<long long, 3> > &a) {
    function<void(node *&, int, int)> B = [&](node *&u, int l, int r) {
      u = new node;
      if (l == r) {
        u->num = a[l];
        return;
      }
      int mid = l + r >> 1;
      return B(u->ch[0], l, mid), B(u->ch[1], mid + 1, r), u->pull();
    };
    n = a.size();
    B(root, 0, n - 1);
  }
  void M(int a, int b, mat x) {
    assert(0 <= a && b < n);
    if (a <= b) M(a, b, x, root, 0, n - 1);
    return;
  }
  array<long long, 3> Q() {
    return root ? root->num : array<long long, 3>{0, 0, 0};
  }

 private:
  void M(int a, int b, mat x, node *&u, int l, int r) {
    if (a <= l && r <= b) {
      u->M(x);
      return;
    }
    int mid = l + r >> 1;
    u->push();
    if (a <= mid) M(a, b, x, u->ch[0], l, mid);
    if (mid < b) M(a, b, x, u->ch[1], mid + 1, r);
    return u->pull();
  }
};
int main() {
  int n, m, q, C, clk;
  cin >> n >> m >> q >> C;
  vector<segment_tree> seg(m);
  vector<int> c(m), f(n), dfn(n), End(n), dep(n);
  vector<pair<int, int> > qry(q);
  int lgn = 0;
  while (n >> lgn) ++lgn;
  vector<vector<int> > par(n, vector<int>(lgn, -1)), has(m), g(n), ndfn(m),
      anc(m), npar(m);
  vector<vector<vector<int> > > ng(m);
  vector<map<int, int> > hsh(m);
  for (int i = 0; i < n; ++i) cin >> f[i], --f[i], has[f[i]].push_back(i);
  for (int i = 1; i < n; ++i)
    cin >> par[i][0], --par[i][0], g[par[i][0]].push_back(i);
  for (int i = 0; i < m; ++i) cin >> c[i];
  for (int i = 0; i < q; ++i) {
    int typ;
    cin >> typ;
    if (typ == 1)
      cin >> qry[i].first >> qry[i].second, --qry[i].first, --qry[i].second,
          has[qry[i].second].push_back(qry[i].first);
    else
      qry[i].first = -1, cin >> qry[i].second, --qry[i].second;
  }
  function<void(int)> dfs = [&](int u) {
    dfn[u] = ++clk;
    for (int i = 1; i < lgn; ++i)
      par[u][i] = ((~par[u][i - 1]) ? par[par[u][i - 1]][i - 1] : -1);
    for (int v : g[u]) dep[v] = dep[u] + 1, dfs(v);
    End[u] = clk;
    return;
  };
  dfs(0);
  auto lca = [&](int u, int v) {
    if (dep[u] < dep[v]) swap(u, v);
    for (int dlt = dep[u] - dep[v], i = 0; i < lgn; ++i)
      if ((dlt >> i) & 1) u = par[u][i];
    if (u == v) return u;
    for (int i = lgn - 1; ~i; --i)
      if (par[u][i] != par[v][i]) u = par[u][i], v = par[v][i];
    return par[u][0];
  };
  for (int i = 0; i < m; ++i) {
    if (!has[i].size()) continue;
    sort(has[i].begin(), has[i].end(),
         [&](int u, int v) { return dfn[u] < dfn[v]; });
    for (int sz = has[i].size(), j = 1; j < sz; ++j)
      has[i].push_back(lca(has[i][j], has[i][j - 1]));
    sort(has[i].begin(), has[i].end(),
         [&](int u, int v) { return dfn[u] < dfn[v]; });
    has[i].resize(unique(has[i].begin(), has[i].end()) - has[i].begin());
    ng[i].resize(has[i].size());
    vector<int> stk, id, val(has[i].size());
    for (int j = 0; j < has[i].size(); ++j) {
      int u = has[i][j];
      while (stk.size() &&
             !(dfn[stk.back()] <= dfn[u] && dfn[u] <= End[stk.back()]))
        stk.pop_back(), id.pop_back();
      if (stk.size())
        ng[i][id.back()].push_back(j), val[j] = dep[u] - dep[stk.back()];
      else
        val[j] = dep[u] + 1;
      stk.push_back(u);
      id.push_back(j);
    }
    vector<int> sz(has[i].size());
    npar[i].resize(has[i].size());
    npar[i][0] = -1;
    function<void(int)> dfs1 = [&](int u) {
      sz[u] = 1;
      if (!ng[i][u].size()) return;
      int son, t = 0;
      for (int v : ng[i][u]) {
        npar[i][v] = u;
        dfs1(v);
        sz[u] += sz[v];
        if (sz[v] > t) t = sz[v], son = v;
      }
      for (int j = 0; j < ng[i][u].size(); ++j)
        if (ng[i][u][j] == son) {
          swap(ng[i][u][j], ng[i][u][0]);
          break;
        }
      return;
    };
    dfs1(0);
    ndfn[i].resize(has[i].size());
    anc[i].resize(has[i].size());
    int clk = 0;
    function<void(int, int)> dfs2 = [&](int u, int p) {
      anc[i][u] = p;
      ndfn[i][u] = clk++;
      for (int j = 0; j < ng[i][u].size(); ++j)
        dfs2(ng[i][u][j], j ? ng[i][u][j] : p);
      return;
    };
    dfs2(0, 0);
    vector<array<long long, 3> > a(has[i].size());
    for (int j = 0; j < has[i].size(); ++j)
      a[ndfn[i][j]] = {0, 0, val[j]}, hsh[i][has[i][j]] = j;
    seg[i] = segment_tree(a);
  }
  function<void(int, int, mat)> M = [&](int i, int u, mat x) {
    u = hsh[i][u];
    while (~u) {
      int p = anc[i][u];
      seg[i].M(ndfn[i][p], ndfn[i][u], x);
      u = npar[i][p];
    }
    return;
  };
  for (int i = 0; i < n; ++i) M(f[i], i, P);
  for (int i = 0; i < q; ++i) {
    int x = qry[i].first, y = qry[i].second;
    if (x < 0) {
      auto t = seg[y].Q();
      cout << setprecision(10)
           << 1.0 *
                  (t[0] * c[y] * c[y] + (long long)C * C * n -
                   2ll * C * t[1] * c[y]) /
                  (1. * n)
           << endl;
    } else {
      M(f[x], x, N);
      M(f[x] = y, x, P);
    }
  }
  return 0;
}