#include <bits/stdc++.h>
using namespace std;
struct timer {
  time_t start;
  timer() { start = clock(); }
  ~timer() {
    cerr << 1. * (clock() - start) / CLOCKS_PER_SEC << " secs" << endl;
  }
};
const int MN = 100010;
struct dinic {
  struct edge {
    int to, rev;
    long long cap;
    edge(int to, long long cap, int rev) : to(to), cap(cap), rev(rev) {}
  };
  vector<edge> G[MN];
  long long level[MN];
  int iter[MN];
  void init(int N) {
    for (int i = 0; i < (N); i++) G[i].clear();
  }
  void add_edge(int from, int to, long long cap) {
    G[from].push_back(edge(to, cap, ((int)(G[to]).size())));
    G[to].push_back(edge(from, 0, ((int)(G[from]).size()) - 1));
  }
  void bfs(int s) {
    memset(level, -1, sizeof(level));
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while (!que.empty()) {
      int v = que.front();
      que.pop();
      for (int i = 0; i < (((int)(G[v]).size())); i++) {
        edge &e = G[v][i];
        if (e.cap > 0 && level[e.to] < 0) {
          level[e.to] = level[v] + 1;
          que.push(e.to);
        }
      }
    }
  }
  long long dfs(int v, int t, long long f) {
    if (v == t) return f;
    for (int &i = iter[v]; i < ((int)(G[v]).size()); i++) {
      edge &e = G[v][i];
      if (e.cap > 0 && level[v] < level[e.to]) {
        long long d = dfs(e.to, t, min(f, e.cap));
        if (d > 0) {
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }
  int max_flow(int s, int t) {
    long long flow = 0;
    for (;;) {
      bfs(s);
      if (level[t] < 0) return flow;
      memset(iter, 0, sizeof(iter));
      int f;
      while ((f = dfs(s, t, 1070000000LL * 1070000000LL)) > 0) {
        flow += f;
      }
    }
  }
};
int n, m, g, s[10010], v[10010];
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  dinic D;
  cin >> n >> m >> g;
  int S = n + m, T = S + 1;
  for (int i = 0; i < (n); i++) cin >> s[i];
  for (int i = 0; i < (n); i++) {
    cin >> v[i];
    if (s[i] == 0) {
      D.add_edge(S, i, v[i]);
    } else {
      D.add_edge(i, T, v[i]);
    }
  }
  long long ans = 0;
  for (int i = 0; i < (m); i++) {
    int a, w, k, f;
    cin >> a >> w >> k;
    ans += w;
    for (int j = 0; j < (k); j++) {
      int d;
      cin >> d;
      d--;
      if (a == 0) {
        D.add_edge(n + i, d, 1070000000LL);
      } else {
        D.add_edge(d, n + i, 1070000000LL);
      }
    }
    cin >> f;
    if (f == 1) w += g;
    if (a == 0) {
      D.add_edge(S, n + i, w);
    } else {
      D.add_edge(n + i, T, w);
    }
  }
  cout << ans - D.max_flow(S, T);
}
