#include <bits/stdc++.h>
using namespace std;
void read(int &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -f;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  x *= f;
}
void print(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (!x) return;
  print(x / 10), putchar(x % 10 + 48);
}
void write(int x) {
  if (!x)
    putchar('0');
  else
    print(x);
  putchar('\n');
}
const int maxn = 1e6 + 10;
const int inf = 1e9;
const double eps = 1e-8;
const int mod = 1e9 + 7;
int n, m, g, head[maxn], tot = 1, r[maxn], cnt, s, t, max_flow;
struct edge {
  int to, nxt, w;
} e[maxn << 1];
void add(int u, int v, int w) {
  e[++tot] = (edge){v, head[u], w}, head[u] = tot;
}
void ins(int u, int v, int w) {
  if (!w) return;
  add(u, v, w), add(v, u, 0);
}
int dis[maxn];
int bfs() {
  memset(dis, -1, (cnt + 1) * 4);
  queue<int> q;
  q.push(s);
  dis[s] = 0;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = head[x]; i; i = e[i].nxt)
      if (dis[e[i].to] == -1 && e[i].w != 0) {
        dis[e[i].to] = dis[x] + 1;
        if (e[i].to == t) return 1;
        q.push(e[i].to);
      }
  }
  return 0;
}
int dfs(int x, int f) {
  if (x == t) return f;
  int used = 0;
  for (int i = head[x]; i; i = e[i].nxt)
    if (dis[e[i].to] == dis[x] + 1 && e[i].w) {
      int d = dfs(e[i].to, min(f, e[i].w));
      e[i].w -= d, e[i ^ 1].w += d, used += d, f -= d;
      if (!f) break;
    }
  if (!used) dis[x] = -1;
  return used;
}
void dinic() {
  while (bfs()) max_flow += dfs(s, inf);
}
int main() {
  read(n), read(m), read(g);
  s = n + 1, t = s + 1;
  cnt = t;
  for (int i = 1; i <= n; i++) read(r[i]);
  for (int i = 1, v; i <= n; i++) {
    read(v);
    if (r[i])
      ins(s, i, v), ins(i, t, 0);
    else
      ins(s, i, 0), ins(i, t, v);
  }
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    int w, tt, m, op;
    read(w), read(tt), read(m);
    ++cnt;
    for (int j = 1, x; j <= m; j++) {
      read(x);
      if (w)
        ins(cnt, x, inf);
      else
        ins(x, cnt, inf);
    }
    read(op);
    ans += tt;
    if (w)
      ins(s, cnt, tt + op * g);
    else
      ins(cnt, t, tt + op * g);
  }
  dinic();
  write(ans - max_flow);
  return 0;
}
