#include <bits/stdc++.h>
using namespace std;
int gi() {
  int x = 0, w = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') w = 0, ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return w ? x : -x;
}
const int N = 15000;
const int inf = 1e9;
struct edge {
  int to, nxt, w;
} a[N * 10];
int n, m, g, sex[N], S, T, head[N], cnt = 1, dep[N], cur[N], ans;
queue<int> Q;
void link(int u, int v, int w) {
  a[++cnt] = (edge){v, head[u], w};
  head[u] = cnt;
  a[++cnt] = (edge){u, head[v], 0};
  head[v] = cnt;
}
bool bfs() {
  memset(dep, 0, sizeof(dep));
  dep[S] = 1;
  Q.push(S);
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int e = head[u]; e; e = a[e].nxt)
      if (a[e].w && !dep[a[e].to]) dep[a[e].to] = dep[u] + 1, Q.push(a[e].to);
  }
  return dep[T];
}
int dfs(int u, int f) {
  if (u == T) return f;
  for (int &e = cur[u]; e; e = a[e].nxt)
    if (a[e].w && dep[a[e].to] == dep[u] + 1) {
      int tmp = dfs(a[e].to, min(a[e].w, f));
      if (tmp) {
        a[e].w -= tmp;
        a[e ^ 1].w += tmp;
        return tmp;
      }
    }
  return 0;
}
int Dinic() {
  int res = 0;
  while (bfs()) {
    for (int i = 1; i <= T; ++i) cur[i] = head[i];
    while (int tmp = dfs(S, inf)) res += tmp;
  }
  return res;
}
int main() {
  n = gi();
  m = gi();
  g = gi();
  S = n + m + 1;
  T = S + 1;
  for (int i = 1; i <= n; ++i) sex[i] = gi();
  for (int i = 1; i <= n; ++i) {
    int x = gi();
    sex[i] ? link(i, T, x) : link(S, i, x);
  }
  for (int i = 1; i <= m; ++i) {
    int v = gi(), w = gi(), k = gi();
    ans += w;
    while (k--) {
      int x = gi();
      v ? link(x, i + n, inf) : link(i + n, x, inf);
    }
    int gg = gi();
    w += g * gg;
    v ? link(i + n, T, w) : link(S, i + n, w);
  }
  printf("%d\n", ans - Dinic());
  return 0;
}
