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;
int N, M, Q, C;
int F[50005], Log[50005];
int TT[50005];
vector<int> G[50005];
int Cost[50005], Level[50005];
bool Blocked[50005];
int P[50005], Sz[50005];
struct Elem {
  long long A, B;
  int H;
};
unordered_map<int, Elem> X[50005];
int Father[22][50005];
long long Dist[50005], Sum[50005];
int Cnt[50005];
void Read() {
  scanf("%d%d%d%d", &N, &M, &Q, &C);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &F[i]);
    Cnt[F[i]]++;
  }
  for (int i = 2; i <= N; i++) {
    int p;
    scanf("%d", &p);
    TT[i] = p;
    Father[0][i] = p;
    G[p].push_back(i);
    G[i].push_back(p);
  }
  for (int i = 1; i <= M; i++) scanf("%d", &Cost[i]);
}
void precalcLog() {
  for (int i = 2; i <= N; i++) Log[i] = Log[i / 2] + 1;
}
void precalcFather() {
  for (int i = 1; i <= Log[N]; i++)
    for (int j = 1; j <= N; j++) Father[i][j] = Father[i - 1][Father[i - 1][j]];
}
int Anc(int x, int dist) {
  while (dist > 0) {
    int k = Log[dist];
    x = Father[k][x];
    dist -= (1 << k);
  }
  return x;
}
int Distance(int x, int y) {
  int initx = x, inity = y;
  if (Level[x] > Level[y]) swap(x, y);
  y = Anc(y, Level[y] - Level[x]);
  int lca;
  if (x == y)
    lca = x;
  else {
    for (int k = Log[N]; k >= 0; k--)
      if (Father[k][x] != Father[k][y]) {
        x = Father[k][x];
        y = Father[k][y];
      }
    lca = Father[0][x];
  }
  return Level[initx] + Level[inity] - 2 * Level[lca];
}
void DFS(int node, int father) {
  Level[node] = Level[father] + 1;
  for (int i = 0; i < G[node].size(); i++) {
    int neighb = G[node][i];
    if (neighb == father) continue;
    DFS(neighb, node);
  }
}
void DFS2(int node, int father) {
  Sz[node] = 1;
  for (int i = 0; i < G[node].size(); i++) {
    int neighb = G[node][i];
    if (neighb == father || Blocked[neighb] == 1) continue;
    DFS2(neighb, node);
    Sz[node] += Sz[neighb];
  }
}
int findCentroid(int node, int father, int sz) {
  for (int i = 0; i < G[node].size(); i++) {
    int neighb = G[node][i];
    if (neighb == father || Blocked[neighb] == 1) continue;
    if (Sz[neighb] > sz / 2) return findCentroid(neighb, node, sz);
  }
  return node;
}
void build() {
  for (int i = 1; i <= N; i++) {
    int color = F[i];
    int node = i;
    Sum[color] += Level[i];
    int nr = 0;
    while (node != 0) {
      ++nr;
      Elem &curr = X[node][color];
      int father = P[node];
      if (father != 0) {
        Elem &prev = X[father][color];
        int d = Distance(i, father);
        Dist[color] += 1LL * d * (prev.H - curr.H);
        Dist[color] += prev.A - curr.B;
        curr.B += d;
      }
      curr.H++;
      int dist = Distance(i, node);
      curr.A += dist;
      node = father;
    }
    node = i;
    Dist[color] += X[i][color].A;
  }
}
void Update(int node, int c) {
  int color = F[node];
  F[node] = c;
  Cnt[color]--;
  Cnt[c]++;
  Sum[color] -= Level[node];
  Sum[c] += Level[node];
  int i = node;
  Dist[color] -= X[node][color].A;
  while (node != 0) {
    Elem &curr = X[node][color];
    int father = P[node];
    if (father != 0) {
      Elem &prev = X[father][color];
      int d = Distance(i, father);
      Dist[color] -= 1LL * d * (prev.H - curr.H);
      Dist[color] -= prev.A - curr.B;
      curr.B -= d;
    }
    curr.H--;
    int dist = Distance(i, node);
    curr.A -= dist;
    if (curr.H == 0) {
      X[node].erase(color);
    }
    node = father;
  }
  node = i;
  color = c;
  Dist[color] += X[i][color].A;
  while (node != 0) {
    Elem &curr = X[node][color];
    int father = P[node];
    if (father != 0) {
      Elem &prev = X[father][color];
      int d = Distance(i, father);
      Dist[color] += 1LL * d * (prev.H - curr.H);
      Dist[color] += prev.A - curr.B;
      curr.B += d;
    }
    curr.H++;
    int dist = Distance(i, node);
    curr.A += dist;
    node = father;
  }
}
void Query(int color) {
  double ans = (double)C * (double)C;
  ans -= (2.0 * C * Cost[color] * (Sum[color])) / (double)N;
  double aux = -Dist[color];
  aux += (Cnt[color]) * Sum[color];
  ans += (1.0 * Cost[color] * Cost[color] * aux) / (double)N;
  printf("%.12f\n", ans);
}
void Decomposition(int root, int father) {
  DFS2(root, 0);
  int centroid = findCentroid(root, 0, Sz[root]);
  Blocked[centroid] = 1;
  P[centroid] = father;
  for (int i = 0; i < G[centroid].size(); i++) {
    int neighb = G[centroid][i];
    if (Blocked[neighb] == 1 || neighb == father) continue;
    Decomposition(neighb, centroid);
  }
}
int main() {
  Read();
  precalcLog();
  precalcFather();
  DFS(1, 0);
  Decomposition(1, 0);
  build();
  for (int i = 1; i <= Q; i++) {
    int type, x, y;
    scanf("%d", &type);
    if (type == 1) {
      scanf("%d%d", &x, &y);
      Update(x, y);
    } else {
      scanf("%d", &x);
      Query(x);
    }
  }
  return 0;
}