#include <bits/stdc++.h>
using namespace std;
const int maxn = 40000 + 10, maxm = 100000 + 10;
const int inf = 1 << 30;
int head[maxn], tot;
int depth[maxn];
queue<int> q;
int n, m, s, t, g;
struct node {
  int lim;
  int to, nxt;
} edg[maxm];
inline void add(int a, int b, int c) {
  edg[tot].to = b;
  edg[tot].nxt = head[a];
  edg[tot].lim = c;
  head[a] = tot++;
}
inline void add_edge(int u, int v, int val) {
  add(u, v, val);
  add(v, u, 0);
}
int dinic_bfs(int s, int t) {
  while (!q.empty()) q.pop();
  memset(depth, 0, sizeof(depth));
  depth[s] = 1;
  q.push(s);
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    for (int i = head[cur]; i != -1; i = edg[i].nxt) {
      if (edg[i].lim && !depth[edg[i].to]) {
        depth[edg[i].to] = depth[cur] + 1;
        q.push(edg[i].to);
      }
    }
  }
  if (depth[t])
    return 1;
  else
    return 0;
}
inline int dinic_dfs(int root, int sum) {
  if (root == t) return sum;
  int k, res = 0;
  for (register int i = head[root]; i != -1 && sum; i = edg[i].nxt) {
    int v = edg[i].to;
    if (edg[i].lim > 0 && (depth[v] == depth[root] + 1)) {
      k = dinic_dfs(v, min(sum, edg[i].lim));
      if (k == 0) depth[v] = 0;
      edg[i].lim -= k;
      edg[i ^ 1].lim += k;
      res += k;
      sum -= k;
    }
  }
  return res;
}
int dinic(int s, int t) {
  int ans = 0, flow;
  while (dinic_bfs(s, t)) {
    do {
      flow = dinic_dfs(s, inf);
      ans += flow;
    } while (flow);
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  memset(head, -1, sizeof(head));
  tot = 0;
  cin >> n >> m >> g;
  s = n + m + 2;
  t = n + m + 1;
  vector<int> ismale(n + 1), v(n + 1);
  for (int i = 1; i <= n; i++) cin >> ismale[i];
  for (int i = 1; i <= n; i++) cin >> v[i];
  for (int i = 1; i <= n; i++) {
    if (ismale[i]) {
      add_edge(s, i, v[i]);
    } else {
      add_edge(i, t, v[i]);
    }
  }
  int sum = 0;
  for (int i = 1; i <= m; i++) {
    int op, w, k, x;
    cin >> op >> w >> k;
    sum += w;
    for (int j = 0; j < k; j++) {
      cin >> x;
      if (op) {
        add_edge(n + i, x, inf);
      } else {
        add_edge(x, n + i, inf);
      }
    }
    cin >> x;
    if (op)
      add_edge(s, n + i, w + x * g);
    else
      add_edge(n + i, t, w + x * g);
  }
  int ans = dinic(s, t);
  cout << sum - ans << "\n";
  return 0;
}
