#include <bits/stdc++.h>
using namespace std;
const int N = 5e4 + 5, mo = 1e9 + 7;
int n, m, q, cc, f[N], p[N], la[N], ne[N];
int ld[N], hv[N], ds, w[N], d[N], rt[N];
int op, x, W, L, R, ts;
unsigned long long C, c[N], ss[N], s[N];
struct no {
  int l, r;
  unsigned long long v, x;
} t[N * 100];
void dfs(int x) {
  ld[x] = 1;
  d[x] = d[p[x]] + 1;
  for (int i = la[x]; i; i = ne[i])
    dfs(i), ld[x] += ld[i], (ld[hv[x]] < ld[i] ? hv[x] = i : 0);
}
void df2(int x, int st) {
  ld[x] = st;
  w[x] = ++ds;
  if (!hv[x]) return;
  df2(hv[x], st);
  for (int i = la[x]; i; i = ne[i])
    if (i != hv[x]) df2(i, i);
}
void fill(int v, int l, int r, unsigned long long x) {
  t[v].x += x;
  t[v].v += x * (r - l + 1);
}
void aa(int v, int l, int m, int r) {
  if (t[v].x) {
    !t[v].r ? t[v].r = ++ts : 0;
    !t[v].l ? t[v].l = ++ts : 0;
    fill(t[v].r, m + 1, r, t[v].x);
    fill(t[v].l, l, m, t[v].x);
    t[v].x = 0;
  }
}
void chh(int &v, int l, int r, unsigned long long x) {
  if (!v) v = ++ts;
  if (L <= l && r <= R) {
    fill(v, l, r, x);
    return;
  }
  int m = l + r >> 1;
  aa(v, l, m, r);
  if (L <= m) chh(t[v].l, l, m, x);
  if (m < R) chh(t[v].r, m + 1, r, x);
  t[v].v = t[t[v].l].v + t[t[v].r].v;
}
unsigned long long gett(int v, int l, int r) {
  if (L <= l && r <= R) return t[v].v;
  int m = l + r >> 1;
  aa(v, l, m, r);
  return (L <= m ? gett(t[v].l, l, m) : 0) +
         (m < R ? gett(t[v].r, m + 1, r) : 0);
}
unsigned long long get(int a, int x) {
  unsigned long long t = 0;
  for (; x; x = p[ld[x]]) L = w[ld[x]], R = w[x], t += gett(rt[a], 1, n);
  return t;
}
void add(int a, int x, unsigned long long va) {
  for (; x; x = p[ld[x]]) L = w[ld[x]], R = w[x], chh(rt[a], 1, n, va);
}
void ch(int a, int x, unsigned long long va) {
  s[a] += va * d[x];
  if (va == -1) ss[a] -= get(a, x) * 2 - d[x];
  add(a, x, va);
  if (va == 1) ss[a] += get(a, x) * 2 - d[x];
}
int main() {
  scanf("%d%d%d%d", &n, &m, &q, &cc);
  C = cc;
  for (int i = 1, E = n; i <= E; i++) scanf("%d", &f[i]);
  for (int i = 2, E = n; i <= E; i++)
    scanf("%d", &p[i]), ne[i] = la[p[i]], la[p[i]] = i;
  for (int i = 1, E = m; i <= E; i++) scanf("%d", &cc), c[i] = cc;
  dfs(1);
  df2(1, 1);
  for (int i = 1, E = n; i <= E; i++) ch(f[i], i, 1);
  for (int t = 1, E = q; t <= E; t++) {
    scanf("%d%d", &op, &x);
    if (op == 1) {
      scanf("%d", &W);
      ch(f[x], x, -1);
      ch(f[x] = W, x, 1);
    } else
      cout << setprecision(20)
           << (long double)(ss[x] * c[x] * c[x] - 2 * C * s[x] * c[x] +
                            C * C * n) /
                  (long double)n
           << endl;
  }
}
