#include <bits/stdc++.h>
using namespace std;
const long long N = (1e5 + 9 + 2000 + 2) * 2, M = (N + 1e4), INF = 1e9;
long long n, m, g, S, T, tot = -1, sum;
long long h[N], dis[N], cur[N], ver[M], nxt[M], f[M];
long long Q[N], hh, tt, a[N];
inline void add(long long x, long long y, long long z) {
  ver[++tot] = y, nxt[tot] = h[x], h[x] = tot, f[tot] = z;
  ver[++tot] = x, nxt[tot] = h[y], h[y] = tot, f[tot] = 0;
}
inline bool bfs() {
  memset(dis, -1, sizeof dis);
  hh = tt = 0;
  Q[0] = S, dis[S] = 0, cur[S] = h[S];
  while (hh <= tt) {
    long long u = Q[hh++];
    for (long long i = h[u]; ~i; i = nxt[i]) {
      long long v = ver[i];
      if (dis[v] == -1 && f[i]) {
        dis[v] = dis[u] + 1;
        cur[v] = h[v];
        if (v == T) return true;
        Q[++tt] = v;
      }
    }
  }
  return false;
}
long long dfs(long long u, long long lim) {
  if (u == T) return lim;
  long long flow = 0;
  for (long long i = cur[u]; ~i && flow < lim; i = nxt[i]) {
    long long v = ver[i];
    if (dis[v] == dis[u] + 1 && f[i]) {
      long long t = dfs(v, min(f[i], lim - flow));
      if (!t) dis[v] = -1;
      f[i] -= t, f[i ^ 1] += t, flow += t;
    }
  }
  return flow;
}
long long dinic() {
  long long res = 0;
  while (bfs()) res += dfs(S, INF);
  return res;
}
signed main() {
  memset(h, -1, sizeof h);
  scanf("%lld%lld%lld", &n, &m, &g);
  S = 0, T = n + m + 1;
  for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (long long i = 1; i <= n; i++) {
    long long x;
    scanf("%lld", &x);
    if (a[i] == 0)
      add(S, i, x);
    else
      add(i, T, x);
  }
  for (long long i = 1; i <= m; i++) {
    long long op, w, k, p;
    long long flag;
    scanf("%lld%lld%lld", &op, &w, &k);
    sum += w;
    while (k--) {
      scanf("%lld", &p);
      if (op == 0)
        add(i + n, p, INF);
      else
        add(p, i + n, INF);
    }
    scanf("%lld", &flag);
    if (flag) w += g;
    if (op == 0)
      add(S, i + n, w);
    else
      add(i + n, T, w);
  }
  printf("%lld", sum - dinic());
  return 0;
}
