#include <bits/stdc++.h>
using std::queue;
namespace G {
struct Edge {
  int to, cap, nxt;
} e[500000 * 5];
int head[500000 * 3], cnt;
inline void Init() { memset(head, -1, sizeof(head)), cnt = -1; }
inline void AddEdge(int u, int v, int w) {
  e[++cnt] = (Edge){v, w, head[u]}, head[u] = cnt;
  e[++cnt] = (Edge){u, 0, head[v]}, head[v] = cnt;
}
int d[500000 * 3];
bool BFS(int s, int t) {
  queue<int> q;
  q.push(s);
  memset(d, 0, sizeof(d));
  d[s] = 1;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = head[x]; ~i; i = e[i].nxt)
      if (e[i].cap > 0 && d[e[i].to] == 0)
        d[e[i].to] = d[x] + 1, q.push(e[i].to);
  }
  return d[t];
}
int DFS(int t, int n, int now) {
  if (n == t) return now;
  int ret = 0;
  for (int i = head[n]; ~i; i = e[i].nxt)
    if (d[e[i].to] == d[n] + 1 && e[i].cap) {
      int di = DFS(t, e[i].to,
                   ((e[i].cap) < (now - ret) ? (e[i].cap) : (now - ret)));
      if (di) {
        e[i].cap -= di, e[i ^ 1].cap += di, ret += di;
        if (ret == now) break;
      }
    }
  return ret;
}
inline int Dinic(int s, int t) {
  int ret = 0;
  while (BFS(s, t)) ret += DFS(t, s, 1 << 30);
  return ret;
}
}  // namespace G
const int S = 500000 - 2, T = 500000 - 1;
int f[500000 + 10];
int main() {
  G::Init();
  int n, m, g;
  scanf("%d%d%d", &n, &m, &g);
  for (int i = 1; i <= n; i++) scanf("%d", &f[i]);
  for (int i = 1; i <= n; i++) {
    int t;
    scanf("%d", &t);
    if (!f[i])
      G::AddEdge(S, i, t);
    else
      G::AddEdge(i, T, t);
  }
  int sum = 0;
  for (int i = 1; i <= m; i++) {
    int ff, w, k;
    scanf("%d%d%d", &ff, &w, &k);
    if (ff) {
      for (int j = 1; j <= k; j++) {
        int t;
        scanf("%d", &t);
        G::AddEdge(t, i + n, 1 << 30);
      }
      scanf("%d", &k);
      if (k)
        G::AddEdge(i + n, T, g + w);
      else
        G::AddEdge(i + n, T, w);
      sum += w;
    } else {
      for (int j = 1; j <= k; j++) {
        int t;
        scanf("%d", &t);
        G::AddEdge(i + n, t, 1 << 30);
      }
      scanf("%d", &k);
      if (k)
        G::AddEdge(S, i + n, g + w);
      else
        G::AddEdge(S, i + n, w);
      sum += w;
    }
  }
  printf("%d\n", sum - G::Dinic(S, T));
  return 0;
}
