#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> S(m, vector<int>(n, 0));
  vector<vector<int>> temp(m, vector<int>(n, 0));
  vector<int> p(m);
  int k, s;
  for (int i = 0; i < m; i++) {
    cin >> k;
    for (int j = 0; j < k; j++) {
      cin >> s;
      S[i][s - 1] = 1;
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> p[i];
  }
  bool on = true;
  int ans = 0;
  int all_on = 1 << n;
  for (int mask = 1; mask < all_on; mask++) {
    for (int i = 0; i < m; i++) {
      int count = 0;
      for (int shift = 0; shift < n; shift++) {
        int sel = (mask >> shift) & 1;
        count += sel * S[i][shift];
      }
      if (count % 2 != p[i]) {
        on = false;
        break;
      }
    }
    if (on) {
      ans++;
    }
    on = true;
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      cout << S[i][j] << " ";
    }
    cout << endl;
  }
  cout << ans << endl;
  return 0;
}
