#include <bits/stdc++.h>
using namespace std;
char RR[30000005], *S = RR;
inline int read() {
  int p = 0, w = 1;
  char c = *S++;
  while (c > '9' || c < '0') {
    if (c == '-') w = -1;
    c = *S++;
  }
  while (c >= '0' && c <= '9') {
    p = p * 10 + c - '0';
    c = *S++;
  }
  return p * w;
}
inline int min(int a, int b) { return (a < b) ? a : b; }
int n, m, s, t, g, cnt = 1;
int col[200050], pay[200050];
int lev[200050], cap[200050], cur[200050], q[200050];
int nxt[200050], res[200050], node[200050], mark[200050];
inline void Unicom(int u, int v, int w) {
  nxt[++cnt] = cap[u];
  cap[u] = cnt;
  node[cnt] = v;
  res[cnt] = w;
  nxt[++cnt] = cap[v];
  cap[v] = cnt;
  node[cnt] = u;
  res[cnt] = 0;
}
inline void Bfs() {
  ++mark[1];
  for (register int i = 1; i <= t; i++) cur[i] = cap[i];
  int fr = 1, to = 2;
  q[fr] = t;
  lev[t] = 1;
  while (fr <= to) {
    int e = q[fr++];
    for (register int i = cap[e]; i; i = nxt[i]) {
      int d = node[i];
      if (lev[d] || !res[i ^ 1]) continue;
      lev[d] = lev[e] + 1;
      ++mark[lev[d]];
      q[++to] = d;
    }
  }
}
inline int Dfs(int e, int ff) {
  int tmp, tt = 0;
  if (e == t) return ff;
  for (int &i = cur[e]; i; i = nxt[i]) {
    int d = node[i];
    if (lev[e] != lev[d] + 1) continue;
    tmp = Dfs(d, min(ff, res[i]));
    tt += tmp;
    ff -= tmp;
    res[i] -= tmp;
    res[i ^ 1] += tmp;
    if (!ff) return tt;
  }
  if (!(--mark[lev[e]])) lev[s] = t + 1;
  ++mark[++lev[e]];
  cur[e] = cap[e];
  return tt;
}
inline int ISAP() {
  Bfs();
  int ans = Dfs(s, 1e9);
  while (lev[s] <= t) ans += Dfs(s, 1e9);
  return ans;
}
int main() {
  fread(RR, 1, sizeof(RR), stdin);
  n = read();
  m = read();
  g = read();
  for (register int i = 1; i <= n; i++) col[i] = read();
  s = n + m + 1;
  t = s + 1;
  for (register int i = 1; i <= n; i++) {
    pay[i] = read();
    if (col[i])
      Unicom(i, t, pay[i]);
    else
      Unicom(s, i, pay[i]);
  }
  int sum = 0;
  for (register int i = 1; i <= m; i++) {
    int pc = read(), pw = read(), num = read();
    sum += pw;
    for (register int j = 1; j <= num; j++) {
      int x = read();
      if (pc)
        Unicom(x, i + n, 2000000);
      else
        Unicom(i + n, x, 2000000);
    }
    int pk = read();
    if (pk) pw += g;
    if (pc)
      Unicom(i + n, t, pw);
    else
      Unicom(s, i + n, pw);
  }
  printf("%d\n", sum - ISAP());
  return 0;
}
