#include <bits/stdc++.h>
using namespace std;
const int MaxN = 20000;
const int MaxM = MaxN * 20;
const int INF = 0x3f3f3f3f;
struct Node {
  int v, c;
  Node *nxt, *twin;
} * g[MaxN], pool[MaxM], *tail = pool;
int n, m, G, ans, st[MaxN], S, T;
int doge[MaxN][15], d[MaxN], c[MaxN];
inline void make_edge(int u, int v, int c) {
  tail->v = v;
  tail->c = c;
  tail->twin = tail + 1;
  tail->nxt = g[u];
  g[u] = tail++;
  tail->v = u;
  tail->c = 0;
  tail->twin = tail - 1;
  tail->nxt = g[v];
  g[v] = tail++;
}
int bfs() {
  static int q[MaxN], l, r;
  memset(d, 0, sizeof(d));
  for (d[q[l = r = 0] = S] = 1; l <= r; l++)
    for (Node *p = g[q[l]]; p; p = p->nxt)
      if (p->c > 0 && !d[p->v]) d[q[++r] = p->v] = d[q[l]] + 1;
  return d[T];
}
int dfs(int u, int fl) {
  int dt = fl;
  if (u == T) return fl;
  for (Node *p = g[u]; p; p = p->nxt)
    if (p->c > 0 && d[p->v] == d[u] + 1) {
      int tmp = dfs(p->v, min(fl, p->c));
      fl -= tmp, p->c -= tmp, p->twin->c += tmp;
      if (!fl) break;
    }
  return dt - fl;
}
int dinic() {
  int res = 0;
  while (bfs()) res += dfs(S, INF);
  return res;
}
int check(int a, int b) {
  for (int i = 1; i <= doge[a][0]; i++)
    for (int j = 1; j <= doge[b][0]; j++)
      if (doge[a][i] == doge[b][j]) return 1;
  return 0;
}
int main() {
  scanf("%d%d%d", &n, &m, &G);
  S = 0, T = n + m + 1;
  for (int i = 1; i <= n; i++) scanf("%d", &st[i]);
  for (int i = 1, c = 0; i <= n; i++)
    scanf("%d", &c), (st[i] ? make_edge(i, T, c) : make_edge(S, i, c));
  for (int i = 1; i <= m; i++) {
    int w, k, f;
    scanf("%d%d%d", &c[i], &w, &k);
    doge[i][0] = k;
    for (int j = 1; j <= k; j++) scanf("%d", &doge[i][j]);
    scanf("%d", &f);
    ans += w;
    f ? w += G : 0;
    c[i] ? make_edge(i + n, T, w) : make_edge(S, i + n, w);
    for (int j = 1; j <= k; j++)
      if (st[doge[i][j]] != c[i])
        c[i] ? make_edge(doge[i][j], i + n, INF)
             : make_edge(i + n, doge[i][j], INF);
  }
  for (int i = 1; i <= m; i++)
    if (!c[i])
      for (int j = 1; j <= m; j++)
        if (c[j] && check(i, j)) make_edge(i + n, j + n, INF);
  printf("%d\n", ans - dinic());
  return 0;
}
