#include <bits/stdc++.h>
using namespace std;
const int MAXN = 111111;
const int oo = 0X1FFFFFFF;
int PP = 1000000009;
const long double PI = 3.141592653589793;
template <typename TT>
void read(TT &x) {
  char ch;
  for (ch = getchar(); ch > '9' || ch < '0'; ch = getchar())
    ;
  for (x = 0; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - 48;
}
struct edge {
  int c, v;
  edge *n, *op;
} * hd[MAXN], epool[400000];
int ent;
void addedge(int u, int v, int c) {
  edge *p = &epool[ent++], *q = &epool[ent++];
  p->n = hd[u];
  p->v = v;
  p->c = c;
  hd[u] = p;
  q->n = hd[v];
  q->v = u;
  q->c = 0;
  hd[v] = q;
  p->op = q;
  q->op = p;
}
int N, S, T;
int dis[MAXN], Q[MAXN], qnt;
int flow;
bool label(int S, int T) {
  fill(dis, dis + N + 1, -1);
  dis[Q[qnt = 0] = T] = 0;
  for (int i = 0; i <= qnt; i++) {
    int u = Q[i];
    for (edge *p = hd[u]; p != NULL; p = p->n)
      if (p->op->c > 0 && dis[p->v] == -1) {
        dis[Q[++qnt] = p->v] = dis[u] + 1;
      }
  }
  return (dis[S] != -1);
}
int aug(int u, int now) {
  if (u == T) return now;
  int lim = now;
  for (edge *p = hd[u]; p != NULL; p = p->n)
    if (p->c > 0) {
      int v = p->v;
      if (dis[u] == dis[v] + 1 && lim) {
        int push = aug(v, min(lim, p->c));
        lim -= push;
        p->c -= push;
        p->op->c += push;
        if (!lim) break;
      }
    }
  return now - lim;
}
void dinic() {
  flow = 0;
  for (; label(S, T);) flow += aug(S, oo);
}
int n, m, g, b[111111];
void Init() {
  {
    read(n);
    read(m);
    read(g);
  };
  S = n + m, T = S + 1, N = T + 1;
  for (int i = 0; i < N; i++) hd[i] = NULL;
  for (int i = 0; i < n; i++) read(b[i]);
  for (int i = 0; i < n; i++) {
    int v;
    read(v);
    if (b[i])
      addedge(i, T, v);
    else
      addedge(S, i, v);
  }
  int ans = 0;
  for (int i = 0; i < m; i++) {
    int w, t, bb, gg;
    {
      read(bb);
      read(w);
      read(t);
    };
    ans += w;
    for (int j = 0; j < t; j++) read(b[j]);
    read(gg);
    if (bb) {
      addedge(i + n, T, w + (gg ? g : 0));
      for (int j = 0; j < t; j++) addedge(b[j] - 1, i + n, oo);
    } else {
      addedge(S, i + n, w + (gg ? g : 0));
      for (int j = 0; j < t; j++) addedge(i + n, b[j] - 1, oo);
    }
  }
  dinic();
  cout << ans - flow;
}
int main() { Init(); }
