#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T& x) {
  bool fu = 0;
  char c;
  for (c = getchar(); c <= 32; c = getchar())
    ;
  if (c == '-') fu = 1, c = getchar();
  for (x = 0; c > 32; c = getchar()) x = x * 10 + c - '0';
  if (fu) x = -x;
};
char getc() {
  char c;
  for (c = getchar(); c <= 32; c = getchar())
    ;
  return c;
}
const int V = 100010;
const int E = 500010;
const int inf = 2000000000;
int n, m, g, x, v[V], z[V], w, k, y, p, o;
long long ans;
int S, T, N, edge, e[E], b[E], c[E], fir[V], last[V];
void clear() {
  edge = 0;
  memset(fir, -1, sizeof(fir));
  memset(b, -1, sizeof(b));
}
void add2(int x, int y, int z) {
  e[edge] = y;
  c[edge] = z;
  if (fir[x] == -1)
    fir[x] = edge;
  else
    b[last[x]] = edge;
  last[x] = edge++;
}
void add(int x, int y, int z) {
  add2(x, y, z);
  add2(y, x, 0);
}
int vh[V], h[V], cur[V], pre[V];
long long sap() {
  int i, j, k, l, p, flow, minh;
  long long ans = 0;
  memset(h, 0, sizeof(h));
  memset(vh, 0, sizeof(vh));
  vh[0] = N;
  memcpy(cur, fir, sizeof(fir));
  memset(pre, 0, sizeof(pre));
  pre[S] = S;
  for (i = S; h[S] < N;) {
    if (i == T) {
      flow = inf;
      for (p = S; p != T; p = e[cur[p]]) flow = min(flow, c[cur[p]]);
      ans += flow;
      for (p = S; p != T; p = e[cur[p]])
        c[cur[p]] -= flow, c[cur[p] ^ 1] += flow;
      i = S;
    }
    for (k = cur[i]; k >= 0; k = b[k])
      if (c[k] && h[e[k]] + 1 == h[i]) {
        cur[i] = k;
        pre[e[k]] = i;
        i = e[k];
        break;
      }
    if (k < 0) {
      if (--vh[h[i]] == 0) break;
      cur[i] = fir[i];
      minh = N;
      for (k = cur[i]; k >= 0; k = b[k])
        if (c[k]) minh = min(minh, h[e[k]] + 1);
      ++vh[h[i] = minh];
      i = pre[i];
    }
  }
  return ans;
}
int main() {
  read(n);
  read(m);
  read(g);
  int i, j;
  S = n + m + 1;
  T = n + m + 2;
  N = T;
  clear();
  for (i = 1; i <= n; i++) read(z[i]);
  for (i = 1; i <= n; i++) read(v[i]);
  for (i = 1; i <= n; i++)
    if (z[i] == 0)
      add(S, i, v[i]);
    else
      add(i, T, v[i]);
  for (i = 1; i <= m; i++) {
    read(o);
    read(w);
    ans += w;
    read(k);
    for (j = 1; j <= k; j++) {
      read(x);
      if (o == 0)
        add(n + i, x, inf);
      else
        add(x, n + i, inf);
    }
    read(p);
    if (p == 1) w += g;
    if (o == 0)
      add(S, n + i, w);
    else
      add(n + i, T, w);
  }
  long long tmp = sap();
  cout << ans - tmp << endl;
  scanf("\n");
  return 0;
}
