#include <bits/stdc++.h>
using namespace std;
int n, dep[100003], s, t, p, m, g, x, a[100003], v[100003], che, v1, w, k, ans;
queue<int> q;
vector<int> l[100003], l1[100003], nu[100003];
void bfs() {
  memset(dep, 0, sizeof(dep));
  q.push(s), dep[s] = 1;
  while (!q.empty()) {
    p = q.front(), q.pop();
    for (int j = 0; j < l[p].size(); j++)
      if (l1[p][j] != 0 && dep[l[p][j]] == 0)
        dep[l[p][j]] = dep[p] + 1, q.push(l[p][j]);
  }
}
int dfs(int x1, int wat) {
  if (x1 == t) return wat;
  int cnt, sum = 0;
  for (int j = 0; j < l[x1].size(); j++)
    if (l1[x1][j] != 0 && dep[l[x1][j]] == dep[x1] + 1)
      cnt = dfs(l[x1][j], min(wat, l1[x1][j])), l1[x1][j] -= cnt,
      l1[l[x1][j]][nu[x1][j]] += cnt, sum += cnt, wat -= cnt;
  if (sum == 0) dep[x1] = 0;
  return sum;
}
void add(int x, int y, int wat) {
  l[x].push_back(y), l[y].push_back(x), l1[x].push_back(wat),
      l1[y].push_back(0), nu[x].push_back(l[y].size() - 1),
      nu[y].push_back(l[x].size() - 1);
}
int main() {
  scanf("%d%d%d", &n, &m, &g);
  s = 0, t = n + m + 1;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &v[i]);
    if (a[i] == 0)
      add(s, i, v[i]);
    else
      add(i, t, v[i]);
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &v1, &w, &k);
    ans += w;
    for (int j = 1; j <= k; j++) {
      scanf("%d", &x);
      if (v1 == 0)
        add(n + i, x, 2e9);
      else
        add(x, n + i, 2e9);
    }
    scanf("%d", &che);
    w += che * g;
    if (v1 == 0)
      add(s, n + i, w);
    else
      add(n + i, t, w);
  }
  while (1) {
    bfs();
    if (dep[t] == 0) break;
    ans -= dfs(s, 2e9);
  }
  cout << ans;
  return 0;
}
