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. 
/**
 * BaZ :D
 */

import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main
{
    static MyScanner scan;
    static PrintWriter pw;
    static long MOD = 1_000_000_007;
    static long INF = 1_000_000_000_000_000_000L;
    static long inf = 2_000_000_000;
    public static void main(String[] args) {
        new Thread(null, null, "BaZ", 1 << 27) {
            public void run() {
                try {
                    solve();
                } catch (Exception e) {
                    e.printStackTrace();
                    System.exit(1);
                }
            }
        }.start();
    }
    static int color[], baap[], weight[], red_count[], blue_count[], forced[],ans = 0;
    static ArrayList<Pair> adj[];
    static void solve() throws IOException
    {
        //initIo(true);
        initIo(false);
        StringBuilder sb = new StringBuilder();
        int n = ni(), k = ni();
        char c[] = ne().toCharArray();
        int which[][] = new int[n+1][2];
        for(int i=0;i<=n;++i) {
            which[i][0] = which[i][1] = -1;
        }
        for(int i=0;i<k;++i) {
            int cnt = ni();
            for(int j=0;j<cnt;++j) {
                int x = ni();
                if(which[x][0] == -1) {
                    which[x][0] = i;
                }
                else {
                    which[x][1] = i;
                }
            }
        }

        adj = new ArrayList[k];
        for(int i=0;i<k;++i) {
            adj[i] = new ArrayList<>();
        }
        for(int i=1;i<=n;++i) {
            if(which[i][0] != -1 && which[i][1] != -1) {
                int u = which[i][0], v = which[i][1];
                //pl(u+" "+v + " " + c[i-1]);
                if(c[i-1] == '1') {
                    adj[u].add(new Pair(v, 0));
                    adj[v].add(new Pair(u, 0));
                }
                else {
                    adj[u].add(new Pair(v, 1));
                    adj[v].add(new Pair(u, 1));
                }
            }
        }

        color = new int[k];
        Arrays.fill(color, -1);
        for(int i=0;i<k;++i) {
            if(color[i] == -1) {
                color[i] = 0;
                dfs(i);
            }
        }
        //pa("color", color);

        init((k-1));


        for(int i=1;i<=n;++i) {
            //pl("i : "+i+" "+which[i][0]+" "+which[i][1]);
            if(which[i][0] != -1 && which[i][1] != -1) {
                un(which[i][0], which[i][1]);
            }
            else if(which[i][0] != -1) {
                int root = gr(which[i][0]);
                if(c[i-1] == '0') {
                    ans-=(forced[root] == -1 ? min(red_count[root], blue_count[root]) : forced[root] == 0 ? red_count[root] : blue_count[root]);
                    forced[root] = color[which[i][0]];
                    ans+=(forced[root] == -1 ? min(red_count[root], blue_count[root]) : forced[root] == 0 ? red_count[root] : blue_count[root]);
                }
                else {
                    ans-=(forced[root] == -1 ? min(red_count[root], blue_count[root]) : forced[root] == 0 ? red_count[root] : blue_count[root]);
                    forced[root] = 1 - color[which[i][0]];
                    ans+=(forced[root] == -1 ? min(red_count[root], blue_count[root]) : forced[root] == 0 ? red_count[root] : blue_count[root]);
                }
            }
            pl(ans);
        }

        pw.flush();
        pw.close();
    }
    static void init(int n)
    {
        baap = new int[n+1];
        weight = new int[n+1];
        red_count = new int[n+1];
        blue_count = new int[n+1];
        forced = new int[n+1];
        for(int i=0;i<=n;++i)
        {
            baap[i] = i;
            ++weight[i];
            if(color[i] == 1) {
                blue_count[i] = 1;
            }
            else {
                red_count[i] = 1;
            }
            forced[i] = -1;
        }
    }
    static int gr(int a)
    {
        if(baap[a]==a)
            return a;
        return baap[a] = gr(baap[a]);
    }
    static boolean un(int a,int b)
    {
        int ra = gr(a);
        int rb = gr(b);
        if(ra==rb)
            return false;
        ans-=(forced[ra] == -1 ? min(red_count[ra], blue_count[ra]) : forced[ra] == 0 ? red_count[ra] : blue_count[ra]);
        ans-=(forced[rb] == -1 ? min(red_count[rb], blue_count[rb]) : forced[rb] == 0 ? red_count[rb] : blue_count[rb]);
        if(weight[rb]>weight[ra])
        {
            weight[rb]+=weight[ra];
            baap[ra] = rb;
            blue_count[rb]+=blue_count[ra];
            red_count[rb]+=red_count[ra];
            if(forced[rb] == -1) {
                forced[rb] = forced[ra];
            }
            ans+=(forced[rb] == -1 ? min(red_count[rb], blue_count[rb]) : forced[rb] == 0 ? red_count[rb] : blue_count[rb]);
        }
        else
        {
            weight[ra]+=weight[rb];
            baap[rb] = ra;
            blue_count[ra]+=blue_count[rb];
            red_count[ra]+=red_count[rb];
            if(forced[ra] == -1) {
                forced[ra] = forced[rb];
            }
            ans+=(forced[ra] == -1 ? min(red_count[ra], blue_count[ra]) : forced[ra] == 0 ? red_count[ra] : blue_count[ra]);
        }
        return true;
    }

    static void dfs(int v) {
        for(Pair p : adj[v]) {
            if(color[p.x] == -1) {
                color[p.x] = (color[v] ^ p.y);
                dfs(p.x);
            }
        }
    }

    static class Pair implements Comparable<Pair>
    {
        int x,y;
        Pair(int x,int y)
        {
            this.x=x;
            this.y=y;
        }
        public int compareTo(Pair other)
        {
            if(this.x!=other.x)
                return this.x-other.x;
            return this.y-other.y;
        }
        public String toString()
        {
            return "("+x+","+y+")";
        }
    }
    static void initIo(boolean isFileIO) throws IOException {
        scan = new MyScanner(isFileIO);
        if(isFileIO) {
            pw = new PrintWriter("/Users/amandeep/Desktop/output.txt");
        }
        else {
            pw = new PrintWriter(System.out, true);
        }
    }
    static int ni() throws IOException
    {
        return scan.nextInt();
    }
    static long nl() throws IOException
    {
        return scan.nextLong();
    }
    static double nd() throws IOException
    {
        return scan.nextDouble();
    }
    static String ne() throws IOException
    {
        return scan.next();
    }
    static String nel() throws IOException
    {
        return scan.nextLine();
    }
    static void pl()
    {
        pw.println();
    }
    static void p(Object o)
    {
        pw.print(o+" ");
    }
    static void pl(Object o)
    {
        pw.println(o);
    }
    static void psb(StringBuilder sb)
    {
        pw.print(sb);
    }
    static void pa(String arrayName, Object arr[])
    {
        pl(arrayName+" : ");
        for(Object o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, int arr[])
    {
        pl(arrayName+" : ");
        for(int o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, long arr[])
    {
        pl(arrayName+" : ");
        for(long o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, double arr[])
    {
        pl(arrayName+" : ");
        for(double o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, char arr[])
    {
        pl(arrayName+" : ");
        for(char o : arr)
            p(o);
        pl();
    }
    static void pa(String listName, List list)
    {
        pl(listName+" : ");
        for(Object o : list)
            p(o);
        pl();
    }
    static void pa(String arrayName, Object[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(Object o : arr[i])
                p(o);
            pl();
        }
    }
    static void pa(String arrayName, int[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(int o : arr[i])
                p(o);
            pl();
        }
    }
    static void pa(String arrayName, long[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(long o : arr[i])
                p(o);
            pl();
        }
    }
    static void pa(String arrayName, char[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(char o : arr[i])
                p(o);
            pl();
        }
    }
    static void pa(String arrayName, double[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(double o : arr[i])
                p(o);
            pl();
        }
    }
    static class MyScanner
    {
        BufferedReader br;
        StringTokenizer st;
        MyScanner(boolean readingFromFile) throws IOException
        {
            if(readingFromFile) {
                br = new BufferedReader(new FileReader("/Users/amandeep/Desktop/input.txt"));
            }
            else {
                br = new BufferedReader(new InputStreamReader(System.in));
            }
        }
        String nextLine()throws IOException
        {
            return br.readLine();
        }
        String next() throws IOException
        {
            if(st==null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }
        int nextInt() throws IOException
        {
            return Integer.parseInt(next());
        }
        long nextLong() throws IOException
        {
            return Long.parseLong(next());
        }
        double nextDouble() throws IOException
        {
            return Double.parseDouble(next());
        }
    }
}