#include <bits/stdc++.h>
using namespace std;
struct edge {
  edge() {}
  edge(int a, int b, int c) : to(a), r(b), next(c) {}
  int next;
  int r;
  int to;
};
class Dinic {
 public:
  void init();
  void add_edge(int x, int y, int re) {
    e[cnt] = edge(y, re, adj[x]);
    adj[x] = cnt;
    cnt++;
    e[cnt] = edge(x, 0, adj[y]);
    adj[y] = cnt;
    cnt++;
  }
  int maxFlow(int s, int t);
  int bfs(int s, int t);
  int dfs(int s, int t, int cf);
  int level[13000];
  int adj[13000];
  struct edge e[13000 * 30];
  int cnt;
};
int gender[10003];
int main() {
  int n, m, g;
  while (cin >> n >> m >> g) {
    int S, T;
    Dinic d;
    int s, w, k, x, sum = 0;
    S = 0, T = n + m + 1;
    d.init();
    for (int i = 1; i <= n; i++) cin >> gender[i];
    for (int i = 1; i <= n; i++) {
      cin >> x;
      if (gender[i])
        d.add_edge(i, T, x);
      else
        d.add_edge(S, i, x);
    }
    for (int i = 1; i <= m; i++) {
      cin >> s >> w >> k;
      sum += w;
      for (int j = 0; j < k; j++) {
        cin >> x;
        if (s)
          d.add_edge(x, n + i, 1e7);
        else
          d.add_edge(n + i, x, 1e7);
      }
      cin >> k;
      if (k) w += g;
      if (s)
        d.add_edge(n + i, T, w);
      else
        d.add_edge(S, n + i, w);
    }
    cout << sum - d.maxFlow(S, T) << endl;
  }
  return 0;
}
void Dinic::init() {
  cnt = 0;
  memset(adj, -1, sizeof(adj));
}
int Dinic::bfs(int s, int t) {
  queue<int> q;
  memset(level, -1, sizeof(level));
  q.push(s);
  level[s] = 0;
  while (!q.empty()) {
    s = q.front();
    q.pop();
    for (int i = adj[s]; i != -1; i = e[i].next) {
      struct edge &y = e[i];
      if (level[y.to] == -1 && y.r > 0) {
        level[y.to] = level[s] + 1;
        q.push(y.to);
      }
    }
  }
  return level[t] != -1;
}
int Dinic::dfs(int s, int t, int cf) {
  if (s == t) return cf;
  int flow = 0;
  for (int i = adj[s]; i != -1; i = e[i].next) {
    struct edge &y = e[i];
    if (level[y.to] > level[s] && y.r > 0) {
      int f = dfs(y.to, t, min(y.r, cf));
      e[i].r -= f;
      e[i ^ 1].r += f;
      flow += f;
      cf -= f;
    }
  }
  return flow;
}
int Dinic::maxFlow(int s, int t) {
  int flow = 0, f;
  while (bfs(s, t)) {
    while (f = dfs(s, t, 1e7)) flow += f;
  }
  return flow;
}
