#include <bits/stdc++.h>
using namespace std;
inline void end() {
  puts("");
  system("pause");
}
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return x * f;
}
const int N = 3e4 + 4, M = 5e5 + 5;
int n, m, g, s, t, ans;
int first[N], nex[M], to[M], w[M], num = 1;
inline void add(int u, int v, int val) {
  nex[++num] = first[u];
  first[u] = num;
  to[num] = v;
  w[num] = val;
}
inline void Add(int u, int v, int val) {
  add(u, v, val);
  add(v, u, 0);
}
namespace ISAP {
int dep[N], gap[N], cur[N];
void bfs() {
  memset(dep, -1, sizeof(dep));
  memset(gap, 0, sizeof(gap));
  queue<int> q;
  q.push(t);
  dep[t] = 0;
  gap[0] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = first[u]; i; i = nex[i]) {
      int v = to[i];
      if (dep[v] != -1) continue;
      dep[v] = dep[u] + 1;
      gap[dep[v]]++;
      q.push(v);
    }
  }
}
inline int dfs(int u, int in) {
  if (u == t) return in;
  int out = 0;
  for (int i = cur[u]; i; i = nex[i]) {
    cur[u] = i;
    int v = to[i];
    if (!w[i] || dep[v] != dep[u] - 1) continue;
    int res = dfs(v, min(w[i], in - out));
    w[i] -= res;
    w[i ^ 1] += res;
    out += res;
    if (in == out) return out;
  }
  gap[dep[u]]--;
  if (!gap[dep[u]]) dep[s] = n + m + m + 3;
  dep[u]++;
  gap[dep[u]]++;
  return out;
}
void work() {
  bfs();
  while (dep[s] < n + m + m + 2) {
    memcpy(cur, first, sizeof(first));
    ans -= dfs(s, 1e9);
  }
}
}  // namespace ISAP
int kind[N];
int main() {
  n = read(), m = read(), g = read();
  s = 0, t = n + m + m + 1;
  for (int i = 1; i <= n; ++i) kind[i] = read();
  for (int i = 1; i <= n; ++i) {
    int x = read();
    if (kind[i])
      Add(i + m, t, x), Add(s, i + m, 0);
    else
      Add(i + m, t, 0), Add(s, i + m, x);
  }
  for (int i = 1; i <= m; ++i) {
    int kk = read(), val = read(), siz = read();
    ans += val;
    if (kk)
      Add(i + n + m, t, val), Add(s, i, 0);
    else
      Add(s, i, val), Add(i + n + m, t, 0);
    while (siz--) {
      int x = read();
      Add(i, x + m, 1e9);
      Add(x + m, i + m + n, 1e9);
    }
    int kkk = read();
    if (kkk) {
      if (kk)
        Add(i + n + m, t, g);
      else
        Add(s, i, g);
    }
  }
  ISAP::work();
  printf("%d", ans);
  return 0;
}
