#include <bits/stdc++.h>
using namespace std;
const int N = 3 * 10000;
const int M = 10 * N;
const long long INF1 = N * N;
const long long INF = 10 * N * INF1;
struct edge {
  int v, to;
  long long u, f;
  edge(int v1 = 0, int to1 = 0, long long u1 = 0, long long f1 = 0)
      : v(v1), u(u1), to(to1), f(f1) {}
};
struct dinic {
  int so, si, n;
  int tope;
  vector<int>* graph;
  edge* e;
  int* po;
  int* d;
  queue<int> qu;
  dinic() {
    tope = 0;
    e = new edge[M];
    graph = new vector<int>[N];
    po = new int[N];
    d = new int[N];
  }
  void add_edge(int v, int to, long long u) {
    e[tope] = edge(v, to, u, 0);
    graph[v].push_back(tope++);
    e[tope] = edge(to, v, 0, 0);
    graph[to].push_back(tope++);
  }
  bool bfs() {
    for (int i = 0; i < n; ++i) d[i] = -1;
    d[so] = 0;
    qu.push(so);
    while (!qu.empty()) {
      int v = qu.front();
      qu.pop();
      for (int j = 0; j < (int)graph[v].size(); ++j) {
        int in = graph[v][j];
        if (e[in].u > e[in].f && d[e[in].to] == -1) {
          d[e[in].to] = d[v] + 1;
          qu.push(e[in].to);
        }
      }
    }
    return (d[si] == -1) ? 0 : 1;
  }
  long long dfs(int v, long long U) {
    if (U <= 0) return -1;
    if (v == si) return U;
    for (; po[v] < (int)graph[v].size(); ++po[v]) {
      int in = graph[v][po[v]];
      if (e[in].u > e[in].f && d[e[in].to] == d[e[in].v] + 1) {
        long long f = dfs(e[in].to, min(U, e[in].u - e[in].f));
        if (f > 0) {
          e[in].f += f;
          e[in ^ 1].f -= f;
          return f;
        }
      }
    }
    return -1;
  }
  long long flow() {
    long long ans = 0;
    while (bfs()) {
      for (int i = 0; i < n; ++i) po[i] = 0;
      while (1) {
        long long f = dfs(so, INF);
        if (f <= 0) break;
        ans += f;
      }
    }
    return ans;
  }
};
dinic F;
bool ty[N];
int ind[N];
int main() {
  ios_base::sync_with_stdio(0);
  int n, m, g;
  cin >> n >> m >> g;
  long long res = n * INF1;
  F.so = 0;
  F.si = 2 * n + m + 1;
  F.n = F.si + 1;
  for (int i = 1; i <= n; ++i) cin >> ty[i];
  for (int i = 1; i <= n; ++i) {
    int val;
    cin >> val;
    F.add_edge(i, n + i, INF);
    if (ty[i] == 0) {
      F.add_edge(F.so, i, INF1 + 0);
      F.add_edge(n + i, F.si, INF1 + val);
    } else {
      F.add_edge(F.so, i, INF1 + val);
      F.add_edge(n + i, F.si, INF1 + 0);
    }
  }
  for (int i = 1; i <= m; ++i) {
    bool ty;
    int val;
    int k;
    cin >> ty >> val >> k;
    res += val;
    for (int j = 1; j <= k; ++j) cin >> ind[j];
    int fri;
    cin >> fri;
    if (ty == 0)
      F.add_edge(2 * n + i, F.si, val + fri * g);
    else
      F.add_edge(F.so, 2 * n + i, val + fri * g);
    for (int j = 1; j <= k; ++j) {
      if (ty == 0)
        F.add_edge(ind[j], 2 * n + i, INF);
      else
        F.add_edge(2 * n + i, n + ind[j], INF);
    }
  }
  res -= F.flow();
  cout << res << endl;
  return 0;
}
