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;
const int inf = (1 << 30) - 1;
const long long linf = (1ll << 62) - 1;
const int N = 1e5 + 100;
int n, m;
long double c;
int q;
vector<int> g[N];
vector<pair<int, int>> req[N];
long double cost[N];
bool tp[N];
long double ans[N];
struct segtree {
  segtree(int n) {
    this->n = n;
    sum.assign(n * 4 + 100, 0);
    add.assign(n * 4 + 100, 0);
    sum2.assign(n * 4 + 100, 0);
    len.assign(n * 4 + 100, 0);
    make_rmq(1, 0, n - 1);
  }
  void make_rmq(int i, int l, int r) {
    len[i] = r - l + 1;
    if (l == r) {
      return;
    }
    make_rmq(i * 2, l, (l + r) / 2);
    make_rmq(i * 2 + 1, (l + r) / 2 + 1, r);
  }
  long double get2(int i) {
    return sum2[i] + 2 * add[i] * sum[i] + add[i] * add[i] * len[i];
  }
  long double get(int i) { return sum[i] + len[i] * add[i]; }
  void recalc(int i) {
    sum[i] = get(i * 2) + get(i * 2 + 1);
    sum2[i] = get2(i * 2) + get2(i * 2 + 1);
  }
  void update(int i, int ll, int rr, int l, int r, long double c) {
    if (ll > r || rr < l) {
      return;
    }
    if (l <= ll && rr <= r) {
      return void(add[i] += c);
    }
    update(i * 2, ll, (ll + rr) / 2, l, r, c);
    update(i * 2 + 1, (ll + rr) / 2 + 1, rr, l, r, c);
    recalc(i);
  }
  void update(int l, int r, long double c) { update(1, 0, n - 1, l, r, c); }
  long double total2() { return get2(1); }
  long double total() { return get(1); }
  vector<long double> sum, add, sum2, len;
  int n;
};
int sz[N], hunext[N], parent[N];
void dfsNext(int v, int p = -1) {
  sz[v] = 1;
  parent[v] = p;
  for (int to : g[v]) {
    if (to != p) {
      dfsNext(to, v);
      sz[v] += sz[to];
    }
  }
  hunext[v] = -1;
  for (int to : g[v]) {
    if (to != p && (hunext[v] == -1 || sz[hunext[v]] < sz[to])) {
      hunext[v] = to;
    }
  }
}
vector<vector<int>> hld;
int huindex[N], pos[N];
vector<segtree> rmq;
void build() {
  static bool used[N];
  for (int i = 0; i < n; i++) {
    int cur = i;
    if (!used[cur]) {
      vector<int> path;
      while (cur != -1) {
        used[cur] = true;
        path.push_back(cur);
        cur = hunext[cur];
      }
      hld.push_back(path);
    }
  }
  for (int i = 0; i < ((int)(hld).size()); i++) {
    for (int j = 0; j < ((int)(hld[i]).size()); j++) {
      huindex[hld[i][j]] = i;
      pos[hld[i][j]] = j;
    }
  }
  for (int i = 0; i < ((int)(hld).size()); i++) {
    rmq.emplace_back(((int)(hld[i]).size()));
  }
}
namespace process {
vector<int> vertices;
vector<pair<int, int>> req;
long double cost;
vector<int> rmq[N * 4 + 100];
long double total2 = 0, total = 0;
void add(int x, long double c) {
  while (x != -1) {
    int huindex = ::huindex[x], pos = ::pos[x];
    total2 -= ::rmq[huindex].total2();
    total -= ::rmq[huindex].total();
    ::rmq[huindex].update(0, pos, c);
    total2 += ::rmq[huindex].total2();
    total += ::rmq[huindex].total();
    x = hld[huindex].front();
    x = parent[x];
  }
}
inline long double getAnswer() {
  return c * c - 2 * c * cost * total / n + total2 * cost * cost / n;
}
void update(int i, int ll, int rr, int l, int r, int x) {
  if (ll > r || rr < l) {
    return;
  }
  if (l <= ll && rr <= r) {
    return void(rmq[i].push_back(x));
  }
  update(i * 2, ll, (ll + rr) / 2, l, r, x);
  update(i * 2 + 1, (ll + rr) / 2 + 1, rr, l, r, x);
}
void divideAndConquer(int i, int l, int r) {
  for (int x : rmq[i]) {
    add(x, 1);
  }
  if (l == r) {
    if (req[l].first == 2) {
      ans[req[l].second] = getAnswer();
    }
  } else {
    divideAndConquer(i * 2, l, (l + r) / 2);
    divideAndConquer(i * 2 + 1, (l + r) / 2 + 1, r);
  }
  for (int x : rmq[i]) {
    add(x, -1);
  }
}
void process() {
  vertices.clear();
  for (auto i : req) {
    if (i.first != 2) {
      vertices.push_back(i.second);
    }
  }
  sort((vertices).begin(), (vertices).end()),
      vertices.resize(unique((vertices).begin(), (vertices).end()) -
                      vertices.begin());
  static int last[N];
  for (int i : vertices) {
    last[i] = -1;
  }
  fill_n(rmq, ((int)(req).size()) * 4 + 100, vector<int>());
  for (int i = 0; i < ((int)(req).size()); i++) {
    if (req[i].first == 2) {
      continue;
    }
    if (req[i].first == 0) {
      assert(last[req[i].second] == -1);
      last[req[i].second] = i;
    } else {
      assert(last[req[i].second] != -1);
      update(1, 0, ((int)(req).size()) - 1, last[req[i].second], i,
             req[i].second);
      last[req[i].second] = -1;
    }
  }
  for (int i : vertices) {
    if (last[i] != -1) {
      update(1, 0, ((int)(req).size()) - 1, last[i], ((int)(req).size()) - 1,
             i);
    }
  }
  divideAndConquer(1, 0, ((int)(req).size()) - 1);
}
void process(const vector<pair<int, int>> &req, long double cost) {
  process::req = req;
  process::cost = cost;
  process();
}
}  // namespace process
int main() {
  cin >> n >> m >> q >> c;
  static int cur[N];
  for (int i = 0; i < n; i++) {
    int f;
    scanf("%d", &f), f--;
    req[f].push_back(make_pair(0, i));
    cur[i] = f;
  }
  for (int i = 1; i < n; i++) {
    int p;
    scanf("%d", &p), p--;
    g[p].push_back(i);
  }
  for (int i = 0; i < m; i++) {
    double x;
    scanf("%lf", &x);
    cost[i] = x;
  }
  for (int i = 0; i < q; i++) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      int x, w;
      scanf("%d%d", &x, &w), x--, w--;
      req[cur[x]].push_back(make_pair(1, x));
      req[w].push_back(make_pair(0, x));
      cur[x] = w;
    } else {
      tp[i] = 1;
      int k;
      scanf("%d", &k), k--;
      req[k].push_back(make_pair(2, i));
    }
  }
  dfsNext(0);
  build();
  for (int i = 0; i < m; i++) {
    if (req[i].empty()) {
      continue;
    }
    process::process(req[i], cost[i]);
  }
  for (int i = 0; i < q; i++) {
    if (tp[i]) {
      printf("%.20lf\n", (double)ans[i]);
    }
  }
  return 0;
}