#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 300010;
const int M = 600010;
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -f;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - 48;
    c = getchar();
  }
  return x * f;
}
int ea[M], eb[M], ec[N], ef[M], etot = 1, dis[N], S, T;
bool vis[N];
void add(int x, int y, int f) {
  etot++;
  ea[etot] = y;
  eb[etot] = ec[x];
  ec[x] = etot;
  ef[etot] = f;
}
void addEdge(int x, int y, int f) {
  add(x, y, f);
  add(y, x, 0);
}
bool bfs() {
  memset(vis, 0, sizeof(vis));
  memset(dis, 0x3f, sizeof(dis));
  dis[S] = 0;
  vis[S] = 1;
  queue<int> q;
  q.push(S);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    vis[x] = 0;
    for (int i = ec[x]; ~i; i = eb[i]) {
      int y = ea[i];
      if (dis[y] > dis[x] + 1 && ef[i]) {
        dis[y] = dis[x] + 1;
        if (!vis[y]) {
          q.push(y);
          vis[y] = 1;
        }
      }
    }
  }
  return dis[T] < inf;
}
int maxf;
int dfs(int x, int flow) {
  if (x == T) {
    vis[T] = 1;
    maxf += flow;
    return flow;
  }
  int used = 0;
  vis[x] = 1;
  for (int i = ec[x]; ~i; i = eb[i]) {
    int y = ea[i];
    if ((!vis[y] || y == T) && ef[i] && dis[y] == dis[x] + 1) {
      int minf = dfs(y, min(flow - used, ef[i]));
      if (minf != 0) ef[i] -= minf, ef[i ^ 1] += minf, used += minf;
      if (used == flow) break;
    }
  }
  return used;
}
int dinic() {
  while (bfs()) {
    vis[T] = 1;
    while (vis[T]) {
      memset(vis, 0, sizeof(vis));
      dfs(S, inf);
    }
  }
  return maxf;
}
int a[N], v[N];
signed main() {
  int n = read(), m = read(), g = read();
  T = n + m + 1;
  memset(ec, -1, sizeof(ec));
  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])
      addEdge(S, i, v[i]);
    else
      addEdge(i, T, v[i]);
  }
  int ans = 0;
  for (int i = 1; i <= m; ++i) {
    int b = read(), w = read(), k = read();
    ans += w;
    for (int j = 1; j <= k; ++j) {
      int x = read();
      if (b)
        addEdge(x, n + i, inf);
      else
        addEdge(n + i, x, inf);
    }
    int p = read();
    if (p) w += g;
    if (b)
      addEdge(n + i, T, w);
    else
      addEdge(S, n + i, w);
  }
  cout << ans - dinic() << endl;
  return 0;
}
