#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
using namespace std;
namespace ywy {
inline int get() {
  int n = 0;
  char c;
  while ((c = getchar()) || 23333) {
    if (c >= '0' && c <= '9') break;
    if (c == '-') goto s;
  }
  n = c - '0';
  while ((c = getchar()) || 23333) {
    if (c >= '0' && c <= '9')
      n = n * 10 + c - '0';
    else
      return (n);
  }
s:
  while ((c = getchar()) || 23333) {
    if (c >= '0' && c <= '9')
      n = n * 10 - c + '0';
    else
      return (n);
  }
}
typedef struct _b {
  int dest;
  int nxt;
  int c;
} bian;
bian memchi[1000001];
int gn = 2, heads[30001], id[30001], que[30001];
inline void add(int s, int t, int c) {
  memchi[gn].dest = t;
  memchi[gn].nxt = heads[s];
  memchi[gn].c = c;
  heads[s] = gn;
  gn++;
}
int s, t;
inline int bfs() {
  int head = 0, tail = 1;
  que[0] = t;
  memset(id, 0, sizeof(id));
  id[t] = 1;
  do {
    int me = que[head];
    head++;
    for (register int i = heads[me]; i; i = memchi[i].nxt) {
      if (!memchi[i ^ 1].c || id[memchi[i].dest]) continue;
      id[memchi[i].dest] = id[me] + 1;
      if (memchi[i].dest == s) return (1);
      que[tail] = memchi[i].dest;
      tail++;
    }
  } while (head < tail);
  return (0);
}
int dfs(int pt, int flow) {
  if (pt == t) return (flow);
  int rest = flow;
  for (register int i = heads[pt]; i && rest; i = memchi[i].nxt) {
    if (!memchi[i].c || id[memchi[i].dest] != id[pt] - 1) continue;
    int cjr = dfs(memchi[i].dest, min(rest, memchi[i].c));
    if (!cjr) id[memchi[i].dest] = 0;
    rest -= cjr;
    memchi[i].c -= cjr;
    memchi[i ^ 1].c += cjr;
  }
  return (flow - rest);
}
int ints[100001];
void ywymain() {
  int n = get(), m = get(), g = get();
  int gpt = n + 1;
  s = gpt;
  gpt++;
  t = gpt;
  gpt++;
  for (register int i = 1; i <= n; i++) ints[i] = get();
  for (register int i = 1; i <= n; i++) {
    int v = get();
    if (!ints[i])
      add(s, i, v), add(i, s, 0);
    else
      add(i, t, v), add(t, i, 0);
  }
  int ans = 0;
  while (m) {
    m--;
    int x = get(), val = get(), k = get();
    ans += val;
    int me = gpt;
    gpt++;
    while (k) {
      k--;
      int a = get();
      if (x)
        add(a, me, 1234567890), add(me, a, 0);
      else
        add(me, a, 1234567890), add(a, me, 0);
    }
    int lose = g * get();
    if (x)
      add(me, t, lose + val), add(t, me, 0);
    else
      add(s, me, lose + val), add(me, s, 0);
  }
  while (bfs()) {
    while (1) {
      int cjr = dfs(s, 1234567890);
      if (!cjr) break;
      ans -= cjr;
    }
  }
  cout << ans << endl;
}
}  // namespace ywy
int main() {
  ywy::ywymain();
  return (0);
}
