#include <bits/stdc++.h>
using namespace std;
inline char getch() {
  static char buf[10000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 10000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline long long read() {
  long long s = 0, f = 1;
  char ch = getch();
  while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getch();
  while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getch();
  return s * f;
}
void File() {
  freopen(
      "filename"
      ".in",
      "r", stdin);
  freopen(
      "filename"
      ".out",
      "w", stdout);
}
const int MaxN = 100000;
const int MaxM = 1000000;
const int inf = 1 << 30;
struct Edge {
  int to, nxt, flow;
};
Edge e[MaxM << 1];
int h[MaxN], cnt = 1;
void Add_Edge(int x, int y, int z) {
  e[++cnt] = (Edge){y, h[x], z};
  h[x] = cnt;
  e[++cnt] = (Edge){x, h[y], 0};
  h[y] = cnt;
}
int dep[MaxN];
bool BFS(int S, int T) {
  memset(dep, 0, sizeof(dep));
  dep[S] = 1;
  queue<int> q;
  q.push(S);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = h[x]; i; i = e[i].nxt) {
      int y = e[i].to;
      if (dep[y] || !e[i].flow) continue;
      dep[y] = dep[x] + 1;
      q.push(y);
      if (y == T) return true;
    }
  }
  return false;
}
int DFS(int x, int flow, int T) {
  if (x == T) return flow;
  int res = 0;
  for (int i = h[x]; i && flow; i = e[i].nxt) {
    int y = e[i].to;
    if (dep[y] != dep[x] + 1 || !e[i].flow) continue;
    int k = DFS(y, min(flow, e[i].flow), T);
    e[i].flow -= k;
    e[i ^ 1].flow += k;
    flow -= k;
    res += k;
  }
  return res;
}
int Maxflow(int S, int T) {
  int maxf = 0, d = 0;
  while (BFS(S, T)) {
    while ((d = DFS(S, inf, T)) != 0) maxf += d;
  }
  return maxf;
}
const int N = 1e4 + 5;
int n, m, g, a[N], V[N], p[N], res;
int main() {
  n = read(), m = read(), g = read();
  int S = 0, T = n + m + 1;
  for (int i = 1; i <= n; i++) a[i] = read();
  for (int i = 1; i <= n; i++) V[i] = read();
  for (int i = 1; i <= n; i++) {
    if (a[i] == 1) {
      Add_Edge(S, i, V[i]);
      Add_Edge(i, T, 0);
    } else {
      Add_Edge(S, i, 0);
      Add_Edge(i, T, V[i]);
    }
  }
  for (int i = 1; i <= m; i++) {
    int t = read(), W = read(), k = read(), d;
    for (int j = 1; j <= k; j++) p[j] = read();
    d = read();
    if (t == 1)
      Add_Edge(S, i + n, W + (d ? g : 0));
    else
      Add_Edge(i + n, T, W + (d ? g : 0));
    for (int j = 1; j <= k; j++) {
      if (t == 1)
        Add_Edge(i + n, p[j], inf);
      else
        Add_Edge(p[j], i + n, inf);
    }
    res += W;
  }
  printf("%d\n", res - Maxflow(S, T));
  return 0;
}
