#include <bits/stdc++.h>
using namespace std;
int head[15000], ip;
struct Edge {
  int to, next, c;
} edge[3000000];
void add(int u, int v, int c) {
  edge[ip].to = v;
  edge[ip].c = c;
  edge[ip].next = head[u];
  head[u] = ip++;
  edge[ip].to = u;
  edge[ip].c = 0;
  edge[ip].next = head[v];
  head[v] = ip++;
}
int level[15000], que[15000];
bool makelevel(int s, int t) {
  memset(level, 0, sizeof(level));
  int iq = 0, top, to, c;
  que[iq++] = s;
  level[s] = 1;
  for (int i = 0; i < (iq); ++i) {
    top = que[i];
    if (top == t) return 1;
    for (int p = head[top]; p != -1; p = edge[p].next) {
      to = edge[p].to, c = edge[p].c;
      if (!level[to] && c > 0) {
        que[iq++] = to;
        level[to] = level[top] + 1;
      }
    }
  }
  return 0;
}
int dfs(int pos, int maxf, int end) {
  if (pos == end) return maxf;
  int ret = 0, to, c, temp;
  for (int p = head[pos]; p != -1; p = edge[p].next) {
    to = edge[p].to, c = edge[p].c;
    if (c > 0 && level[to] == level[pos] + 1) {
      temp = dfs(to, min(maxf - ret, c), end);
      edge[p].c -= temp;
      edge[p ^ 1].c += temp;
      ret += temp;
      if (ret == maxf) return ret;
    }
  }
  --level[pos];
  return ret;
}
int dinic(int start, int end) {
  int ret = 0;
  while (makelevel(start, end)) ret += dfs(start, 1e9, end);
  return ret;
}
int sex[15000];
int main() {
  int n, m, g, x;
  while (cin >> n >> m >> g) {
    memset(head, -1, sizeof(head));
    ip = 0;
    int start = 0, end = n + m + 1;
    for (int i = (1); i <= (n); ++i) scanf("%d", &sex[i]);
    for (int i = (1); i <= (n); ++i) {
      scanf("%d", &x);
      if (sex[i] == 0)
        add(start, i, x);
      else
        add(i, end, x);
    }
    int ans = 0;
    for (int i = (n + 1); i <= (n + m); ++i) {
      int p, pay, num, flag;
      scanf("%d%d%d", &p, &pay, &num);
      ans += pay;
      while (num--) {
        scanf("%d", &x);
        if (p == 0)
          add(i, x, 1e9);
        else
          add(x, i, 1e9);
      }
      scanf("%d", &flag);
      if (flag) pay += g;
      if (p == 0)
        add(start, i, pay);
      else
        add(i, end, pay);
    }
    cout << ans - dinic(start, end) << endl;
  }
  return 0;
}
