#include <bits/stdc++.h>
const int N = 15000;
const int M = 105000;
const int inf = 987654321;
int point[N], to[M], liu[M], next[M], cc = 1;
int n, m, p;
int start[N];
int ans = 0;
int dui[N], top, tail, ceng[N];
int s[N];
void add(int x, int y, int z) {
  cc++;
  next[cc] = point[x];
  point[x] = cc;
  to[cc] = y;
  liu[cc] = z;
  cc++;
  next[cc] = point[y];
  point[y] = cc;
  to[cc] = x;
}
void getData() {
  int i;
  int now;
  int a, b, c;
  scanf("%d%d%d", &n, &m, &p);
  for (i = 1; i <= n; i++) scanf("%d", &start[i]);
  for (i = 1; i <= n; i++) {
    scanf("%d", &now);
    if (start[i])
      add(1, i + 2, now);
    else
      add(i + 2, 2, now);
  }
  for (i = 1; i <= m; i++) {
    scanf("%d", &now);
    if (now) {
      scanf("%d%d", &a, &b);
      ans += a;
      while (b--) {
        scanf("%d", &now);
        add(n + i + 2, now + 2, inf);
      }
      scanf("%d", &now);
      if (now) a += p;
      add(1, n + i + 2, a);
    } else {
      scanf("%d%d", &a, &b);
      ans += a;
      while (b--) {
        scanf("%d", &now);
        add(now + 2, n + i + 2, inf);
      }
      scanf("%d", &now);
      if (now) a += p;
      add(n + i + 2, 2, a);
    }
  }
  n = n + m + 2;
}
int Bfs() {
  memset(ceng, 0, sizeof ceng);
  top = 0;
  tail = 1;
  dui[1] = 1;
  ceng[1] = 1;
  while (top < tail) {
    int now = dui[++top];
    int then = point[now];
    while (then) {
      if (liu[then] && !ceng[to[then]]) {
        ceng[to[then]] = ceng[now] + 1;
        dui[++tail] = to[then];
      }
      then = next[then];
    }
  }
  return (ceng[2]);
}
int Dfs(int x, int maxz) {
  if (x == 2) return maxz;
  int last = maxz;
  while (s[x]) {
    if (liu[s[x]] && ceng[x] + 1 == ceng[to[s[x]]]) {
      int has = Dfs(to[s[x]], last < liu[s[x]] ? last : liu[s[x]]);
      last -= has;
      liu[s[x]] -= has;
      liu[s[x] ^ 1] += has;
      if (!last) return maxz;
    }
    s[x] = next[s[x]];
  }
  return (maxz - last);
}
void Do() {
  while (Bfs()) {
    int i;
    for (i = 1; i <= n; i++) s[i] = point[i];
    ans -= Dfs(1, inf);
  }
  printf("%d\n", ans);
}
int main() {
  getData();
  Do();
  return 0;
}
