#include <bits/stdc++.h>
using namespace std;
int n, m, q;
double c;
int dist[100000][20];
double depth[100000];
int p[100000], fa[100000], lst[100000];
int tot;
int aim[200000], subs[200000], adj[100000];
int favor[200000];
int scalar[100000];
int color[60000];
int dep[100000];
map<int, double> sumdepth[60000], fadepth[60000], subnum[60000];
int num[1000010];
double alldep[1000010];
double cost2[100000], cost1[100000];
double ans;
void getdep(int x, int father, int d) {
  depth[x] = d;
  int i = adj[x];
  while (i) {
    if (aim[i] != father) getdep(aim[i], x, d + 1);
    i = subs[i];
  }
}
void dfs(int x, int d) {
  int i = adj[x];
  lst[d] = x;
  if (d > tot) tot = d;
  while (i) {
    if (aim[i] != fa[x] && p[aim[i]] == 0) {
      fa[aim[i]] = x;
      dfs(aim[i], d + 1);
    }
    i = subs[i];
  }
}
int getcentroid(int x) {
  fa[x] = 0;
  tot = 0;
  lst[tot] = x;
  dfs(x, 0);
  x = lst[tot];
  fa[x] = 0;
  tot = 0;
  dfs(x, 0);
  for (int i = tot; i >= 0; --i) {
    if (i < tot) lst[i] = fa[lst[i + 1]];
    if (i == tot / 2) return lst[i];
  }
}
void discomp(int x, int father, int d, int len) {
  dist[x][d] = len;
  int i = adj[x];
  while (i) {
    if (aim[i] != father && p[aim[i]] == 0) discomp(aim[i], x, d, len + 1);
    i = subs[i];
  }
}
void buildcentree(int parent, int x, int d) {
  int cent;
  cent = getcentroid(x);
  p[cent] = parent;
  discomp(cent, 0, d, 0);
  dep[cent] = d;
  int i = adj[cent];
  while (i) {
    if (p[aim[i]] == 0) buildcentree(cent, aim[i], d + 1);
    i = subs[i];
  }
}
void Insert(int x, int y) {
  int tc, tx, d, computed;
  if (color[x] > 0) {
    tx = x;
    tc = color[x];
    num[tc] -= 1;
    alldep[tc] -= depth[tx];
    cost1[tc] -= depth[tx];
    cost2[tc] -= depth[tx] * num[tc] + alldep[tc] + depth[tx];
    d = dep[x];
    computed = 0;
    int prev = 0;
    while (d >= 0) {
      sumdepth[tx][tc] -= dist[x][d];
      if (prev > 0) fadepth[prev][tc] -= dist[x][d];
      subnum[tx][tc] -= 1;
      cost2[tc] += sumdepth[tx][tc] - fadepth[prev][tc];
      cost2[tc] += dist[x][d] * (subnum[tx][tc] - computed);
      computed = subnum[tx][tc];
      prev = tx;
      tx = p[tx];
      --d;
    }
  }
  tx = x;
  color[tx] = y;
  cost1[y] += depth[tx];
  cost2[y] += depth[tx] * num[y] + alldep[y] + depth[tx];
  alldep[y] += depth[tx];
  num[y] += 1;
  d = dep[x];
  computed = 0;
  int prev = 0;
  while (d >= 0) {
    cost2[y] -= sumdepth[tx][y] - fadepth[prev][y];
    cost2[y] -= dist[x][d] * (subnum[tx][y] - computed);
    computed = subnum[tx][y];
    sumdepth[tx][y] += dist[x][d];
    if (prev > 0) fadepth[prev][y] += dist[x][d];
    subnum[tx][y] += 1;
    prev = tx;
    tx = p[tx];
    --d;
  }
}
int main() {
  scanf("%d %d %d %lf", &n, &m, &q, &c);
  for (int i = 1; i <= n; ++i) scanf("%d", &favor[i]);
  int pa;
  for (int i = 2; i <= n; ++i) {
    scanf("%d", &pa);
    aim[i * 2 - 3] = pa;
    subs[i * 2 - 3] = adj[i];
    adj[i] = i * 2 - 3;
    aim[i * 2 - 2] = i;
    subs[i * 2 - 2] = adj[pa];
    adj[pa] = i * 2 - 2;
  }
  getdep(1, 0, 1);
  for (int i = 1; i <= m; ++i) scanf("%d", &scalar[i]);
  buildcentree(-1, 1, 0);
  for (int i = 1; i <= n; ++i) Insert(i, favor[i]);
  int type, a, b;
  for (int i = 1; i <= q; ++i) {
    scanf("%d", &type);
    if (type == 1) {
      scanf("%d %d", &a, &b);
      Insert(a, b);
    } else {
      scanf("%d", &a);
      ans = cost2[a] * scalar[a] * scalar[a] - 2 * cost1[a] * scalar[a] * c +
            c * c * n;
      ans = ans / n;
      printf("%.9lf\n", ans);
    }
  }
  return 0;
}
