#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
struct flows {
  struct node {
    int to, next, flow;
  } e[20010 * 40];
  int tot, st[20010], dis[20010], cur[20010];
  void init() { tot = -1, memset(e, -1, sizeof e), memset(st, -1, sizeof st); }
  void add(int x, int y, int z) {
    e[++tot].to = y;
    e[tot].flow = z;
    e[tot].next = st[x];
    st[x] = tot;
  }
  void add_edge(int x, int y, int z) { add(x, y, z), add(y, x, 0); }
  queue<int> que;
  int bfs(int S, int T) {
    memcpy(cur, st, sizeof st);
    memset(dis, 0, sizeof dis);
    while (!que.empty()) que.pop();
    que.push(S);
    dis[S] = 1;
    while (!que.empty()) {
      int now = que.front();
      que.pop();
      for (int i = st[now]; ~i; i = e[i].next)
        if (e[i].flow && !dis[e[i].to]) {
          dis[e[i].to] = dis[now] + 1;
          if (e[i].to == T) return 1;
          que.push(e[i].to);
        }
    }
    return 0;
  }
  int finds(int now, int T, int flow) {
    if (now == T) return flow;
    int f;
    for (int i = cur[now]; ~i; i = e[i].next) {
      cur[now] = i;
      if (e[i].flow && dis[e[i].to] == dis[now] + 1 &&
          (f = finds(e[i].to, T, min(flow, e[i].flow)))) {
        e[i].flow -= f;
        e[i ^ 1].flow += f;
        return f;
      }
    }
    return 0;
  }
  int dinic(int S, int T) {
    int flow = 0, x;
    while (bfs(S, T)) {
      while (x = finds(S, T, inf)) {
        flow += x;
      }
    }
    return flow;
  }
} flow;
int n, m, g, v, w, t, id, ans, x, sex[20010], want[20010];
vector<int> ins[20010];
int main() {
  scanf("%d%d%d", &n, &m, &g);
  int S = 0, T = n + m + 1;
  flow.init();
  for (int i = 1; i <= n; ++i) scanf("%d", &sex[i]);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &v);
    if (sex[i])
      flow.add_edge(i, T, v);
    else
      flow.add_edge(S, i, v);
  }
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%d", &want[i], &w, &t);
    for (int j = 1; j <= t; ++j) {
      scanf("%d", &id);
      if (sex[id] ^ want[i])
        if (want[i])
          flow.add_edge(id, n + i, inf);
        else
          flow.add_edge(n + i, id, inf);
      ins[id].push_back(i);
    }
    ans += w;
    scanf("%d", &x);
    if (x) w += g;
    if (want[i])
      flow.add_edge(n + i, T, w);
    else
      flow.add_edge(S, n + i, w);
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j < ins[i].size(); ++j)
      for (int k = j + 1; k < ins[i].size(); ++k)
        if (want[ins[i][j]] ^ want[ins[i][k]])
          if (want[ins[i][j]])
            flow.add_edge(n + ins[i][k], n + ins[i][j], inf);
          else
            flow.add_edge(n + ins[i][j], n + ins[i][k], inf);
  printf("%d", ans - flow.dinic(S, T));
}
