#include <bits/stdc++.h>
using namespace std;
pair<int, int> operator+(const pair<int, int> &a, const pair<int, int> &b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
pair<int, int> operator-(const pair<int, int> &a, const pair<int, int> &b) {
  return make_pair(a.first - b.first, a.second - b.second);
}
pair<int, int> &operator+=(pair<int, int> &a, const pair<int, int> &b) {
  a.first += b.first;
  a.second += b.second;
  return a;
}
pair<int, int> &operator-=(pair<int, int> &a, const pair<int, int> &b) {
  a.first -= b.first;
  a.second -= b.second;
  return a;
}
template <class T, class U>
bool cmp_second(const pair<T, U> &a, const pair<T, U> &b) {
  return a.second < b.second;
}
template <class T>
T gcd(T a, T b) {
  a = abs(a);
  b = abs(b);
  while (b) {
    T t = b;
    b = a % b;
    a = t;
  }
  return a;
}
template <class T>
pair<T, T> ext_gcd(T a, T b) {
  T a0 = 1, a1 = 0, b0 = 0, b1 = 1;
  if (a < 0) {
    a = -a;
    a0 = -1;
  }
  if (b < 0) {
    b = -b;
    b1 = -1;
  }
  while (b) {
    T t, q = a / b;
    t = b;
    b = a - b * q;
    a = t;
    t = b0;
    b0 = a0 - b0 * q;
    a0 = t;
    t = b1;
    b1 = a1 - b1 * q;
    a1 = t;
  }
  return make_pair(a0, a1);
}
inline int sg(int x) { return x ? (x > 0 ? 1 : -1) : 0; }
const int inf = 1000000010;
class Arc {
 public:
  int to, revind;
  int flow, cap;
  Arc(int _to, int _revind, int _cap)
      : to(_to), revind(_revind), cap(_cap), flow(0) {}
};
class DinicFlow {
 public:
  int vn, src, sink;
  vector<Arc> adj[15000];
  int dist[15000];
  int ql, qr, que[15000];
  int iter[15000];
  DinicFlow(int _vn, int _src, int _sink) : vn(_vn), src(_src), sink(_sink) {}
  void append(int v, int u, int c) {
    int vid = adj[v].size(), uid = adj[u].size();
    adj[v].push_back(Arc(u, uid, c));
    adj[u].push_back(Arc(v, vid, 0));
  }
  void bfs_layer() {
    ql = qr = 0;
    for (int i = 0; i < vn; i++) dist[i] = inf;
    que[qr++] = src;
    dist[src] = 0;
    while (ql < qr) {
      int v = que[ql++];
      for (int i = 0; i < adj[v].size(); i++) {
        int u = adj[v][i].to;
        int res = adj[v][i].cap - adj[v][i].flow;
        if (dist[u] < inf) continue;
        if (!res) continue;
        que[qr++] = u;
        dist[u] = dist[v] + 1;
      }
    }
  }
  int dfs_push(int v, int a) {
    if (v == sink) return a;
    int pushed = 0;
    for (int &i = iter[v]; i < adj[v].size(); i++) {
      int u = adj[v][i].to;
      int res = adj[v][i].cap - adj[v][i].flow;
      if (dist[u] != dist[v] + 1) continue;
      if (!res) continue;
      int ri = adj[v][i].revind;
      int pf = dfs_push(u, min(a - pushed, res));
      adj[v][i].flow += pf;
      adj[u][ri].flow -= pf;
      pushed += pf;
      if (pushed == a) break;
    }
    return pushed;
  }
  int push_flow() {
    bfs_layer();
    for (int i = 0; i < vn; i++) iter[i] = 0;
    return dfs_push(src, inf);
  }
  int maxflow() {
    int f = 0;
    while (1) {
      int pf = push_flow();
      if (!pf) break;
      f += pf;
    }
    return f;
  }
  vector<pair<int, int> > mincut() {
    bfs_layer();
    vector<pair<int, int> > cut;
    for (int v = 0; v < vn; v++) {
      for (int i = 0; i < adj[v].size(); i++) {
        int u = adj[v][i].to;
        if (dist[v] < inf && dist[u] == inf) cut.push_back(make_pair(v, u));
      }
    }
    return cut;
  }
  vector<int> srccut() {
    bfs_layer();
    vector<int> vs;
    for (int v = 0; v < vn; v++)
      if (dist[v] < inf) vs.push_back(v);
    return vs;
  }
  vector<int> sinkcut() {
    bfs_layer();
    vector<int> vs;
    for (int v = 0; v < vn; v++)
      if (dist[v] == inf) vs.push_back(v);
    return vs;
  }
  bool mincut_is_isolated_sink() { return sinkcut().size() == 1; }
};
int nsub, nplan, pen;
int osex[15000], tran[15000];
int base;
inline int vsub(int x) { return x + 1; }
inline int vplan(int x) { return nsub + x + 1; }
int main(void) {
  scanf("%d %d %d", &(nsub), &(nplan), &(pen));
  int vn = nsub + nplan + 2;
  int src = 0;
  int sink = vn - 1;
  base = 0;
  DinicFlow df(vn, src, sink);
  for (int i = 0; i < nsub; i++) scanf("%d", &(osex[i]));
  for (int i = 0; i < nsub; i++) {
    scanf("%d", &(tran[i]));
    if (osex[i])
      df.append(vsub(i), sink, tran[i]);
    else
      df.append(src, vsub(i), tran[i]);
  }
  for (int i = 0; i < nplan; i++) {
    int goal, reward, num, isfriend;
    scanf("%d %d %d", &(goal), &(reward), &(num));
    for (int t = 0; t < num; t++) {
      int u;
      scanf("%d", &(u));
      u--;
      if (goal)
        df.append(vsub(u), vplan(i), inf);
      else
        df.append(vplan(i), vsub(u), inf);
    }
    scanf("%d", &(isfriend));
    int rc = reward + (isfriend ? pen : 0);
    base += reward;
    if (goal)
      df.append(vplan(i), sink, rc);
    else
      df.append(src, vplan(i), rc);
  }
  int mincost = df.maxflow();
  int sol = base - mincost;
  printf("%d\n", sol);
  return 0;
}
