#include <bits/stdc++.h>
using namespace std;
long long sz[600002], p[600002], r[600002], an[600002], ans = 0;
long long parent(long long i) {
  if (i == p[i]) return i;
  return p[i] = parent(p[i]);
}
void Union(long long i, long long j) {
  i = parent(i);
  j = parent(j);
  if (i == j) {
    ans -= an[i];
    return;
  }
  ans -= an[i];
  ans -= an[j];
  if (sz[i] > sz[j]) swap(i, j);
  p[i] = j;
  sz[j] += sz[i];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, k, i, c, j, x, a, b;
  string s;
  cin >> n >> k >> s;
  vector<long long> v[n + 1];
  sz[0] = k;
  an[0] = 0;
  p[0] = 0;
  r[0] = 2 * k + 1;
  sz[2 * k + 1] = 0;
  an[2 * k + 1] = 0;
  p[2 * k + 1] = 2 * k + 1;
  r[2 * k + 1] = 0;
  for (i = 1; i <= k; i++) {
    cin >> c;
    for (j = 0; j < c; j++) {
      cin >> x;
      v[x].push_back(i);
    }
    sz[i] = 1;
    sz[k + i] = 0;
    p[i] = i;
    p[k + i] = k + i;
    r[i] = k + i;
    r[k + i] = i;
    an[i] = 0;
    an[k + i] = 0;
  }
  for (i = 1; i <= n; i++) {
    if (v[i].size() == 0) {
      cout << ans / 2 << endl;
      continue;
    }
    if (v[i].size() == 1) {
      if (s[i - 1] == '1') {
        Union(0, v[i][0]);
        Union(r[0], r[v[i][0]]);
        a = parent(r[0]);
        b = parent(0);
        an[a] = sz[a];
        an[b] = sz[a];
        ans += 2 * an[a];
      } else {
        Union(r[0], v[i][0]);
        Union(0, r[v[i][0]]);
        a = parent(r[0]);
        b = parent(0);
        an[a] = sz[a];
        an[b] = sz[a];
        ans += 2 * an[a];
      }
      cout << ans / 2 << endl;
      continue;
    }
    if (s[i - 1] == '1') {
      Union(v[i][0], v[i][1]);
      Union(r[v[i][0]], r[v[i][1]]);
      a = parent(r[v[i][0]]);
      b = parent(v[i][0]);
      an[a] = min(sz[a], sz[b]);
      an[b] = min(sz[a], sz[b]);
      ans += 2 * an[a];
    } else {
      Union(r[v[i][0]], v[i][1]);
      Union(v[i][0], r[v[i][1]]);
      a = parent(r[v[i][0]]);
      b = parent(v[i][0]);
      an[a] = min(sz[a], sz[b]);
      an[b] = min(sz[a], sz[b]);
      ans += 2 * an[a];
    }
    cout << ans / 2 << "\n";
  }
  return 0;
}
