#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char ch = getchar();
  int nega = 1;
  while (!isdigit(ch)) {
    if (ch == '-') nega = -1;
    ch = getchar();
  }
  int ans = 0;
  while (isdigit(ch)) {
    ans = ans * 10 + ch - 48;
    ch = getchar();
  }
  if (nega == -1) return -ans;
  return ans;
}
int add(int x, int y) { return x + y >= 998244353 ? x + y - 998244353 : x + y; }
int sub(int x, int y) { return x - y < 0 ? x - y + 998244353 : x - y; }
int mul(int x, int y) { return 1LL * x * y % 998244353; }
int a[200005], s, t;
struct Edge {
  int v, nxt, cap;
};
Edge edge[200005 * 2];
int first[200005], ss = 1;
void add(int u, int v, int w) {
  ss++;
  edge[ss].v = v, edge[ss].cap = w;
  edge[ss].nxt = first[u], first[u] = ss;
  ss++;
  edge[ss].v = u, edge[ss].cap = 0;
  edge[ss].nxt = first[v], first[v] = ss;
}
int dep[200005];
bool bfs(int u) {
  for (int i = 1; i < 200005; i++) dep[i] = 0;
  dep[u] = 1;
  queue<int> q;
  q.push(u);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = first[u]; i != 0; i = edge[i].nxt) {
      if (edge[i].cap == 0) continue;
      int v = edge[i].v;
      if (!dep[v]) {
        dep[v] = dep[u] + 1;
        q.push(v);
      }
    }
  }
  return dep[t];
}
int dfs(int u, int flow) {
  if (u == t) return flow;
  if (!flow) return flow;
  int go = 0;
  for (int i = first[u]; i != 0; i = edge[i].nxt) {
    if (edge[i].cap == 0) continue;
    int v = edge[i].v;
    if (dep[v] != dep[u] + 1) continue;
    int R = dfs(v, min(flow, edge[i].cap));
    edge[i].cap -= R, edge[i ^ 1].cap += R;
    flow -= R, go += R;
  }
  return go;
}
int dinic() {
  int ans = 0;
  while (bfs(s)) ans += dfs(s, 0x3fffffff);
  return ans;
}
signed main() {
  int n = read(), m = read(), g = read();
  s = n + m + 1, t = n + m + 2;
  for (int i = 1; i <= n; i++) a[i] = read();
  for (int i = 1; i <= n; i++) {
    int w = read();
    if (a[i])
      add(i, t, w);
    else
      add(s, i, w);
  }
  int sum = 0;
  for (int i = 1; i <= m; i++) {
    int o = read(), w = read(), k = read();
    sum += w;
    if (o) {
      while (k--) {
        int u = read();
        add(u, n + i, 0x3fffffff);
      }
      int p = read();
      if (p)
        add(n + i, t, g + w);
      else
        add(n + i, t, w);
    } else {
      while (k--) {
        int u = read();
        add(n + i, u, 0x3fffffff);
      }
      int p = read();
      if (p)
        add(s, n + i, g + w);
      else
        add(s, n + i, w);
    }
  }
  cout << sum - dinic() << endl;
  return 0;
}
