#include <bits/stdc++.h>
template <class c>
int popc(c a) {
  if (sizeof(c) == 8)
    return __builtin_popcountll(a);
  else
    return __builtin_popcount(a);
}
template <class c>
int ctz(c a) {
  if (sizeof(c) == 8)
    return __builtin_ctzll(a);
  else
    return __builtin_ctz(a);
}
template <class c>
int clz(c a) {
  if (sizeof(c) == 8)
    return __builtin_clzll(a);
  else
    return __builtin_clz(a);
}
inline int min(const int &first, const int &second) {
  return (((second - first) >> (32 - 1)) & (first ^ second)) ^ first;
}
inline int max(const int &first, const int &second) {
  return (((second - first) >> (32 - 1)) & (first ^ second)) ^ second;
}
inline long long min(const long long &first, const long long &second) {
  return (((second - first) >> (64 - 1)) & (first ^ second)) ^ first;
}
inline long long max(const long long &first, const long long &second) {
  return (((second - first) >> (64 - 1)) & (first ^ second)) ^ second;
}
using namespace std;
char string_in_buffer[(int)2e6];
void fast_scan(int &first) { scanf("%d", &first); }
void fast_scan(long long &first) { scanf("%lld", &first); }
void fast_scan(unsigned long long &first) { scanf("%llu", &first); }
void fast_scan(double &first) { scanf("%lf", &first); }
void fast_scan(long double &first) { scanf("%Lf", &first); }
void fast_scan(char &first) {
  scanf("%c", &first);
  if (first == '\n') {
    fast_scan(first);
  }
}
void fast_scan(string &first) {
  scanf("%s", string_in_buffer);
  first = string(string_in_buffer);
}
template <class TFirst, class TSecond>
void fast_scan(pair<TFirst, TSecond> &p) {
  fast_scan(p.first);
  fast_scan(p.second);
}
template <class T>
void fast_scan(vector<T> &v) {
  for (auto &first : v) fast_scan(first);
}
void fast_print(const int &first) { printf("%d", first); }
void fast_print(const unsigned int &first) { printf("%u", first); }
void fast_print(const long long &first) { printf("%lld", first); }
void fast_print(const unsigned long long &first) { printf("%llu", first); }
void fast_print(const char &first) { printf("%c", first); };
void fast_print(const double &first) { printf("%.15lf", first); }
void fast_print(const long double &first) { printf("%.15Lf", first); }
void fast_print(const string &first) { printf("%s", first.c_str()); }
void fast_print(const char v[]) { fast_print((string)v); }
template <class TFirst, class TSecond>
void fast_print(const pair<TFirst, TSecond> &p) {
  fast_print(p.first);
  fast_print(' ');
  fast_print(p.second);
}
template <class T>
void fast_print(const vector<T> &v) {
  if (v.empty()) return;
  fast_print(v[0]);
  for (int i = 1; i < v.size(); i++) {
    fast_print(' ');
    fast_print(v[i]);
  }
}
template <class T>
void fast_print(const vector<vector<T>> &v) {
  if (v.empty()) return;
  fast_print(v[0]);
  for (int i = 1; i < v.size(); i++) {
    fast_print('\n');
    fast_print(v[i]);
  }
}
template <class T>
void fast_print(const T &v) {
  for (const auto &first : v) {
    fast_print(first);
    fast_print(' ');
  }
}
using namespace std;
namespace smart_io {
string print_start = "";
string sep = " ";
bool first_print = false;
void precall_print() {
  fast_print(print_start);
  print_start = "\n";
  first_print = true;
}
void _print(deque<string>) {}
template <class T, class... Args>
void _print(deque<string> names, T elem, Args... args) {
  if (!first_print) {
    fast_print("\n");
  } else {
    first_print = false;
  }
  fast_print(names.front());
  fast_print(" = ");
  fast_print(elem);
  names.pop_front();
  _print(names, args...);
}
}  // namespace smart_io
template <class T>
ostream &operator,(ostream &os, const T &object) {
  if (!smart_io::first_print) {
    fast_print(smart_io::sep);
  } else {
    smart_io::first_print = false;
  }
  fast_print(object);
  return os;
}
template <class T>
istream &operator,(istream &is, T &object) {
  fast_scan(object);
  return is;
}
namespace escape__from__random__aetuhoetnuhshe {
using namespace std::chrono;
mt19937 rng(duration_cast<milliseconds>(system_clock::now().time_since_epoch())
                .count());
uniform_real_distribution<> prob_dist(0.0, 1.0);
};  // namespace escape__from__random__aetuhoetnuhshe
namespace typedefs {}
namespace numbers_operation {
template <class T>
inline T floor_mod(T a, const T &b) {
  a %= b;
  if (a < 0) a += b;
  return a;
}
}  // namespace numbers_operation
using namespace numbers_operation;
using namespace typedefs;
using namespace escape__from__random__aetuhoetnuhshe;
int n, k;
vector<int> up;
vector<int> tsize;
vector<int> size0;
vector<int> parity;
vector<bool> stat;
int get_root(int v) {
  if (up[v] == v) return v;
  return get_root(up[v]);
}
int get_parity(int v) {
  int p = parity[v];
  if (up[v] == v) return p;
  return p ^ get_parity(up[v]);
}
void invert(int i) {
  i = get_root(i);
  parity[i] ^= 1;
  size0[i] = tsize[i] - size0[i];
}
void block(int i) {
  i = get_root(i);
  stat[i] = true;
}
int rez = 0;
void update(int i, int d) {
  i = get_root(i);
  if (!stat[i])
    rez += min(size0[i], tsize[i] - size0[i]) * d;
  else
    rez += size0[i] * d;
}
signed main(signed argc, char *argv[]) {
  cin, n, k;
  {
    up.resize(k);
    iota(up.begin(), up.end(), 0);
    tsize.resize(k, 1);
    size0.resize(k, 1);
    stat.resize(k, false);
    parity.resize(k, 0);
  }
  vector<vector<int>> g(n);
  string s;
  cin, s;
  for (int i = 0; i < (k); i++) {
    int c;
    cin, c;
    vector<int> elems(c);
    cin, elems;
    for (auto &first : elems) {
      first--;
    };
    for (int el : elems) {
      g[el].push_back(i);
    }
  }
  for (int i = 0; i < n; i++) {
    if (((int)g[i].size()) > 1) {
      int a = get_root(g[i][0]);
      int b = get_root(g[i][1]);
      if (a == b) {
        goto after;
      }
      update(a, -1);
      update(b, -1);
      int pa = get_parity(g[i][0]);
      int push_back = get_parity(g[i][1]);
      if (tsize[a] < tsize[b]) {
        swap(a, b);
        swap(pa, push_back);
      }
      if (s[i] == '1') {
        if (pa != push_back) {
          if (!stat[b]) {
            parity[b] ^= 1;
            size0[b] = tsize[b] - size0[b];
          } else {
            assert(!stat[a]);
            parity[a] ^= 1;
            size0[a] = tsize[a] - size0[a];
          }
        }
        parity[b] ^= parity[a];
        up[b] = a;
        tsize[a] += tsize[b];
        size0[a] += size0[b];
        stat[a] = (stat[a] | stat[b]);
      } else {
        if (pa == push_back) {
          if (!stat[b]) {
            if (i == 4) {
            }
            parity[b] ^= 1;
            size0[b] = tsize[b] - size0[b];
          } else {
            assert(!stat[a]);
            parity[a] ^= 1;
            size0[a] = tsize[a] - size0[a];
          }
        }
        parity[b] ^= parity[a];
        up[b] = a;
        tsize[a] += tsize[b];
        size0[a] += size0[b];
        stat[a] = (stat[a] | stat[b]);
      }
      update(a, 1);
    } else {
      if (!g[i].empty()) {
        update(g[i][0], -1);
      }
      if (s[i] == '1') {
        if (!g[i].empty()) {
          int color = get_parity(g[i][0]);
          if (color == 0) {
            invert(get_root(g[i][0]));
          }
          block(g[i][0]);
        }
      } else {
        assert(!g[i].empty());
        int color = get_parity(g[i][0]);
        if (color == 1) {
          invert(get_root(g[i][0]));
        }
        block(g[i][0]);
      }
      if (!g[i].empty()) {
        update(g[i][0], 1);
      }
    }
  after:
    smart_io::precall_print();
    cout, rez;
  }
}

### Prompt

Please provide a cpp coded solution to the problem described below:

There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1).

You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≤ i_1 < i_2 < i_3 ≤ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = ∅.

In one operation, you can choose one of these k subsets and switch the state of all lamps in it. It is guaranteed that, with the given subsets, it's possible to make all lamps be simultaneously on using this type of operation.

Let m_i be the minimum number of operations you have to do in order to make the i first lamps be simultaneously on. Note that there is no condition upon the state of other lamps (between i+1 and n), they can be either off or on.

You have to compute m_i for all 1 ≤ i ≤ n.

Input

The first line contains two integers n and k (1 ≤ n, k ≤ 3 ⋅ 10^5).

The second line contains a binary string of length n, representing the initial state of each lamp (the lamp i is off if s_i = 0, on if s_i = 1).

The description of each one of the k subsets follows, in the following format:

The first line of the description contains a single integer c (1 ≤ c ≤ n) — the number of elements in the subset.

The second line of the description contains c distinct integers x_1, …, x_c (1 ≤ x_i ≤ n) — the elements of the subset.

It is guaranteed that: 

  * The intersection of any three subsets is empty; 
  * It's possible to make all lamps be simultaneously on using some operations. 

Output

You must output n lines. The i-th line should contain a single integer m_i — the minimum number of operations required to make the lamps 1 to i be simultaneously on.

Examples

Input


7 3
0011100
3
1 4 6
3
3 4 7
2
2 3


Output


1
2
3
3
3
3
3


Input


8 6
00110011
3
1 3 8
5
1 2 5 6 7
2
6 8
2
3 5
2
4 7
1
2


Output


1
1
1
1
1
1
4
4


Input


5 3
00011
3
1 2 3
1
4
3
3 4 5


Output


1
1
1
1
1


Input


19 5
1001001001100000110
2
2 3
2
5 6
2
8 9
5
12 13 14 15 16
1
19


Output


0
1
1
1
2
2
2
3
3
3
3
4
4
4
4
4
4
4
5

Note

In the first example: 

  * For i = 1, we can just apply one operation on A_1, the final states will be 1010110; 
  * For i = 2, we can apply operations on A_1 and A_3, the final states will be 1100110; 
  * For i ≥ 3, we can apply operations on A_1, A_2 and A_3, the final states will be 1111111. 



In the second example: 

  * For i ≤ 6, we can just apply one operation on A_2, the final states will be 11111101; 
  * For i ≥ 7, we can apply operations on A_1, A_3, A_4, A_6, the final states will be 11111111. 

### Response

```cpp
#include <bits/stdc++.h>
template <class c>
int popc(c a) {
  if (sizeof(c) == 8)
    return __builtin_popcountll(a);
  else
    return __builtin_popcount(a);
}
template <class c>
int ctz(c a) {
  if (sizeof(c) == 8)
    return __builtin_ctzll(a);
  else
    return __builtin_ctz(a);
}
template <class c>
int clz(c a) {
  if (sizeof(c) == 8)
    return __builtin_clzll(a);
  else
    return __builtin_clz(a);
}
inline int min(const int &first, const int &second) {
  return (((second - first) >> (32 - 1)) & (first ^ second)) ^ first;
}
inline int max(const int &first, const int &second) {
  return (((second - first) >> (32 - 1)) & (first ^ second)) ^ second;
}
inline long long min(const long long &first, const long long &second) {
  return (((second - first) >> (64 - 1)) & (first ^ second)) ^ first;
}
inline long long max(const long long &first, const long long &second) {
  return (((second - first) >> (64 - 1)) & (first ^ second)) ^ second;
}
using namespace std;
char string_in_buffer[(int)2e6];
void fast_scan(int &first) { scanf("%d", &first); }
void fast_scan(long long &first) { scanf("%lld", &first); }
void fast_scan(unsigned long long &first) { scanf("%llu", &first); }
void fast_scan(double &first) { scanf("%lf", &first); }
void fast_scan(long double &first) { scanf("%Lf", &first); }
void fast_scan(char &first) {
  scanf("%c", &first);
  if (first == '\n') {
    fast_scan(first);
  }
}
void fast_scan(string &first) {
  scanf("%s", string_in_buffer);
  first = string(string_in_buffer);
}
template <class TFirst, class TSecond>
void fast_scan(pair<TFirst, TSecond> &p) {
  fast_scan(p.first);
  fast_scan(p.second);
}
template <class T>
void fast_scan(vector<T> &v) {
  for (auto &first : v) fast_scan(first);
}
void fast_print(const int &first) { printf("%d", first); }
void fast_print(const unsigned int &first) { printf("%u", first); }
void fast_print(const long long &first) { printf("%lld", first); }
void fast_print(const unsigned long long &first) { printf("%llu", first); }
void fast_print(const char &first) { printf("%c", first); };
void fast_print(const double &first) { printf("%.15lf", first); }
void fast_print(const long double &first) { printf("%.15Lf", first); }
void fast_print(const string &first) { printf("%s", first.c_str()); }
void fast_print(const char v[]) { fast_print((string)v); }
template <class TFirst, class TSecond>
void fast_print(const pair<TFirst, TSecond> &p) {
  fast_print(p.first);
  fast_print(' ');
  fast_print(p.second);
}
template <class T>
void fast_print(const vector<T> &v) {
  if (v.empty()) return;
  fast_print(v[0]);
  for (int i = 1; i < v.size(); i++) {
    fast_print(' ');
    fast_print(v[i]);
  }
}
template <class T>
void fast_print(const vector<vector<T>> &v) {
  if (v.empty()) return;
  fast_print(v[0]);
  for (int i = 1; i < v.size(); i++) {
    fast_print('\n');
    fast_print(v[i]);
  }
}
template <class T>
void fast_print(const T &v) {
  for (const auto &first : v) {
    fast_print(first);
    fast_print(' ');
  }
}
using namespace std;
namespace smart_io {
string print_start = "";
string sep = " ";
bool first_print = false;
void precall_print() {
  fast_print(print_start);
  print_start = "\n";
  first_print = true;
}
void _print(deque<string>) {}
template <class T, class... Args>
void _print(deque<string> names, T elem, Args... args) {
  if (!first_print) {
    fast_print("\n");
  } else {
    first_print = false;
  }
  fast_print(names.front());
  fast_print(" = ");
  fast_print(elem);
  names.pop_front();
  _print(names, args...);
}
}  // namespace smart_io
template <class T>
ostream &operator,(ostream &os, const T &object) {
  if (!smart_io::first_print) {
    fast_print(smart_io::sep);
  } else {
    smart_io::first_print = false;
  }
  fast_print(object);
  return os;
}
template <class T>
istream &operator,(istream &is, T &object) {
  fast_scan(object);
  return is;
}
namespace escape__from__random__aetuhoetnuhshe {
using namespace std::chrono;
mt19937 rng(duration_cast<milliseconds>(system_clock::now().time_since_epoch())
                .count());
uniform_real_distribution<> prob_dist(0.0, 1.0);
};  // namespace escape__from__random__aetuhoetnuhshe
namespace typedefs {}
namespace numbers_operation {
template <class T>
inline T floor_mod(T a, const T &b) {
  a %= b;
  if (a < 0) a += b;
  return a;
}
}  // namespace numbers_operation
using namespace numbers_operation;
using namespace typedefs;
using namespace escape__from__random__aetuhoetnuhshe;
int n, k;
vector<int> up;
vector<int> tsize;
vector<int> size0;
vector<int> parity;
vector<bool> stat;
int get_root(int v) {
  if (up[v] == v) return v;
  return get_root(up[v]);
}
int get_parity(int v) {
  int p = parity[v];
  if (up[v] == v) return p;
  return p ^ get_parity(up[v]);
}
void invert(int i) {
  i = get_root(i);
  parity[i] ^= 1;
  size0[i] = tsize[i] - size0[i];
}
void block(int i) {
  i = get_root(i);
  stat[i] = true;
}
int rez = 0;
void update(int i, int d) {
  i = get_root(i);
  if (!stat[i])
    rez += min(size0[i], tsize[i] - size0[i]) * d;
  else
    rez += size0[i] * d;
}
signed main(signed argc, char *argv[]) {
  cin, n, k;
  {
    up.resize(k);
    iota(up.begin(), up.end(), 0);
    tsize.resize(k, 1);
    size0.resize(k, 1);
    stat.resize(k, false);
    parity.resize(k, 0);
  }
  vector<vector<int>> g(n);
  string s;
  cin, s;
  for (int i = 0; i < (k); i++) {
    int c;
    cin, c;
    vector<int> elems(c);
    cin, elems;
    for (auto &first : elems) {
      first--;
    };
    for (int el : elems) {
      g[el].push_back(i);
    }
  }
  for (int i = 0; i < n; i++) {
    if (((int)g[i].size()) > 1) {
      int a = get_root(g[i][0]);
      int b = get_root(g[i][1]);
      if (a == b) {
        goto after;
      }
      update(a, -1);
      update(b, -1);
      int pa = get_parity(g[i][0]);
      int push_back = get_parity(g[i][1]);
      if (tsize[a] < tsize[b]) {
        swap(a, b);
        swap(pa, push_back);
      }
      if (s[i] == '1') {
        if (pa != push_back) {
          if (!stat[b]) {
            parity[b] ^= 1;
            size0[b] = tsize[b] - size0[b];
          } else {
            assert(!stat[a]);
            parity[a] ^= 1;
            size0[a] = tsize[a] - size0[a];
          }
        }
        parity[b] ^= parity[a];
        up[b] = a;
        tsize[a] += tsize[b];
        size0[a] += size0[b];
        stat[a] = (stat[a] | stat[b]);
      } else {
        if (pa == push_back) {
          if (!stat[b]) {
            if (i == 4) {
            }
            parity[b] ^= 1;
            size0[b] = tsize[b] - size0[b];
          } else {
            assert(!stat[a]);
            parity[a] ^= 1;
            size0[a] = tsize[a] - size0[a];
          }
        }
        parity[b] ^= parity[a];
        up[b] = a;
        tsize[a] += tsize[b];
        size0[a] += size0[b];
        stat[a] = (stat[a] | stat[b]);
      }
      update(a, 1);
    } else {
      if (!g[i].empty()) {
        update(g[i][0], -1);
      }
      if (s[i] == '1') {
        if (!g[i].empty()) {
          int color = get_parity(g[i][0]);
          if (color == 0) {
            invert(get_root(g[i][0]));
          }
          block(g[i][0]);
        }
      } else {
        assert(!g[i].empty());
        int color = get_parity(g[i][0]);
        if (color == 1) {
          invert(get_root(g[i][0]));
        }
        block(g[i][0]);
      }
      if (!g[i].empty()) {
        update(g[i][0], 1);
      }
    }
  after:
    smart_io::precall_print();
    cout, rez;
  }
}

```