#include <bits/stdc++.h>
using namespace std;
struct edge {
  int from;
  int to;
  int next;
  long long flow;
} E[200000 * 2 + 5];
int head[20000 + 5];
int cur[20000 + 5];
int esz = 1;
void add_edge(int u, int v, long long w) {
  esz++;
  E[esz].from = u;
  E[esz].to = v;
  E[esz].flow = w;
  E[esz].next = head[u];
  head[u] = esz;
  esz++;
  E[esz].from = v;
  E[esz].to = u;
  E[esz].flow = 0;
  E[esz].next = head[v];
  head[v] = esz;
}
int deep[20000 + 5];
bool bfs(int s, int t) {
  memset(deep, 0, sizeof(deep));
  queue<int> q;
  q.push(s);
  deep[s] = 1;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = head[x]; i; i = E[i].next) {
      int y = E[i].to;
      if (!deep[y] && E[i].flow) {
        deep[y] = deep[x] + 1;
        q.push(y);
        if (y == t) return 1;
      }
    }
  }
  return 0;
}
long long dfs(int x, int t, long long minf) {
  if (x == t) return minf;
  long long rest = minf, k;
  for (int &i = cur[x]; i; i = E[i].next) {
    int y = E[i].to;
    if (E[i].flow && deep[y] == deep[x] + 1) {
      k = dfs(y, t, min(rest, E[i].flow));
      E[i].flow -= k;
      E[i ^ 1].flow += k;
      rest -= k;
      if (k == 0) deep[y] = 0;
      if (rest == 0) break;
    }
  }
  return minf - rest;
}
long long dinic(int s, int t) {
  long long ans = 0;
  long long now = 0;
  while (bfs(s, t)) {
    memcpy(cur, head, sizeof(head));
    while ((now = dfs(s, t, 0x3f3f3f3f3f3f3f3f))) ans += now;
  }
  return ans;
}
int n, m, g;
int b[20000 + 5];
int a[20000 + 5];
int main() {
  scanf("%d %d %d", &n, &m, &g);
  int s = 0, t = n + m + 1;
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (b[i] == 0)
      add_edge(s, i, a[i]);
    else
      add_edge(i, t, a[i]);
  }
  int type, w, k, sign, x;
  long long sum = 0;
  for (int i = 1; i <= m; i++) {
    scanf("%d %d %d", &type, &w, &k);
    for (int j = 1; j <= k; j++) {
      scanf("%d", &x);
      if (type == 1)
        add_edge(x, i + n, 0x3f3f3f3f3f3f3f3f);
      else
        add_edge(i + n, x, 0x3f3f3f3f3f3f3f3f);
    }
    scanf("%d", &sign);
    if (type == 1)
      add_edge(i + n, t, w + sign * g);
    else
      add_edge(s, i + n, w + sign * g);
    sum += w;
  }
  printf("%I64d\n", sum - dinic(s, t));
}
