#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
const int mod = 20010905;
const int inf = 0x3f3f3f3f;
const long long linf = 0x3f3f3f3f3f3f3f3f;
long long lowbit(long long x) { return x & (-x); }
long long qpow(long long a, long long b, long long c) {
  long long res = 1;
  a %= mod;
  while (b) {
    if (b & 1) res = (res * a) % c;
    a = (a * a) % c;
    b >>= 1;
  }
  return res % c;
}
long long qmul(long long a, long long b, long long c) {
  long long res = 0;
  while (b) {
    if (b & 1) res = (res + a) % c;
    a = (a + a) % c;
    b >>= 1;
  }
  return res % c;
}
struct Bit {
  long long Bit[maxn], N;
  void addBit(long long x, long long v) {
    x = N - x + 1;
    while (x <= N) Bit[x] = max(Bit[x], v), x += lowbit(x);
  }
  long long qBit(long long x) {
    x = N - x + 1;
    long long res = -linf;
    while (x) res = max(res, Bit[x]), x -= lowbit(x);
    return res;
  }
};
char s[maxn];
vector<int> e[maxn];
int pre[maxn];
long long sz[maxn];
int fin(int x) { return pre[x] == x ? x : pre[x] = fin(pre[x]); }
int n, k;
void add(int x, int y) {
  x = fin(x), y = fin(y);
  if (x == y) return;
  pre[x] = y;
  sz[y] += sz[x];
}
int calc(int x) {
  int y = fin(x + k);
  x = fin(x);
  return min(sz[x], sz[y]);
}
long long ANS[maxn];
int main() {
  scanf("%d%d", &n, &k);
  scanf("%s", s + 1);
  for (int i = 1; i <= k; i++) {
    int kk, x;
    scanf("%d", &kk);
    while (kk--) {
      scanf("%d", &x);
      e[x].push_back(i);
    }
  }
  sz[0] = inf;
  for (int i = 1; i <= 2 * k; i++) pre[i] = i, sz[i] = (i <= k);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (e[i].size()) {
      if (s[i] == '1') {
        if (e[i].size() == 1) {
          ans -= calc(e[i][0]);
          sz[fin(e[i][0])] = inf;
          ans += calc(e[i][0]);
        } else {
          int x = e[i][0], y = e[i][1];
          if (fin(x) != fin(y)) {
            ans -= calc(x) + calc(y);
            add(x, y), add(x + k, y + k);
            ans += calc(x);
          }
        }
      } else {
        if (e[i].size() == 1) {
          ans -= calc(e[i][0]);
          sz[fin(e[i][0] + k)] = inf;
          ans += calc(e[i][0]);
        } else {
          int x = e[i][0], y = e[i][1];
          if (fin(x) != fin(y + k)) {
            ans -= calc(x) + calc(y);
            add(x, y + k), add(x + k, y);
            ans += calc(x);
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
