#include <bits/stdc++.h>
inline int read() {
  int x = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x;
}
namespace Graph {
const int inf = 1073741823;
static const int N = 20010, M = 200010;
int dis[N], pre[N], vis[N], flo[N], que[N * 10];
int tot = 1, fir[N], nex[M], got[M], tak[M], cst[M];
inline void AddEdge(int u, int v, int t, int w = 0) {
  nex[++tot] = fir[u], fir[u] = tot, got[tot] = v, tak[tot] = t, cst[tot] = w;
  nex[++tot] = fir[v], fir[v] = tot, got[tot] = u, tak[tot] = 0, cst[tot] = -w;
}
inline int bfs(int s, int t) {
  for (int i = 1; i <= t; ++i) dis[i] = 0;
  int l = 1, r = 1;
  dis[que[1] = s] = 1;
  while (l <= r) {
    int u = que[l++];
    for (int i = fir[u]; i; i = nex[i]) {
      if (dis[got[i]] || !tak[i]) continue;
      dis[got[i]] = dis[u] + 1, que[++r] = got[i];
    }
  }
  return dis[t];
}
inline int dfs(int u, int t, int flow) {
  int rest = flow;
  if (u == t) return flow;
  for (int i = fir[u]; i && rest; i = nex[i]) {
    if (dis[u] + 1 != dis[got[i]] || !tak[i]) continue;
    int tmp = dfs(got[i], t, std::min(tak[i], rest));
    if (!tmp) dis[got[i]] = 0;
    tak[i] -= tmp, tak[i ^ 1] += tmp, rest -= tmp;
  }
  return flow - rest;
}
inline int Maxflow(int s, int t) {
  int flow = 0;
  while (bfs(s, t)) flow += dfs(s, t, inf);
  return flow;
}
inline int spfa(int s, int t) {
  for (int i = 1; i <= t; i++) dis[i] = inf;
  int l = 1, r = 1;
  dis[s] = 0, flo[s] = inf, que[1] = s;
  while (l <= r) {
    int u = que[l++];
    vis[u] = false;
    for (int i = fir[u]; i; i = nex[i]) {
      int v = got[i], w = cst[i];
      if (!tak[i] || dis[u] + w >= dis[v]) continue;
      dis[v] = dis[u] + w, pre[v] = i;
      flo[v] = std::min(flo[u], tak[i]);
      if (!vis[v]) vis[v] = true, que[++r] = v;
    }
  }
  return dis[t] != inf;
}
inline std::pair<int, int> MincostMaxflow(int s, int t) {
  int cost = 0, flow = 0;
  while (spfa(s, t)) {
    cost += flo[t] * dis[t], flow += flo[t];
    for (int u = t; u != s; u = got[pre[u] ^ 1])
      tak[pre[u]] -= flo[t], tak[pre[u] ^ 1] += flo[t];
  }
  return std::make_pair(flow, cost);
}
}  // namespace Graph
using namespace Graph;
int col[N];
int main() {
  int n = read(), m = read(), g = read();
  int s = n + m + 1, t = n + m + 2, ans = 0;
  for (int i = 1; i <= n; ++i) col[i] = read();
  for (int i = 1; i <= n; ++i)
    col[i] ? AddEdge(i, t, read()) : AddEdge(s, i, read());
  for (int i = 1; i <= m; ++i) {
    int c = read(), w = read(), k = read();
    for (int j = 1; j <= k; ++j)
      c ? AddEdge(read(), i + n, inf) : AddEdge(i + n, read(), inf);
    c ? AddEdge(i + n, t, read() * g + w) : AddEdge(s, i + n, read() * g + w);
    ans += w;
  }
  printf("%d\n", ans - Maxflow(s, t));
  return 0;
}
