#include <bits/stdc++.h>
using namespace std;
const int N = 12010, M = 1000000, Inf = 2000000000;
int tt = 1, S, T;
bool w[N];
int head[N], to[M], nxt[M], s[M], lev[N], v[N];
inline int gi() {
  int x = 0, o = 1;
  char ch = getchar();
  while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
  if (ch == '-') o = -1, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * o;
}
inline bool bfs() {
  memset(lev, 0, sizeof(lev));
  int t = 0, sum = 1;
  v[1] = S, lev[S] = 1;
  while (t < sum) {
    int x = v[++t];
    for (int i = head[x]; i; i = nxt[i]) {
      int y = to[i];
      if (s[i] && !lev[y]) {
        lev[y] = lev[x] + 1, v[++sum] = y;
        if (y == T) return 1;
      }
    }
  }
  return 0;
}
inline int dfs(int x, int Mx) {
  if (x == T) return Mx;
  int ret = 0;
  for (int i = head[x]; i; i = nxt[i]) {
    int y = to[i];
    if (s[i] && lev[y] == lev[x] + 1) {
      int f = dfs(y, min(Mx - ret, s[i]));
      s[i] -= f, s[i ^ 1] += f, ret += f;
      if (ret == Mx) break;
    }
  }
  if (!ret) lev[x] = 0;
  return ret;
}
inline void lnk(int x, int y, int z) {
  to[++tt] = y, nxt[tt] = head[x], s[tt] = z, head[x] = tt;
  to[++tt] = x, nxt[tt] = head[y], head[y] = tt;
}
int main() {
  int n, m, g, ans = 0;
  cin >> n >> m >> g;
  S = 0, T = n + m + 1;
  for (int i = 1; i <= n; i++) w[i] = gi();
  for (int i = 1; i <= n; i++) {
    if (w[i])
      lnk(S, i, gi());
    else
      lnk(i, T, gi());
  }
  for (int i = 1; i <= m; i++) {
    int x = gi(), y = gi(), z = gi();
    ans += y;
    if (x) {
      while (z--) lnk(n + i, gi(), Inf);
      lnk(S, n + i, y + g * gi());
    } else {
      while (z--) lnk(gi(), n + i, Inf);
      lnk(n + i, T, y + g * gi());
    }
  }
  while (bfs()) ans -= dfs(S, Inf);
  cout << ans;
  return 0;
}
