#include <bits/stdc++.h>
using namespace std;
const int Maxx = 1000001, Maxn = 2001, INF = 0x3f3f3f3f, Mod = 1e9 + 7;
inline int read() {
  int res = 0, bj = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') bj |= (ch == '-'), ch = getchar();
  while (ch >= '0' && ch <= '9')
    res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
  return bj ? -res : res;
}
void print(int x) {
  if (x > 9) print(x / 10);
  putchar(x % 10 ^ 48);
}
inline void printnum(int x, char ch) {
  if (x < 0) putchar('-'), x = -x;
  print(x), putchar(ch);
}
int n, m, k, g, S, T, Po, Ans, cnt = 1, h[Maxx], d[Maxx], q[Maxx], to[Maxx],
                               nx[Maxx], vl[Maxx];
bool rp[Maxx];
inline void Add(int x, int y, int z) {
  to[++cnt] = y, nx[cnt] = h[x], vl[h[x] = cnt] = z;
  to[++cnt] = x, nx[cnt] = h[y], vl[h[y] = cnt] = 0;
}
inline bool Bfs(int S, int T) {
  int l = 1, r = 1, x;
  memset(d, -1, sizeof(d)), d[q[++r] = S] = 0;
  while (l < r) {
    if ((x = q[++l]) == T) return true;
    for (int i = h[x]; i; i = nx[i])
      if (vl[i] && d[to[i]] == -1) d[q[++r] = to[i]] = d[x] + 1;
  }
  return false;
}
int Dfs(int x, int Mx) {
  if (x == T) return Mx;
  int ret = 0, dlt;
  for (int i = h[x]; i && Mx; i = nx[i])
    if (vl[i] && d[to[i]] == d[x] + 1)
      if (dlt = Dfs(to[i], vl[i] < Mx ? vl[i] : Mx))
        vl[i] -= dlt, vl[i ^ 1] += dlt, Mx -= dlt, ret += dlt;
      else
        d[to[i]] = 0;
  return ret;
}
int main() {
  n = read(), m = read(), g = read(), S = n + m + 1, T = n + m + 2;
  for (int i = 1; i <= n; ++i) rp[i] = read();
  for (int i = 1; i <= n; ++i)
    if (rp[i])
      Add(S, i, read());
    else
      Add(i, T, read());
  for (int i = 1; i <= m; ++i)
    if (read()) {
      Add(S, i + n, read()), Po = cnt - 1, k = read() + 1;
      while (--k) Add(i + n, read(), INF);
      Ans += vl[Po], vl[Po] += read() ? g : 0;
    } else {
      Add(i + n, T, read()), Po = cnt - 1, k = read() + 1;
      while (--k) Add(read(), i + n, INF);
      Ans += vl[Po], vl[Po] += read() ? g : 0;
    }
  while (Bfs(S, T)) Ans -= Dfs(S, 1 << 30);
  printnum(Ans, '\n');
  return 0;
}
