import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author masterbios
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        HBinaryMedian solver = new HBinaryMedian();
        solver.solve(1, in, out);
        out.close();
    }

    static class HBinaryMedian {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            try {
                int t = in.nextInt();
                while (t-- > 0) {
                    long n = in.nextLong(), m = in.nextLong();
                    long k = (1L << m) - n, nth = (k - 1) >> 1;
                    long low = 0, high = (1 << m) - 1;
                    long a[] = new long[(int) n];
                    for (int i = 0; i < n; i++) a[i] = Long.parseLong(in.next(), 2);
                    Arrays.sort(a);
                    nth++;
//                out.println("nth=" + nth + " k=" + k);
                    long minus = (1L << 60) + 2, mid = 0;
//                out.println("k=" + k + " nth=" + nth + " low=" + low + " high=" + high);
//                out.println("minus=" + minus + " mid=" + mid);
                    while (low <= high) {
                        mid = low + (high - low) / 2;
                        long get = lowerBound(a, mid);
                        long left = -1;
                        if (get == -1) left = mid + 1;
                        else left = (mid - a[(int) get]) + (a[(int) get] + 1) - (get + 1);
                        if (left < nth) {
                            low = mid + 1;
                        } else if (left == nth) {
                            if (get != -1 && a[(int) get] == mid) high = mid - 1;
                            else break;
                        } else {
                            high = mid - 1;
                        }
                    }
                    nth = mid;
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < m; i++) {
                        if ((nth & (1L << i)) != 0) sb.append("1");
                        else sb.append("0");
                    }
//                out.println(sb.toString());
                    sb.reverse();
                    out.println(sb.toString());
                }
            } catch (IOException e) {

            }
        }

        public long lowerBound(long a[], long find) {
            int low = 0, high = a.length - 1;
            while (low <= high) {
                int mid = low + (high - low) / 2;
                if (a[mid] <= find) {
                    low = mid + 1;
                } else {
                    high = mid - 1;
                }
            }
            return low - 1;
        }

    }

    static class FastReader {
        private byte[] buf = new byte[1024];
        private int index;
        private InputStream in;
        private int total;

        public FastReader(InputStream in) {
            this.in = in;
        }

        public int scan() throws IOException {
            if (total < 0) throw new InputMismatchException();
            if (index >= total) {
                index = 0;
                total = in.read(buf);
                if (total <= 0) return -1;
            }
            return buf[index++];
        }

        public int nextInt() throws IOException {
            int integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                } else {
                    throw new InputMismatchException();
                }
            }
            return neg * integer;
        }

        public long nextLong() throws IOException {
            long number = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            long neg = 1L;
            if (n == '-') {
                neg = -1L;
                n = scan();
            }
            long add = 0L;
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    number *= 10L;
                    add = (n - '0');
                    number += add;
                    n = scan();
                } else {
                    throw new InputMismatchException();
                }
            }
            return neg * number;
        }

        public String next() throws IOException {
            StringBuilder sb = new StringBuilder();
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            while (!isWhiteSpace(n)) {
                sb.append((char) n);
                n = scan();
            }
            return sb.toString();
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            return false;
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author masterbios
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        HBinaryMedian solver = new HBinaryMedian();
        solver.solve(1, in, out);
        out.close();
    }

    static class HBinaryMedian {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            try {
                int t = in.nextInt();
                while (t-- > 0) {
                    long n = in.nextLong(), m = in.nextLong();
                    long k = (1L << m) - n, nth = (k - 1) >> 1;
                    long low = 0, high = (1 << m) - 1;
                    long a[] = new long[(int) n];
                    for (int i = 0; i < n; i++) a[i] = Long.parseLong(in.next(), 2);
                    Arrays.sort(a);
                    while (low <= high) {
                        long mid = low + (high - low) / 2;
                        long left = mid;
                        for (long x : a)
                            if (x <= mid) {
                                left--;
                            }
                        if (left < nth) low = mid + 1;
                        else high = mid - 1;
                    }
                    nth = high + 1;
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < m; i++) {
                        if ((nth & (1L << i)) != 0) sb.append("1");
                        else sb.append("0");
                    }
                    sb.reverse();
                    out.println(sb.toString());
                }
            } catch (IOException e) {

            }
        }

    }

    static class FastReader {
        private byte[] buf = new byte[1024];
        private int index;
        private InputStream in;
        private int total;

        public FastReader(InputStream in) {
            this.in = in;
        }

        public int scan() throws IOException {
            if (total < 0) throw new InputMismatchException();
            if (index >= total) {
                index = 0;
                total = in.read(buf);
                if (total <= 0) return -1;
            }
            return buf[index++];
        }

        public int nextInt() throws IOException {
            int integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                } else {
                    throw new InputMismatchException();
                }
            }
            return neg * integer;
        }

        public long nextLong() throws IOException {
            long number = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            long neg = 1L;
            if (n == '-') {
                neg = -1L;
                n = scan();
            }
            long add = 0L;
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    number *= 10L;
                    add = (n - '0');
                    number += add;
                    n = scan();
                } else {
                    throw new InputMismatchException();
                }
            }
            return neg * number;
        }

        public String next() throws IOException {
            StringBuilder sb = new StringBuilder();
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            while (!isWhiteSpace(n)) {
                sb.append((char) n);
                n = scan();
            }
            return sb.toString();
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            return false;
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.Arrays;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author masterbios
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        HBinaryMedian solver = new HBinaryMedian();
        solver.solve(1, in, out);
        out.close();
    }

    static class HBinaryMedian {
        private boolean oj = System.getProperty("ONLINE_JUDGE") != null;

        public void solve(int testNumber, FastReader in, PrintWriter out) {
            try {
                int t = in.nextInt();
                while (t-- > 0) {
                    long n = in.nextLong(), m = in.nextLong();
                    long k = (1L << m) - n, nth = (k - 1L) >> 1L;
                    long low = 0L, high = (1L << m) - 1L;
                    long a[] = new long[(int) n];
                    for (int i = 0; i < n; i++) a[i] = Long.parseLong(in.next(), 2);
                    Arrays.sort(a);
                    while (low <= high) {
                        long mid = low + (high - low) / 2L;
                        long left = mid;
                        for (long x : a)
                            if (x <= mid) {
                                left--;
                            }
                        if (left < nth) low = mid + 1L;
                        else high = mid - 1L;
                    }
                    nth = high + 1L;
                    StringBuilder sb = new StringBuilder();
                    for (long i = 0L; i < m; i++) {
                        if ((nth & (1L << i)) != 0L) sb.append("1");
                        else sb.append("0");
                    }
                    sb.reverse();
                    out.println(sb.toString());
                    String x = "str";
                    int y = 10;
                    long z = 10L;
                    double rr = 4.4d;
                    debug(x, y, z, rr);
                }
            } catch (IOException e) {

            }
        }

        private void debug(Object... o) {
            if (!oj) {
                System.out.println(Arrays.deepToString(o));
            }
        }

    }

    static class FastReader {
        private byte[] buf = new byte[1024];
        private int index;
        private InputStream in;
        private int total;

        public FastReader(InputStream in) {
            this.in = in;
        }

        public int scan() throws IOException {
            if (total < 0) throw new InputMismatchException();
            if (index >= total) {
                index = 0;
                total = in.read(buf);
                if (total <= 0) return -1;
            }
            return buf[index++];
        }

        public int nextInt() throws IOException {
            int integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                } else {
                    throw new InputMismatchException();
                }
            }
            return neg * integer;
        }

        public long nextLong() throws IOException {
            long number = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            long neg = 1L;
            if (n == '-') {
                neg = -1L;
                n = scan();
            }
            long add = 0L;
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    number *= 10L;
                    add = (n - '0');
                    number += add;
                    n = scan();
                } else {
                    throw new InputMismatchException();
                }
            }
            return neg * number;
        }

        public String next() throws IOException {
            StringBuilder sb = new StringBuilder();
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            while (!isWhiteSpace(n)) {
                sb.append((char) n);
                n = scan();
            }
            return sb.toString();
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            return false;
        }

    }
}


// Problem : H. Binary Median
// Contest : Codeforces - Codeforces Round #644 (Div. 3)
// URL : https://codeforces.com/contest/1360/problem/H
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class a implements Runnable{

    public static void main(String[] args) {
        new Thread(null, new a(), "process", 1<<26).start();
    }
	public void run() {
		FastReader scan = new FastReader();
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
		//PrintWriter out = new PrintWriter("file.out");
		Task solver = new Task();
		int t = scan.nextInt();
		//int t = 1;
		for(int i = 1; i <= t; i++) solver.solve(i, scan, out);
		out.close();
	}

	static class Task {
		static final int inf = Integer.MAX_VALUE;
		int n; int m;
		long[] arr;
		HashSet<Long> hs;
		public void solve(int testNumber, FastReader sc, PrintWriter pw) {
			//CHECK FOR QUICKSORT TLE
			//***********************//
			//CHECK FOR INT OVERFLOW
			//***********************//
			n = sc.nextInt();
			m = sc.nextInt();
			hs = new HashSet<Long>();
			arr = new long[n];
			for(int i = 0; i < n; i++) {
				long t = Long.parseLong(sc.nextLine(), 2);
				hs.add(t);
				arr[i] = t;
			}
			sort(arr);
			long c = search();
			while(hs.contains(c++));
			c--;
			String str = "";
			for(int i = 0; i < m; i++) {
				str = (c%2) + str;
				c>>=1;
			}
			//pw.println(Arrays.toString(arr));
			//pw.println(3 - searc2h(3));
			pw.println(str);
		}

		public long search(){
			long lo = 0, hi = 1l<<62;
			long ind = ((1l<<m)-n-1)/2;
		    for(int i=0;i<70;i++) {
		        long mid = (lo+hi)/2;
		        int x = searc2h(mid);
		        if(mid - x == ind) {
		        	return mid;
		        }
		        if (mid - x < ind) {
		            lo = mid;
		        } else {
		            hi = mid;
		        }
		    }
		    return lo;
		}
		public int searc2h(long a){
			int lo = 0, hi = n;

		    for(int i = 0; i < 33; i ++) {
		        int mid = (lo+hi)/2;
		        if(arr[mid] == a) {
		        	return mid;
		        }

		        if (arr[mid] <= a) {
		            lo = mid;
		        } else {
		            hi = mid;
		        }
		    }
		    if(a < arr[0]) {
		    	return 0;
		    }
		    return lo + 1;
		}
	}
	static long binpow(long a, long b, long m) {
		a %= m;
		long res = 1;
		while (b > 0) {
			if ((b & 1) == 1)
				res = res * a % m;
			a = a * a % m;
			b >>= 1;
		}
		return res;
	}
	static void sort(int[] x){
		shuffle(x);
		Arrays.sort(x);
	}
	static void sort(long[] x){
		shuffle(x);
		Arrays.sort(x);
	}
	static class tup implements Comparable<tup>{
		int a, b;
		tup(int a,int b){
			this.a=a;
			this.b=b;
		}
		@Override
		public int compareTo(tup o){
			return Integer.compare(o.b,b);
		}
	}
	static void shuffle(int[] a) {
		Random get = new Random();
		for (int i = 0; i < a.length; i++) {
			int r = get.nextInt(i + 1);
			int temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}

	static void shuffle(long[] a) {
		Random get = new Random();
		for (int i = 0; i < a.length; i++) {
			int r = get.nextInt(i + 1);
			long temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public FastReader(String s) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(new File(s)));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}


// Problem : H. Binary Median
// Contest : Codeforces - Codeforces Round #644 (Div. 3)
// URL : https://codeforces.com/contest/1360/problem/H
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class a implements Runnable{

    public static void main(String[] args) {
        new Thread(null, new a(), "process", 1<<26).start();
    }
	public void run() {
		FastReader scan = new FastReader();
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
		//PrintWriter out = new PrintWriter("file.out");
		Task solver = new Task();
		int t = scan.nextInt();
		//int t = 1;
		for(int i = 1; i <= t; i++) solver.solve(i, scan, out);
		out.close();
	}

	static class Task {
		static final int inf = Integer.MAX_VALUE;
		int n; int m;
		long[] arr;
		HashSet<Long> hs;
		public void solve(int testNumber, FastReader sc, PrintWriter pw) {
			//CHECK FOR QUICKSORT TLE
			//***********************//
			//CHECK FOR INT OVERFLOW
			//***********************//
			n = sc.nextInt();
			m = sc.nextInt();
			hs = new HashSet<Long>();
			arr = new long[n];
			for(int i = 0; i < n; i++) {
				long t = Long.parseLong(sc.nextLine(), 2);
				hs.add(t);
				arr[i] = t;
			}
			sort(arr);
			long c = search();
			while(hs.contains(c++));
			c--;
			String str = "";
			for(int i = 0; i < m; i++) {
				str = (c%2) + str;
				c>>=1;
			}
			pw.println(str);
		}

		public long search(){
			long lo = 0, hi = 1l<<62;
			long ind = ((1l<<m)-n-1)/2;
		    for(int i=0;i<70;i++) {
		        long mid = (lo+hi)/2;
		        int x = searc2h(mid);
		        if(mid - x == ind) {
		        	return mid;
		        }
		        if (mid - x < ind) {
		            lo = mid;
		        } else {
		            hi = mid;
		        }
		    }
		    return lo;
		}
		public int searc2h(long a){
			int lo = 0, hi = n;

		    for(int i = 0; i < 33; i ++) {
		        int mid = (lo+hi)/2;
		        if(arr[mid] == a) {
		        	return mid;
		        }

		        if (arr[mid] <= a) {
		            lo = mid;
		        } else {
		            hi = mid - 1;
		        }
		    }
		    return lo + 1;
		}
	}
	static long binpow(long a, long b, long m) {
		a %= m;
		long res = 1;
		while (b > 0) {
			if ((b & 1) == 1)
				res = res * a % m;
			a = a * a % m;
			b >>= 1;
		}
		return res;
	}
	static void sort(int[] x){
		shuffle(x);
		Arrays.sort(x);
	}
	static void sort(long[] x){
		shuffle(x);
		Arrays.sort(x);
	}
	static class tup implements Comparable<tup>{
		int a, b;
		tup(int a,int b){
			this.a=a;
			this.b=b;
		}
		@Override
		public int compareTo(tup o){
			return Integer.compare(o.b,b);
		}
	}
	static void shuffle(int[] a) {
		Random get = new Random();
		for (int i = 0; i < a.length; i++) {
			int r = get.nextInt(i + 1);
			int temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}

	static void shuffle(long[] a) {
		Random get = new Random();
		for (int i = 0; i < a.length; i++) {
			int r = get.nextInt(i + 1);
			long temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public FastReader(String s) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(new File(s)));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}


// Problem : H. Binary Median
// Contest : Codeforces - Codeforces Round #644 (Div. 3)
// URL : https://codeforces.com/contest/1360/problem/H
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class a implements Runnable{

    public static void main(String[] args) {
        new Thread(null, new a(), "process", 1<<26).start();
    }
	public void run() {
		FastReader scan = new FastReader();
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
		//PrintWriter out = new PrintWriter("file.out");
		Task solver = new Task();
		int t = scan.nextInt();
		//int t = 1;
		for(int i = 1; i <= t; i++) solver.solve(i, scan, out);
		out.close();
	}

	static class Task {
		static final int inf = Integer.MAX_VALUE;
		int n; int m;
		long[] arr;
		HashSet<Long> hs;
		public void solve(int testNumber, FastReader sc, PrintWriter pw) {
			//CHECK FOR QUICKSORT TLE
			//***********************//
			//CHECK FOR INT OVERFLOW
			//***********************//
			n = sc.nextInt();
			m = sc.nextInt();
			hs = new HashSet<Long>();
			arr = new long[n];
			for(int i = 0; i < n; i++) {
				long t = Long.parseLong(sc.nextLine(), 2);
				hs.add(t);
				arr[i] = t;
			}
			sort(arr);
			long c = search();
			while(hs.contains(c++));
			c--;
			String str = "";
			for(int i = 0; i < m; i++) {
				str = (c%2) + str;
				c>>=1;
			}
			pw.println(str);
		}

		public long search(){
			long lo = 0, hi = 1l<<62;
			long ind = ((1l<<m)-n-1)/2;
		    for(int i=0;i<70;i++) {
		        long mid = (lo+hi)/2;
		        int x = searc2h(mid);
		        if(mid - x == ind) {
		        	return mid;
		        }
		        if (mid - x < ind) {
		            lo = mid;
		        } else {
		            hi = mid;
		        }
		    }
		    return lo;
		}
		public int searc2h(long a){
			int lo = 0, hi = n;

		    for(int i = 0; i < 33; i ++) {
		        int mid = (lo+hi)/2;
		        if(arr[mid] == a) {
		        	return mid;
		        }

		        if (arr[mid] <= a) {
		            lo = mid;
		        } else {
		            hi = mid - 1;
		        }
		    }
		    if(a < arr[0]) {
		    	return 0;
		    }
		    return lo + 1;
		}
	}
	static long binpow(long a, long b, long m) {
		a %= m;
		long res = 1;
		while (b > 0) {
			if ((b & 1) == 1)
				res = res * a % m;
			a = a * a % m;
			b >>= 1;
		}
		return res;
	}
	static void sort(int[] x){
		shuffle(x);
		Arrays.sort(x);
	}
	static void sort(long[] x){
		shuffle(x);
		Arrays.sort(x);
	}
	static class tup implements Comparable<tup>{
		int a, b;
		tup(int a,int b){
			this.a=a;
			this.b=b;
		}
		@Override
		public int compareTo(tup o){
			return Integer.compare(o.b,b);
		}
	}
	static void shuffle(int[] a) {
		Random get = new Random();
		for (int i = 0; i < a.length; i++) {
			int r = get.nextInt(i + 1);
			int temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}

	static void shuffle(long[] a) {
		Random get = new Random();
		for (int i = 0; i < a.length; i++) {
			int r = get.nextInt(i + 1);
			long temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public FastReader(String s) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(new File(s)));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}


import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Round644 {

	static class Reader {
		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		public Reader() {
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public Reader(String file_name) throws IOException {
			din = new DataInputStream(new FileInputStream(file_name));
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public String readLine() throws IOException {
			byte[] buf = new byte[64]; // line length
			int cnt = 0, c;
			while ((c = read()) != -1) {
				if (c == '\n')
					break;
				buf[cnt++] = (byte) c;
			}
			return new String(buf, 0, cnt);
		}

		public int nextInt() throws IOException {
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (neg)
				return -ret;
			return ret;
		}

		public long nextLong() throws IOException {
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public double nextDouble() throws IOException {
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();

			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (c == '.') {
				while ((c = read()) >= '0' && c <= '9') {
					ret += (c - '0') / (div *= 10);
				}
			}

			if (neg)
				return -ret;
			return ret;
		}

		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		private byte read() throws IOException {
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		public void close() throws IOException {
			if (din == null)
				return;
			din.close();
		}
	}

	public static long[] initArray(int n, Reader scan) throws IOException {

		long arr[] = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = scan.nextLong();
		}

		return arr;
	}

	public static long sum(int arr[]) {

		long sum = 0;
		for (int i : arr) {
			sum += (long) i;
		}

		return sum;
	}

	public static int max(int arr[]) {

		int max = Integer.MIN_VALUE;

		for (int i : arr) {
			max = Math.max(i, max);
		}

		return max;
	}

	public static int min(int arr[]) {
		int min = Integer.MAX_VALUE;

		for (int i : arr) {
			min = Math.min(i, min);
		}

		return min;
	}

	public static List<Integer>[] initAdjacency(int n, Reader scan, boolean type) throws IOException{

		List<Integer> adj[]=new ArrayList[n];

		for(int i=0;i<n;i++) {
			int u=scan.nextInt();
			int v=scan.nextInt();

			if(adj[u]==null) adj[u]=new ArrayList<>();
			if(type&&adj[v]==null) adj[v]=new ArrayList<>();

			adj[u].add(v);

			if(type) adj[v].add(u);

		}

		return adj;
	}

	public static void main(String[] args) throws IOException{

		Scanner scan=new Scanner(System.in);
		int t=scan.nextInt();
		while(t-->0) {
			int n=scan.nextInt();
			int m=scan.nextInt();
			String arr[]=new String[n];

			for(int i=0;i<n;i++) {
				arr[i]=scan.next();
			}
			System.out.println(H(n, arr, m));
		}

	}

	public static int A(int l1, int b1, int l2, int b2) {

		int ans1= Math.max(b1+b2, Math.max(l1, l2));

		int ans2= Math.max(l1+l2, Math.max(b1, b2));

		int ans3= Math.max(l1+b2, Math.max(l2, b1));

		int ans4= Math.max(b1+l2, Math.max(l1, b2));

		int val= Math.min(ans1,  Math.min(ans2, Math.min(ans3,  ans4)));

		return val*val;

	}

	public static long B(long arr[], int n) {

		Arrays.sort(arr);

		long min=Integer.MAX_VALUE;
		for(int i=0;i<n-1;i++) {

			min=Math.min(min, arr[i+1]-arr[i]);
		}

		return min;
	}

	public static void C(int n, long arr[]) {

		boolean check=false;

		Arrays.sort(arr);

		int e=0;
		int o=0;

		for(int i=0;i<n;i++) {

			if(arr[i]%2==0) {
				e++;
			}
			else {
				o++;
			}

			if(i!=0) {
				if(arr[i]==arr[i-1]+1) {
					check=true;
				}
			}
		}

		if(e%2==0&&o%2==0) {
			System.out.println("YES");
			return;
		}

		if(check) {
			System.out.println("YES");
			return;
		}

		System.out.println("NO");

	}

	public static long D(long n, long k) {

		if(n<=k) return 1;

		long ans=1;
		for(long i=1;i*i<=n;i++) {

			if(i<=k&&n%i==0) ans=Math.max(ans, i);

			if(n/i<=k&&n%i==0) ans=Math.max(ans,  n/i);

		}

		return n/ans;
	}

	public static void E(String arr[]) {

		for(int i=0;i<arr.length-1;i++) {
			String s=arr[i];
			String s2=arr[i+1];
			for(int j=0;j<s.length()-1;j++) {

				if(s.charAt(j)=='1'&&s.charAt(j+1)=='0'&&s2.charAt(j)=='0') {
					System.out.println("NO");
					return;
				}

			}
		}

		System.out.println("YES");

	}

	public static void F(int n, int m, String arr[]) {

		String s= arr[0];

		outer:for(int i=0;i<s.length();i++) {

			String ref= s.substring(0, i)+"."+s.substring(i+1);

			Set<Integer> ans= match(ref, arr);

			if(ans==null) {
				continue outer;
			}

			char c='.';
			for(Integer x: ans) {

				if(c=='.') {
					c= arr[x].charAt(i);
				}else {

					if(arr[x].charAt(i)!=c) {
						continue outer;
					}
				}
			}

			if(c=='.') c='a';

			System.out.println(s.substring(0,i)+c+s.substring(i+1));
			return;
		}

		System.out.println(-1);

	}

	public static Set<Integer> match(String ref, String arr[]) {

		Set<Integer> strict=new HashSet<>();

		for(int i=1;i<arr.length;i++) {
			String s=arr[i];
			int count=0;
			for(int j=0;j<s.length();j++) {

				if(ref.charAt(j)=='.') continue;
				if(s.charAt(j)!=ref.charAt(j)) {
					count++;
					if(count>1)
						return null;
				}

			}

			if(count==1) {
				strict.add(i);
			}
		}

		return strict;
	}

	public static boolean G(int n, int m, int a, int b, int i, int j, int rowCount[], int colCount[], int matrix[][]) {

		if(j>=m) return false;

		if(i==n) {

			System.out.println("YES");
			for(int x=0;x<n;x++) {
				for(int y=0;y<m;y++) {
					System.out.print(matrix[x][y]);
				}

				System.out.println();
			}

			return true;

		}

		for(int x=j;x<m;x++) {

			if(colCount[x]>=b) continue;

			matrix[i][x]=1;
			rowCount[i]++;
			colCount[x]++;

			boolean recAns= (rowCount[i]==a)? G(n, m, a, b, i+1, 0, rowCount, colCount, matrix): G(n, m, a, b, i, x+1, rowCount, colCount, matrix);

			if(recAns) return true;

			matrix[i][x]=0;
			rowCount[i]--;
			colCount[x]--;

		}

		return false;

	}

	public static String H(int n, String arr[], int m) {

		TreeSet<Long> idx=new TreeSet<>();

		long ind= ((((long)Math.pow(2, m)-(long)arr.length)-1)/2)+1;

		for(String x: arr) {
			long val= getIndex(x, m);
			idx.add(val);
		}

		for(Long x: idx) {

			if(ind<x) {
				return idxToString(ind, m);
			}

			ind++;
		}

		return idxToString(ind, m);

	}

	public static long getIndex(String s, int m) {

		long l=1;
		long h= (long)Math.pow(2, m);
		int k=0;
		while(l<h) {

			long mid= l+(h-l)/2;
			if(s.charAt(k)=='0') {
				h=mid;
			}else {
				l=mid+1;
			}

			k++;
		}

		return l;
	}

	public static String idxToString(long idx, int m) {

		long l=1;
		long h= (long)Math.pow(2, m);

		StringBuilder ans=new StringBuilder("");
		int k=0;
		while(k<m) {

			long mid= l+(h-l)/2;

			if(idx<=mid) {
				ans.append('0');
				h=mid;
			}else {
				ans.append("1");
				l=mid+1;
			}

			k++;
		}

		return ans.toString();

	}
}


import java.io.*;
import java.util.*;
import java.math.*;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class BinaryMedian {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(in.nextInt(), in, out);
        out.close();
    }
    static class TaskA {
        long mod = (long)1e9 + 7;
        public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
            while(testNumber-->0){
            	int n = in.nextInt();
            	int m = in.nextInt();
            	long total = pow(2 , m);
            	long a[] = new long[n];
            	for(int i=0;i<n;i++)
            		a[i] = Long.parseLong(in.next() , 2);
            	Arrays.sort(a);
            	// print1d(a , out);
            	long median = (total+1)/2 - 1;
            	// out.println("median " + median);
            	HashSet<Long> removed = new HashSet<>();
            	for(int i=0;i<n;i++){
            		long x = a[i];
            		removed.add(x);
            		// out.println(removed);
            		if(x<median){
            			if(total%2==1);
	            		else{
	            			while(true){
	            				median++;
	            				if(!removed.contains(median))
	            					break;
	            			}
	            		}
						total--;
            		}
            		else if(x>median){
            			if(total%2 == 1){
            				while(true){
            					median--;
            					if(!removed.contains(median))
            						break;
            				}
            			}
            			//if even nothing to do
            			total--;
            		}
            		else{
            			if(total%2==1){
            				while(true){
            					median--;
            					if(!removed.contains(median))
            						break;
            				}
            			}
            			else{
            				while(true){
            					median++;
            					if(!removed.contains(median))
            						break;
            				}
            			}
            			total--;
            		}
            		// out.println(median);
            	}
            	String ans = Long.toString(median , 2);
            	int remaining = m - ans.length();
            	for(int i=0;i<remaining;i++)
            		out.print('0');
            	out.println(Long.toString(median , 2));
            }
        }
        public void print1d(long a[] , PrintWriter out){
        	for(int i=0;i<a.length;i++)
        		out.print(a[i] + " ");
        	out.println();
        }
        public void print2d(int a[][] , PrintWriter out){
            for(int i=0;i<a.length;i++){
                for(int j=0;j<a[i].length;j++)
                    out.print(a[i][j] + " ");
                out.println();
            }
            out.println();
        }
        public void sieve(int a[]){
            a[0] = a[1] = 1;
            int i;
            for(i=2;i*i<=a.length;i++){
                if(a[i] != 0)
                    continue;
                a[i] = i;
                for(int k = (i)*(i);k<a.length;k+=i){
                    if(a[k] != 0)
                        continue;
                    a[k] = i;
                }
            }
        }
        public int [][] matrixExpo(int c[][] , int n){
            int a[][] = new int[c.length][c[0].length];
            int b[][] = new int[a.length][a[0].length];
            for(int i=0;i<c.length;i++)
                for(int j=0;j<c[0].length;j++)
                    a[i][j] = c[i][j];
            for(int i=0;i<a.length;i++)
                b[i][i] = 1;
            while(n!=1){
                if(n%2 == 1){
                    b = matrixMultiply(a , a);
                    n--;
                }
                a = matrixMultiply(a , a);
                n/=2;
            }
            return matrixMultiply(a , b);
        }
        public int [][] matrixMultiply(int a[][] , int b[][]){
            int r1 = a.length;
            int c1 = a[0].length;
            int c2 = b[0].length;
            int c[][] = new int[r1][c2];
            for(int i=0;i<r1;i++){
                for(int j=0;j<c2;j++){
                    for(int k=0;k<c1;k++)
                        c[i][j] += a[i][k]*b[k][j];
                }
            }
            return c;
        }
        public long nCrPFermet(int n , int r , long p){
            if(r==0)
                return 1l;
            long fact[] = new long[n+1];
            fact[0] = 1;
            for(int i=1;i<=n;i++)
                fact[i] = (i*fact[i-1])%p;
            long modInverseR = pow(fact[r] , p-2 , p);
            long modInverseNR = pow(fact[n-r] , p-2 , p);
            long w = (((fact[n]*modInverseR)%p)*modInverseNR)%p;
            return w;
        }
        public long pow(long a, long b, long m) {
            a %= m;
            long res = 1;
            while (b > 0) {
                long x = b&1;
                if (x == 1)
                    res = res * a % m;
                a = a * a % m;
                b >>= 1;
            }
            return res;
        }
        public long pow(long a, long b) {
            long res = 1;
            while (b > 0) {
                long x = b&1;
                if (x == 1)
                    res = res * a;
                a = a * a;
                b >>= 1;
            }
            return res;
        }
        public void swap(int a[] , int p1 , int p2){
            int x = a[p1];
            a[p1] = a[p2];
            a[p2] = x;
        }
        public void sortedArrayToBST(TreeSet<Integer> a , int start, int end) {
            if (start > end) {
                return;
            }
            int mid = (start + end) / 2;
            a.add(mid);
            sortedArrayToBST(a, start, mid - 1);
            sortedArrayToBST(a, mid + 1, end);
        }
        class Combine{
            int value;
            int delete;
            Combine(int val , int delete){
                this.value = val;
                this.delete = delete;
            }
        }
        class Sort2 implements Comparator<Combine>{
            public int compare(Combine a , Combine b){
                if(a.value > b.value)
                    return 1;
                else if(a.value == b.value && a.delete>b.delete)
                    return 1;
                else if(a.value == b.value && a.delete == b.delete)
                    return 0;
                return -1;
            }
        }
        public int lowerLastBound(ArrayList<Integer> a , int x){
            int l = 0;
            int r = a.size()-1;
            if(a.get(l)>=x)
                return -1;
            if(a.get(r)<x)
                return r;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a.get(mid) == x && a.get(mid-1)<x)
                    return mid-1;
                else if(a.get(mid)>=x)
                    r = mid-1;
                else if(a.get(mid)<x && a.get(mid+1)>=x)
                    return mid;
                else if(a.get(mid)<x && a.get(mid+1)<x)
                    l = mid+1;
            }
            return mid;
        }
        public int upperFirstBound(ArrayList<Integer> a , Integer x){
            int l = 0;
            int r = a.size()-1;
            if(a.get(l)>x)
                return l;
            if(a.get(r)<=x)
                return r+1;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a.get(mid) == x && a.get(mid+1)>x)
                    return mid+1;
                else if(a.get(mid)<=x)
                    l = mid+1;
                else if(a.get(mid)>x && a.get(mid-1)<=x)
                    return mid;
                else if(a.get(mid)>x && a.get(mid-1)>x)
                    r = mid-1;
            }
            return mid;
        }
        public int lowerLastBound(int a[] , int x){
            int l = 0;
            int r = a.length-1;
            if(a[l]>=x)
                return -1;
            if(a[r]<x)
                return r;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a[mid] == x && a[mid-1]<x)
                    return mid-1;
                else if(a[mid]>=x)
                    r = mid-1;
                else if(a[mid]<x && a[mid+1]>=x)
                    return mid;
                else if(a[mid]<x && a[mid+1]<x)
                    l = mid+1;
            }
            return mid;
        }
        public int upperFirstBound(int a[] , int x){
            int l = 0;
            int r = a.length-1;
            if(a[l]>x)
                return l;
            if(a[r]<=x)
                return r+1;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a[mid] == x && a[mid+1]>x)
                    return mid+1;
                else if(a[mid]<=x)
                    l = mid+1;
                else if(a[mid]>x && a[mid-1]<=x)
                    return mid;
                else if(a[mid]>x && a[mid-1]>x)
                    r = mid-1;
            }
            return mid;
        }
        public long log(float number , int base){
            return (long) Math.floor((Math.log(number) / Math.log(base)));
        }
        public long gcd(long a , long b){
            if(a<b){
                long c = b;
                b = a;
                a = c;
            }
            if(b == 0)
                return a;
            return gcd(b , a%b);
        }
        public long[] gcdEx(long p, long q) {
            if (q == 0)
                return new long[] { p, 1, 0 };
            long[] vals = gcdEx(q, p % q);
            long d = vals[0];
            long a = vals[2];
            long b = vals[1] - (p / q) * vals[2];
            // 0->gcd 1->xValue 2->yValue
            return new long[] { d, a, b };
        }
        public void sievePhi(int a[]){
            a[0] = 0;
            a[1] = 1;
            for(int i=2;i<a.length;i++)
                a[i] = i-1;
            for(int i=2;i<a.length;i++)
                for(int j = 2*i;j<a.length;j+=i)
                    a[j] -= a[i];
        }
        public void lcmSum(long a[]){
        	int sievePhi[] = new int[(int)1e6 + 1];
        	sievePhi(sievePhi);
        	a[0] = 0;
        	for(int i=1;i<a.length;i++)
        		for(int j = i;j<a.length;j+=i)
        			a[j] += (long)i*sievePhi[i];
        }
        static class AVLTree{
            Node root;
            public AVLTree(){
                this.root = null;
            }
            public int height(Node n){
                return (n == null ? 0 : n.height);
            }
            public int getBalance(Node n){
                return (n == null ? 0 : height(n.left) - height(n.right));
            }
            public Node rotateRight(Node a){
                Node b = a.left;
                Node br = b.right;

                a.lSum -= b.lSum;
                a.lCount -= b.lCount;

                b.rSum += a.rSum;
                b.rCount += a.rCount;

                b.right = a;
                a.left = br;

                a.height = 1 + Math.max(height(a.left) , height(a.right));
                b.height = 1 + Math.max(height(b.left) , height(b.right));
                return b;
            }
            public Node rotateLeft(Node a){
                Node b = a.right;
                Node bl = b.left;

                a.rSum -= b.rSum;
                a.rCount -= b.rCount;

                b.lSum += a.lSum;
                b.lCount += a.lCount;

                b.left = a;
                a.right = bl;

                a.height = 1 + Math.max(height(a.left) , height(a.right));
                b.height = 1 + Math.max(height(b.left) , height(b.right));
                return b;
            }
            public Node insert(Node root , long value){
                if(root == null){
                    return new Node(value);
                }
                if(value<=root.value){
                    root.lCount++;
                    root.lSum += value;
                    root.left =  insert(root.left , value);
                }
                if(value>root.value){
                    root.rCount++;
                    root.rSum += value;
                    root.right = insert(root.right , value);
                }
                // updating the height of the root
                root.height = 1 + Math.max(height(root.left) , height(root.right));
                int balance = getBalance(root);

                //ll
                if(balance>1 && value<=root.left.value)
                    return rotateRight(root);
                //rr
                if(balance<-1 && value>root.right.value)
                    return rotateLeft(root);
                //lr
                if(balance>1 && value>root.left.value){
                    root.left = rotateLeft(root.left);
                    return rotateRight(root);
                }
                //rl
                if(balance<-1 && value<=root.right.value){
                    root.right = rotateRight(root.right);
                    return rotateLeft(root);
                }
                return root;
            }
            public void insertElement(long value){
                this.root = insert(root , value);
            }
            public int getElementLessThanK(long k){
                int count = 0;
                Node temp = root;
                while(temp!=null){
                    if(temp.value == k){
                        if(temp.left == null || temp.left.value<k){
                            count += temp.lCount;
                            return count-1;
                        }
                        else
                            temp = temp.left;
                    }
                    else if(temp.value>k){
                        temp = temp.left;
                    }
                    else{
                        count += temp.lCount;
                        temp = temp.right;
                    }
                }
                return count;
            }
            public void inorder(Node root , PrintWriter out){
                Node temp = root;
                if(temp!=null){
                    inorder(temp.left , out);
                    out.println(temp.value + " " + temp.lCount + " " + temp.rCount);
                    inorder(temp.right , out);
                }
            }
        }
        static class Node{
            long value;
            long lCount , rCount;
            long lSum , rSum;
            Node left , right;
            int height;
            public Node(long value){
                this.value = value;
                left = null;
                right = null;
                lCount = 1;
                rCount = 1;
                lSum = value;
                rSum = value;
                height = 1;
            }
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;

/*
procrastinating
*/

public class Main {

    static FastReader in;
    static PrintWriter out;
    static Random rand = new Random();
    static final int oo = (int) 2e9;
    static final long OO = (long) 4e18;
    static final int MOD = 998244353;

    static void dbg(Object... args) {
        for (Object a : args)
            out.print(a + " ");
        out.println();
    }

    static int n, m;
    static HashSet<Long> set;

    static long toLong(char[] s) {
        long res = 0;
        for (int i = 0; i < m; i++)
            res |= (s[i] - '0') << (m - 1 - i);
        return res;
    }

    static int fun(long x) {
        int less = 0, more = 0, equal = 0;
        for (long y : set) {
            if (y < x)
                less++;
            else if (y > x)
                more++;
            else
                equal = 1;
        }

        long cnt1 = x - less;
        long cnt2 = (1 << m) - 1 - x - more;

        if (equal == 0) {
            if (cnt1 == cnt2 || cnt1 == cnt2 + 1)
                return 0;
            else if (cnt1 < cnt2)
                return 1;
            else
                return -1;
        } else {
            if (cnt1 == cnt2)
                return -1;
            else if (cnt1 < cnt2)
                return 1;
            else
                return -1;
        }

    }

    static void solve() {
        int t = in.nextInt();

        for (int tt = 0; tt < t; tt++) {
            n = in.nextInt();
            m = in.nextInt();

            set = new HashSet<>();
            for (int i = 0; i < n; i++) {
                long val = toLong(in.next().toCharArray());
                set.add(val);
            }

            long low = 0, high = (1 << m) - 1;
            while (low < high) {
                long mid = (low + high) / 2;
                int f = fun(mid);
                if (f == 1)
                    low = mid + 1;
                else if (f == -1)
                    high = mid - 1;
                else {
                    low = mid;
                    break;
                }
            }

            for (int i = 0; i < m; i++)
                out.print((low & (1 << (m - 1 - i))) == 0 ? 0 : 1);
            out.println();

        }

    }

    public static void main(String[] args) throws FileNotFoundException {
        in = new FastReader(System.in);
//        in = new FastReader(new FileInputStream("sometext.txt"));
        out = new PrintWriter(System.out);
//        out = new PrintWriter(new FileOutputStream("output.txt"));

        solve();

//        Thread thread = new Thread(null, () -> {
//            solve();
//        }, "Main", 1 << 28);
//        thread.start();
//        try {
//            thread.join();
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }

//        out.flush();
        out.close();
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        Integer nextInt() {
            return Integer.parseInt(next());
        }

        Long nextLong() {
            return Long.parseLong(next());
        }

        Double nextDouble() {
            return Double.parseDouble(next());
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(nextLine());
            }
            return st.nextToken();
        }

        String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }
    }

}


/* ****amitm16a2**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define mp          make_pair
using namespace std;
ll atMostSum(vector<ll>arr, ll n, ll k)
{
    ll sum = 0;
    ll cnt = 0, maxcnt = 0;

    for (ll i = 0; i < n; i++) {

        if ((sum + arr[i]) <= k) {
            sum += arr[i];
            cnt++;
        }

        else if(sum!=0)
        {
            sum = sum - arr[i - cnt] + arr[i];
        }

        maxcnt = max(cnt, maxcnt);
    }
    return maxcnt;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll n,m;
	cin>>n>>m;

	ll sum1=0;

	vector<ll>v,ans,u;
	rep(i,0,n){
		ll temp;
		cin>>temp;
		v.pb(temp);
	}

	rep(i,0,n){

		sum1+=v[i];

		if(sum1<=m){
			ans.pb(0);
			u.pb(v[i]);
		}
		else{

			ll diff=n-1-i;
			ll t=atMostSum(u,u.size(),m-v[i])+1;
			u.pb(v[i]);

			ans.pb(n-t-diff);

		}
	}

	rep(i,0,n)
	cout<<ans[i]<<" ";

	return 0;
}


/* ****amitm16a2**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define mp          make_pair
using namespace std;

ll b[101];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll n,m;
	cin>>n>>m;

	ll a[n];
	ll ans[n];

	rep(i,0,n){
		cin>>a[i];

	}

	ll sum=0;

	for(ll i=0; i<n; i++){
		sum+=a[i];

		if(sum<=m){
			ans[i]=0;
			b[a[i]]++;
		}
		else{

			ll find=m-a[i];
			ll sub=0;
			ll count=0;

			for(ll j=1; j<101; j++){

				if(b[j]>0){
					ll t=b[j];
					ll diff=find-sub;

					if(j*b[j]<=diff){
						sub+=j*b[j];
						count+=b[j];
					}
					else{
						ll quo=diff/j;
						sub+=quo*j;
						count+=quo;
						break;
					}

				}
				else
					continue;

			}
			//cout<<count<<endl;
			b[a[i]]++;
			ans[i]=i-count;
		}

	}
	for(ll i=0; i<n; i++)
		cout<<ans[i]<<" ";

	return 0;
}


/* ****amitm16a2**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define mp          make_pair
using namespace std;

ll b[101];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll n,m;
	cin>>n>>m;

	ll a[n];
	ll ans[n];

	rep(i,0,n){
		cin>>a[i];

	}

	ll sum=0;

	for(ll i=0; i<n; i++){
		sum+=a[i];

		if(sum<=m){
			ans[i]=0;
			b[a[i]]++;
		}
		else{

			ll find=m-a[i];
			ll sub=0;
			ll count=0;

			for(ll j=1; j<101; j++){

				if(b[j]>0){
					ll t=b[j];

					while(t--){
					sub+=j;

					if(sub<=find)
					count++;

				    else
				    	break;

					}

				}
				else
					continue;

			}
			//cout<<count<<endl;
			b[a[i]]++;
			ans[i]=i-count;
		}

	}
	for(ll i=0; i<n; i++)
		cout<<ans[i]<<" ";

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef     long long                            ll;
typedef     long long int                        llt;
typedef     unsigned int                         ut;

const llt md = 1000000007; // i.e. pow(10,9) + 7

void disp(llt arr[], llt n){
    llt i;
    i=0;
    //cout<<endl;
    while(i<n){
        cout<<arr[i]<<' ';
        i++;
    }
    //cout<<endl;
    return;
}

void disp_v(vector<llt> &v){
    llt i;
    i=0;
    cout<<endl;
    while(i<v.size()){
        cout<<v[i]<<' ';
        i++;
    }
    cout<<endl;
    return;
}

llt never(llt arr[][2], llt m, llt a, llt b){
    llt i;
    i=0;
    while(i<m){

        if(arr[i][0]!=a && arr[i][1]!=a && arr[i][0]!=b && arr[i][1]!=b){
            return 0;
        }

        i++;
    }
    return 1;
}

llt max(llt a, llt b){
    if(a>b){
        return a;
    }
    return b;
}

llt min(llt a, llt b){
    if(a>b){
        return b;
    }
    return a;
}

llt bin_sch(vector<llt> &v, llt beg, llt end, llt a){
    if(beg>=end){
        return -1;
    }

    llt n;
    n = (beg+end)/2;

    if (v[n]<=a && v[n+1]>a){
        return n;
    }
    else{
        if(v[n]>a){
            return bin_sch(v,beg,n-1,a);
        }
        else{
            return bin_sch(v,n+1,end,a);
        }
    }

}

// 1 4 5 6 8 9
// 0 1 2 3 4 5

int main() {
	llt T,N,M,K,X,i,j,k,x,y,z,q,count,temp,num,sum,times,odd,ans1,ans2,ans3,a,b,c,d,pos,rmg,n,m;

    // vector<vector<llt> > v(n+1);
    // vector<llt> v;
    // int n = sizeof(arr)/sizeof(arr[0]);
    // sort(arr, arr+n);
    // sort(arr, arr+n, greater<int>());
    // sort(v.begin(), v.end());
    // sort(v.begin(), v.end(), greater<int>());
    // vector_name.insert (position, val);
    // vector_name.insert(position, size, val); // how many times do you want to insert : size

    cin>>n>>M;

    llt time[n];
    llt ans[n];
    vector<llt> v;

    i=0;
    while(i<n){
        cin>>time[i];
        ans[i] = -1;
        i++;
    }

    sum = 0;
    times = 0;
    i=0;
    while(i<n){

        // create a vector and push the time into it
        if(i==0){
            // push it into the vector
            v.push_back(time[0]);
            sum = time[0];
            cout<<times<<' ';
        }
        else{

            // sort the vector v in ascending order and find the first numbers whose sum + time[i] < (just less than) M
            // the remaining would have to be failed and store in ans[i]

            // sort(v.begin(), v.end());

            if(sum+time[i]<=M){
                // don't update times and push it into the sorted array

                pos = bin_sch(v,0,v.size()-1,time[i]);

                if(pos==-1){
                    if(v.back()<=time[i]){
                        v.push_back(time[i]);
                    }
                    else{
                        v.insert(v.begin(), time[i]);
                    }
                }
                else{
                    v.insert(v.begin()+pos, time[i]);
                }

                cout<<times<<' ';
                sum = sum+time[i];

            }
            else{

                while(sum+time[i]>M && v.size()>0){
                    // pop from v, and update times and sum
                    sum = sum - v.back();
                    times++;
                    v.pop_back();
                }

                sum = sum+time[i];

                // now push time[i]

                pos = bin_sch(v,0,v.size()-1,time[i]);

                if(pos==-1){
                    if(v.back()<=time[i]){
                        v.push_back(time[i]);
                    }
                    else{
                        v.insert(v.begin(), time[i]);
                    }
                }
                else{
                    v.insert(v.begin()+pos, time[i]);
                }

                cout<<times<<' ';

            }

        }

        i++;
        //disp_v(v);
    }

    //disp(ans,n);

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef     long long                            ll;
typedef     long long int                        llt;
typedef     unsigned int                         ut;

const llt md = 1000000007; // i.e. pow(10,9) + 7

void disp(llt arr[], llt n){
    llt i;
    i=0;
    //cout<<endl;
    while(i<n){
        cout<<arr[i]<<' ';
        i++;
    }
    //cout<<endl;
    return;
}

llt never(llt arr[][2], llt m, llt a, llt b){
    llt i;
    i=0;
    while(i<m){

        if(arr[i][0]!=a && arr[i][1]!=a && arr[i][0]!=b && arr[i][1]!=b){
            return 0;
        }

        i++;
    }
    return 1;
}

llt max(llt a, llt b){
    if(a>b){
        return a;
    }
    return b;
}

llt min(llt a, llt b){
    if(a>b){
        return b;
    }
    return a;
}

int main() {
	llt T,N,M,K,X,i,j,k,x,y,z,q,count,temp,num,times,odd,ans1,ans2,ans3,a,b,c,d,pos,rmg,n,m;

    // vector<vector<llt> > v(n+1);
    // vector<llt> v;
    // int n = sizeof(arr)/sizeof(arr[0]);
    // sort(arr, arr+n);
    // sort(arr, arr+n, greater<int>());
    // sort(v.begin(), v.end());
    // sort(v.begin(), v.end(), greater<int>());
    // vector_name.insert (position, val); // auto it = vec.insert(vec.begin()+1, 3);
    // vector_name.insert(position, size, val); // how many times do you want to insert : size

    cin>>n>>M;

    llt time[n];
    llt ans[n];
    vector<llt> v;

    i=0;
    while(i<n){
        cin>>time[i];
        ans[i] = -1;
        i++;
    }

    i=0;
    while(i<n){

        // create a vector and push the time into it
        if(i==0){
            // push it into the vector
            v.push_back(time[0]);
            ans[0] = 0;
        }
        else{

            // sort the vector v in ascending order and find the first numbers whose sum + time[i] < (just less than) M
            // the remaining would have to be failed and store in ans[i]

            // sort(v.begin(), v.end());

            llt sum;
            sum = time[i];

            j=0;
            while( sum+v[j]<=M && j<v.size() ){

                sum = sum + v[j];

                j++;
            }

            v.insert(v.begin()+j, time[i]);

            ans[i] = v.size() - j - 1; // -1 since time[i] is inserted

            //v.push_back(time[i]);

        }

        i++;
    }

    disp(ans,n);

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef     long long                            ll;
typedef     long long int                        llt;
typedef     unsigned int                         ut;

const int md = 1000000007; // i.e. pow(10,9) + 7

int never(int arr[], int n, int tot, int M){
    int i,times;
    times = 0;
    i=n-1;
    while(i>=0 && tot>M){

        if(arr[i]>0){
            while(arr[i]>0 && tot>M){
                tot = tot - i;
                times++;
                arr[i] = arr[i] - 1;
            }
        }

        i--;
    }
    return times;
}

void copy(int p[], int n[], int N){
    int i=0;
    while(i<N){
        n[i] = p[i];
        i++;
    }
    return;
}

int main() {
	int T,N,M,K,X,i,j,k,x,y,z,q,num,times,odd,tot1,ans1,ans2,ans3,a,b,c,d,pos,rmg,n,m,tot;

    cin>>n>>M;

    int time[n];
    int count[101];
    int temp[101];
    vector<int> v;

    i=0;
    while(i<101){
        count[i] = 0;
        temp[i] = 0;
        i++;
    }

    i=0;
    while(i<n){
        cin>>time[i];
        i++;
    }

    tot = 0;

    i=0;
    while(i<n){
        times = 0;
        if(tot+time[i]<=M){
            cout<<times<<' ';
        }
        else{
            tot1 = tot;
            copy(count,temp,101);
            times = never(temp,101,tot1+time[i],M);
            cout<<times<<' ';
        }
        tot = tot + time[i];
        count[time[i]]++;
        i++;
    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef     long long                            ll;
typedef     long long int                        llt;
typedef     unsigned int                         ut;

const int md = 1000000007; // i.e. pow(10,9) + 7

int never(int arr[], int n, int tot, int M){

    int toget = tot - M;

    int i,times;
    times = 0;
    i=n-1;
    while(i>0 && tot>M){

        if(arr[i]>0){

            int h;
            if(toget%i==0)
                h = (int)(toget/i);
            else
                h = (int)(toget/i)+1;

            if(h<=arr[i]){
                times = times + h;
                return times;
            }
            else{
                toget = toget - (arr[i]*i);
                times = times + arr[i];
                arr[i] = 0;
            }
        }

        i--;
    }
    return times;
}

void copy(int p[], int n[], int N){
    int i=0;
    while(i<N){
        n[i] = p[i];
        i++;
    }
    return;
}

int main() {
	int T,N,M,K,X,i,j,k,x,y,z,q,num,times,odd,tot1,ans1,ans2,ans3,a,b,c,d,pos,rmg,n,m,tot;

    cin>>n>>M;

    int time[n];
    int count[101];
    int temp[101];
    vector<int> v;

    i=0;
    while(i<101){
        count[i] = 0;
        temp[i] = 0;
        i++;
    }

    i=0;
    while(i<n){
        cin>>time[i];
        i++;
    }

    tot = 0;

    i=0;
    while(i<n){
        times = 0;
        if(tot+time[i]<=M){
            cout<<times<<' ';
        }
        else{
            copy(count,temp,101);
            times = never(temp,101,tot+time[i],M);
            cout<<times<<' ';
        }
        tot = tot + time[i];
        count[time[i]]++;
        i++;
    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef     long long                            ll;
typedef     long long int                        llt;
typedef     unsigned int                         ut;

const llt md = 1000000007; // i.e. pow(10,9) + 7

void disp(llt arr[], llt n){
    llt i;
    i=0;
    //cout<<endl;
    while(i<n){
        cout<<arr[i]<<' ';
        i++;
    }
    //cout<<endl;
    return;
}

void disp_v(vector<llt> &v){
    llt i;
    i=0;
    cout<<endl;
    while(i<v.size()){
        cout<<v[i]<<' ';
        i++;
    }
    //cout<<endl;
    return;
}

llt never(llt arr[][2], llt m, llt a, llt b){
    llt i;
    i=0;
    while(i<m){

        if(arr[i][0]!=a && arr[i][1]!=a && arr[i][0]!=b && arr[i][1]!=b){
            return 0;
        }

        i++;
    }
    return 1;
}

llt max(llt a, llt b){
    if(a>b){
        return a;
    }
    return b;
}

llt min(llt a, llt b){
    if(a>b){
        return b;
    }
    return a;
}

llt bin_sch(vector<llt> &v, llt beg, llt end, llt a){
    if(beg>=end){
        return -1;
    }

    llt n;
    n = (beg+end)/2;

    if (v[n]<=a && v[n+1]>a){
        return n;
    }
    else{
        if(v[n]>a){
            return bin_sch(v,beg,n-1,a);
        }
        else{
            return bin_sch(v,n+1,end,a);
        }
    }

}

// 1 4 5 6 8 9
// 0 1 2 3 4 5

int main() {
	llt T,N,M,K,X,i,j,k,x,y,z,q,count,temp,num,sum,times,odd,ans1,ans2,ans3,a,b,c,d,pos,rmg,n,m;

    // vector<vector<llt> > v(n+1);
    // vector<llt> v;
    // int n = sizeof(arr)/sizeof(arr[0]);
    // sort(arr, arr+n);
    // sort(arr, arr+n, greater<int>());
    // sort(v.begin(), v.end());
    // sort(v.begin(), v.end(), greater<int>());
    // vector_name.insert (position, val);
    // vector_name.insert(position, size, val); // how many times do you want to insert : size

    cin>>n>>M;

    llt time[n];
    llt ans[n];
    vector<llt> v;

    i=0;
    while(i<n){
        cin>>time[i];
        ans[i] = -1;
        i++;
    }

    sum = 0;
    times = 0;
    i=0;
    while(i<n){
        //disp_v(v);
        // create a vector and push the time into it
        if(i==0){
            // push it into the vector
            v.push_back(time[0]);
            sum = time[0];
            cout<<times<<' ';
        }
        else{

            // sort the vector v in ascending order and find the first numbers whose sum + time[i] < (just less than) M
            // the remaining would have to be failed and store in ans[i]

            // sort(v.begin(), v.end());

            if(sum+time[i]<=M){
                // don't update times and push it into the sorted array

                pos = bin_sch(v,0,v.size()-1,time[i]);

                if(pos==-1){
                    if(v.back()<=time[i]){
                        v.push_back(time[i]);
                    }
                    else{
                        v.insert(v.begin(), time[i]);
                    }
                }
                else{
                    v.insert(v.begin()+pos, time[i]);
                }

                cout<<times<<' ';
                sum = sum+time[i];

            }
            else{

                while(sum+time[i]>M && v.size()>0){
                    // pop from v, and update times and sum
                    sum = sum - v.back();
                    times++;
                    v.pop_back();
                }

                sum = sum+time[i];

                // now push time[i]

                pos = bin_sch(v,0,v.size()-1,time[i]);

                if(pos==-1){
                    if(v.back()<=time[i]){
                        v.push_back(time[i]);
                    }
                    else{
                        v.insert(v.begin(), time[i]);
                    }
                }
                else{
                    v.insert(v.begin()+pos, time[i]);
                }

                cout<<times<<' ';

            }

        }

        i++;
    }

    //disp(ans,n);

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef     long long                            ll;
typedef     long long int                        llt;
typedef     unsigned int                         ut;

const llt md = 1000000007; // i.e. pow(10,9) + 7

void disp(llt arr[], llt n){
    llt i;
    i=0;
    //cout<<endl;
    while(i<n){
        cout<<arr[i]<<' ';
        i++;
    }
    //cout<<endl;
    return;
}

llt never(llt arr[][2], llt m, llt a, llt b){
    llt i;
    i=0;
    while(i<m){

        if(arr[i][0]!=a && arr[i][1]!=a && arr[i][0]!=b && arr[i][1]!=b){
            return 0;
        }

        i++;
    }
    return 1;
}

llt max(llt a, llt b){
    if(a>b){
        return a;
    }
    return b;
}

llt min(llt a, llt b){
    if(a>b){
        return b;
    }
    return a;
}

int main() {
	llt T,N,M,K,X,i,j,k,s,x,y,z,q,count,temp,num,times,odd,ans1,ans2,ans3,a,pos,rmg,n,m;

    // vector<vector<llt> > v(n+1);
    // vector<llt> v;

    cin>>n>>M;

    llt time[n];
    llt ans[n];
    vector<llt> v;

    i=0;
    while(i<n){
        cin>>time[i];
        ans[i] = -1;
        i++;
    }

    i=0;
    while(i<n){

        // create a vector and push the time into it
        if(i==0){
            // push it into the vector
            v.push_back(time[0]);
            ans[0] = 0;
        }
        else{

            // sort the vector v in ascending order and find the first numbers whose sum + time[i] < (just less than) M
            // the remaining would have to be failed and store in ans[i]

            sort(v.begin(), v.end());

            llt sum;
            sum = time[i];

            j=0;
            while( sum+v[j]<=M && j<v.size() ){

                sum = sum + v[j];

                j++;
            }

            ans[i] = v.size() - j;
            v.push_back(time[i]);

        }

        i++;
    }

    disp(ans,n);

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef     long long                            ll;
typedef     long long int                        llt;
typedef     unsigned int                         ut;

const int md = 1000000007; // i.e. pow(10,9) + 7

void disp(int arr[], int n){
    int i;
    i=0;
    //cout<<endl;
    while(i<n){
        cout<<arr[i]<<' ';
        i++;
    }
    //cout<<endl;
    return;
}

void disp_v(vector<int> &v){
    int i;
    i=0;
    cout<<endl;
    while(i<v.size()){
        cout<<v[i]<<' ';
        i++;
    }
    cout<<endl;
    return;
}

int never(int arr[][2], int m, int a, int b){
    int i;
    i=0;
    while(i<m){

        if(arr[i][0]!=a && arr[i][1]!=a && arr[i][0]!=b && arr[i][1]!=b){
            return 0;
        }

        i++;
    }
    return 1;
}

int max(int a, int b){
    if(a>b){
        return a;
    }
    return b;
}

int min(int a, int b){
    if(a>b){
        return b;
    }
    return a;
}

int bin_sch(vector<int> &v, int beg, int end, int a){
    if(beg>end){
        return -1;
    }
    if(beg==end && beg>=v.size()-1){
        return -1;
    }
    int n;
    n = (beg+end)/2;

    if (v[n]<=a && v[n+1]>a){
        return n;
    }
    else{
        if(v[n]>a){
            return bin_sch(v,beg,n-1,a);
        }
        else{
            return bin_sch(v,n+1,end,a);
        }
    }

}

// 1 4 5 6 8 9
// 0 1 2 3 4 5

int main() {
	int T,N,M,K,X,i,j,k,x,y,z,q,count,temp,num,sum,times,odd,ans1,ans2,ans3,a,b,c,d,pos,rmg,n,m;

    // vector<vector<int> > v(n+1);
    // vector<int> v;
    // int n = sizeof(arr)/sizeof(arr[0]);
    // sort(arr, arr+n);
    // sort(arr, arr+n, greater<int>());
    // sort(v.begin(), v.end());
    // sort(v.begin(), v.end(), greater<int>());
    // vector_name.insert (position, val);
    // vector_name.insert(position, size, val); // how many times do you want to insert : size

    cin>>n>>M;

    int time[n];
    int ans[n];
    vector<int> v;

    i=0;
    while(i<n){
        cin>>time[i];
        ans[i] = -1;
        i++;
    }

    sum = 0;
    times = 0;
    i=0;
    while(i<n){

        // create a vector and push the time into it
        if(i==0){
            // push it into the vector
            v.push_back(time[0]);
            sum = time[0];
            cout<<times<<' ';
        }
        else{

            // sort the vector v in ascending order and find the first numbers whose sum + time[i] < (just less than) M
            // the remaining would have to be failed and store in ans[i]

            // sort(v.begin(), v.end());

            if(sum+time[i]<=M){
                // don't update times and push it into the sorted array

                pos = bin_sch(v,0,v.size()-1,time[i]);
                //cout<<time[i]<<' '<<pos<<endl;
                if(pos==-1){
                    if(v.back()<=time[i]){
                        v.push_back(time[i]);
                    }
                    else{
                        v.insert(v.begin(), time[i]);
                    }
                }
                else{
                    v.insert(v.begin()+pos+1, time[i]);
                }

                cout<<times<<' ';
                sum = sum+time[i];

            }
            else{

                while(sum+time[i]>M && v.size()>0){
                    // pop from v, and update times and sum
                    sum = sum - v.back();
                    times++;
                    v.pop_back();
                }

                sum = sum+time[i];

                // now push time[i]

                pos = bin_sch(v,0,v.size()-1,time[i]);
                //cout<<time[i]<<' '<<pos<<endl;
                if(pos==-1){
                    if(v.back()<=time[i]){
                        v.push_back(time[i]);
                    }
                    else{
                        v.insert(v.begin(), time[i]);
                    }
                }
                else{
                    v.insert(v.begin()+pos+1, time[i]);
                }

                cout<<times<<' ';

            }

        }

        i++;
        //disp_v(v);
    }

    //disp(ans,n);

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef     long long                            ll;
typedef     long long int                        llt;
typedef     unsigned int                         ut;

const int md = 1000000007; // i.e. pow(10,9) + 7

int never(int arr[], int n){
    int i;
    i=n-1;
    while(i>0){

        if(arr[i]>0){
            arr[i]--;
            return i;
        }

        i--;
    }
    return -1;
}

int max(int a, int b){
    if(a>b){
        return a;
    }
    return b;
}

int min(int a, int b){
    if(a>b){
        return b;
    }
    return a;
}

int main() {
	int T,N,M,K,X,i,j,k,x,y,z,q,temp,num,times,odd,ans1,ans2,ans3,a,b,c,d,pos,rmg,n,m,tot;

    cin>>n>>M;

    int time[n];
    int count[101];

    i=0;
    while(i<101){
        count[i] = 0;
        i++;
    }

    i=0;
    while(i<n){
        cin>>time[i];
        i++;
    }

    tot = 0;
    times = 0;
    i=0;
    while(i<n){

        //tot = tot + time[i];

        if(tot+time[i]<=M){
            tot = tot + time[i];
            cout<<times<<' ';
        }
        else{
            while(tot+time[i]>M){
                tot = tot - never(count,101);
                times++;
            }
            tot = tot + time[i];
            cout<<times<<' ';
        }
        count[time[i]]++;
        i++;
    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef     long long                            ll;
typedef     long long int                        llt;
typedef     unsigned int                         ut;

const int md = 1000000007; // i.e. pow(10,9) + 7

void disp(int arr[], int n){
    int i;
    i=0;
    //cout<<endl;
    while(i<n){
        cout<<arr[i]<<' ';
        i++;
    }
    //cout<<endl;
    return;
}

void disp_v(vector<int> &v){
    int i;
    i=0;
    cout<<endl;
    while(i<v.size()){
        cout<<v[i]<<' ';
        i++;
    }
    //cout<<endl;
    return;
}

int never(int arr[][2], int m, int a, int b){
    int i;
    i=0;
    while(i<m){

        if(arr[i][0]!=a && arr[i][1]!=a && arr[i][0]!=b && arr[i][1]!=b){
            return 0;
        }

        i++;
    }
    return 1;
}

int max(int a, int b){
    if(a>b){
        return a;
    }
    return b;
}

int min(int a, int b){
    if(a>b){
        return b;
    }
    return a;
}

int bin_sch(vector<int> &v, int beg, int end, int a){
    if(beg>end){
        return -1;
    }
    if(beg==end && beg>=v.size()-1){
        return -1;
    }
    int n;
    n = (beg+end)/2;

    if (v[n]<=a && v[n+1]>a){
        return n;
    }
    else{
        if(v[n]>a){
            return bin_sch(v,beg,n-1,a);
        }
        else{
            return bin_sch(v,n+1,end,a);
        }
    }

}

int main() {
	int T,N,M,K,X,i,j,k,x,y,z,q,count,temp,num,times,odd,ans1,ans2,ans3,a,b,c,d,pos,rmg,n,m;

    // vector<vector<int> > v(n+1);
    // vector<int> v;
    // int n = sizeof(arr)/sizeof(arr[0]);
    // sort(arr, arr+n);
    // sort(arr, arr+n, greater<int>());
    // sort(v.begin(), v.end());
    // sort(v.begin(), v.end(), greater<int>());
    // vector_name.insert (position, val); // auto it = vec.insert(vec.begin()+1, 3);
    // vector_name.insert(position, size, val); // how many times do you want to insert : size

    cin>>n>>M;

    int time[n];
    int ans[n];
    vector<int> v;

    i=0;
    while(i<n){
        cin>>time[i];
        ans[i] = -1;
        i++;
    }

    i=0;
    while(i<n){

        // create a vector and push the time into it
        if(i==0){
            // push it into the vector
            v.push_back(time[0]);
            ans[0] = 0;
        }
        else{

            // sort the vector v in ascending order and find the first numbers whose sum + time[i] < (just less than) M
            // the remaining would have to be failed and store in ans[i]

            // sort(v.begin(), v.end());

            int sum;
            sum = time[i];

            j=0;
            while( sum+v[j]<=M && j<v.size() ){

                sum = sum + v[j];

                j++;
            }

            ans[i] = v.size() - j;

            pos = bin_sch(v,0,v.size()-1,time[i]);
            //cout<<time[i]<<' '<<pos<<endl;
            if(pos==-1){
                if(v.back()<=time[i]){
                    v.push_back(time[i]);
                }
                else{
                    v.insert(v.begin(), time[i]);
                }
            }
            else{
                v.insert(v.begin()+pos+1, time[i]);
            }

            //v.insert(v.begin()+j, time[i]);

            //v.push_back(time[i]);

        }
        //disp_v(v);
        i++;
    }

    disp(ans,n);

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef     long long                            ll;
typedef     long long int                        llt;
typedef     unsigned int                         ut;

const int md = 1000000007; // i.e. pow(10,9) + 7

int never(int arr[], int n){
    int i;
    i=n-1;
    while(i>=0){

        if(arr[i]>0){
            arr[i] = arr[i] - 1;
            return i;
        }

        i--;
    }
    return -1;
}

void copy(int p[], int n[], int N){
    int i=0;
    while(i<N){
        n[i] = p[i];
        i++;
    }
    return;
}

int main() {
	int T,N,M,K,X,i,j,k,x,y,z,q,num,times,odd,tot1,ans1,ans2,ans3,a,b,c,d,pos,rmg,n,m,tot;

    cin>>n>>M;

    int time[n];
    int count[101];
    int temp[101];
    vector<int> v;

    i=0;
    while(i<101){
        count[i] = 0;
        temp[i] = 0;
        i++;
    }

    i=0;
    while(i<n){
        cin>>time[i];
        i++;
    }

    tot = 0;

    i=0;
    while(i<n){
        times = 0;
        if(tot+time[i]<=M){

            cout<<times<<' ';
        }
        else{
            tot1 = tot;
            copy(count,temp,101);
            while(tot1+time[i]>M){
                tot1 = tot1 - never(temp,101);
                times++;
            }
            cout<<times<<' ';
        }
        tot = tot + time[i];
        count[time[i]]++;
        i++;
    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef     long long                            ll;
typedef     long long int                        llt;
typedef     unsigned int                         ut;

const llt md = 1000000007; // i.e. pow(10,9) + 7

void disp(llt arr[], llt n){
    llt i;
    i=0;
    //cout<<endl;
    while(i<n){
        cout<<arr[i]<<' ';
        i++;
    }
    //cout<<endl;
    return;
}

llt never(llt arr[][2], llt m, llt a, llt b){
    llt i;
    i=0;
    while(i<m){

        if(arr[i][0]!=a && arr[i][1]!=a && arr[i][0]!=b && arr[i][1]!=b){
            return 0;
        }

        i++;
    }
    return 1;
}

llt max(llt a, llt b){
    if(a>b){
        return a;
    }
    return b;
}

llt min(llt a, llt b){
    if(a>b){
        return b;
    }
    return a;
}

int main() {
	llt T,N,M,K,X,i,j,k,x,y,z,q,count,temp,num,times,odd,ans1,ans2,ans3,a,b,c,d,pos,rmg,n,m;

    // vector<vector<llt> > v(n+1);
    // vector<llt> v;
    // int n = sizeof(arr)/sizeof(arr[0]);
    // sort(arr, arr+n);
    // sort(arr, arr+n, greater<int>());
    // sort(v.begin(), v.end());
    // sort(v.begin(), v.end(), greater<int>());
    // vector_name.insert (position, val); // auto it = vec.insert(vec.begin()+1, 3);
    // vector_name.insert(position, size, val); // how many times do you want to insert : size

    cin>>n>>M;

    llt time[n];
    llt ans[n];
    vector<llt> v;

    i=0;
    while(i<n){
        cin>>time[i];
        ans[i] = -1;
        i++;
    }

    i=0;
    while(i<n){

        // create a vector and push the time into it
        if(i==0){
            // push it into the vector
            v.push_back(time[0]);
            ans[0] = 0;
        }
        else{

            // sort the vector v in ascending order and find the first numbers whose sum + time[i] < (just less than) M
            // the remaining would have to be failed and store in ans[i]

            // sort(v.begin(), v.end());

            llt sum;
            sum = time[i];

            j=0;
            while( sum+v[j]<=M && j<v.size() ){

                sum = sum + v[j];

                j++;
            }

            ans[i] = v.size() - j;
            v.insert(v.begin()+j, time[i]);
            //v.push_back(time[i]);

        }

        i++;
    }

    disp(ans,n);

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef     long long                            ll;
typedef     long long int                        llt;
typedef     unsigned int                         ut;

const int md = 1000000007; // i.e. pow(10,9) + 7

int never(int arr[], int n){
    int i;
    i=n-1;
    while(i>=0){

        if(arr[i]>0){
            arr[i]--;
            return i;
        }

        i--;
    }
    return -1;
}

int main() {
	int T,N,M,K,X,i,j,k,x,y,z,q,temp,num,times,odd,ans1,ans2,ans3,a,b,c,d,pos,rmg,n,m,tot;

    cin>>n>>M;

    int time[n];
    int count[101];
    vector<int> v;

    i=0;
    while(i<101){
        count[i] = 0;
        i++;
    }

    i=0;
    while(i<n){
        cin>>time[i];
        i++;
    }

    tot = 0;
    times = 0;
    i=0;
    while(i<n){
        if(tot+time[i]<=M){
            tot = tot + time[i];
            cout<<times<<' ';
        }
        else{
            while(tot+time[i]>M){
                if(never(count,101)!=-1){
                    tot = tot - never(count,101);
                    times++;
                }
            }
            tot = tot + time[i];
            cout<<times<<' ';
        }
        count[time[i]]++;
        i++;
    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

typedef     long long                            ll;
typedef     long long int                        llt;
typedef     unsigned int                         ut;

const llt md = 1000000007; // i.e. pow(10,9) + 7

void disp(llt arr[], llt n){
    llt i;
    i=0;
    //cout<<endl;
    while(i<n){
        cout<<arr[i]<<' ';
        i++;
    }
    //cout<<endl;
    return;
}

llt never(llt arr[][2], llt m, llt a, llt b){
    llt i;
    i=0;
    while(i<m){

        if(arr[i][0]!=a && arr[i][1]!=a && arr[i][0]!=b && arr[i][1]!=b){
            return 0;
        }

        i++;
    }
    return 1;
}

llt max(llt a, llt b){
    if(a>b){
        return a;
    }
    return b;
}

llt min(llt a, llt b){
    if(a>b){
        return b;
    }
    return a;
}

int main() {
	llt T,N,M,K,X,i,j,k,s,x,y,z,q,count,temp,num,times,odd,ans1,ans2,ans3,a,pos,rmg,n,m;

    // vector<vector<llt> > v(n+1);
    // vector<llt> v;

    cin>>n>>M;

    llt time[n];
    llt ans[n];
    vector<llt> v;

    i=0;
    while(i<n){
        cin>>time[i];
        ans[i] = -1;
        i++;
    }

    i=0;
    while(i<n){

        // create a vector and push the time into it
        if(i==0){
            // push it into the vector
            v.push_back(time[0]);
            ans[0] = 0;
        }
        else{

            // sort the vector v in ascending order and find the first numbers whose sum + time[i] < (just less than) M
            // the remaining would have to be failed and store in ans[i]

            sort(v.begin(), v.end());

            llt sum;
            sum = time[i];

            j=0;
            while( sum+v[j]<=M && j<v.size() ){

                sum = sum + v[j];

                j++;
            }

            ans[i] = v.size() - j;
            v.push_back(time[i]);

        }

        i++;
    }

    disp(ans,n);

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef     long long                            ll;
typedef     long long int                        llt;
typedef     unsigned int                         ut;

const int md = 1000000007; // i.e. pow(10,9) + 7

void disp(int arr[], int n){
    int i;
    i=0;
    cout<<endl;
    while(i<n){
        cout<<arr[i]<<' ';
        i++;
    }
    cout<<endl;
    return;
}

void disp_v(vector<int> &v){
    int i;
    i=0;
    cout<<endl;
    while(i<v.size()){
        cout<<v[i]<<' ';
        i++;
    }
    cout<<endl;
    return;
}

int never(int arr[], int n){
    int i;
    i=n-1;
    while(i>=0){

        if(arr[i]>0){
            arr[i]--;
            return i;
        }

        i--;
    }
    return -1;
}

int max(int a, int b){
    if(a>b){
        return a;
    }
    return b;
}

int min(int a, int b){
    if(a>b){
        return b;
    }
    return a;
}

int bin_sch(vector<int> &v, int beg, int end, int a){
    if(beg>end){
        return -1;
    }
    if(beg==end && beg>=v.size()-1){
        return -1;
    }
    int n;
    n = (beg+end)/2;

    if (v[n]<=a && v[n+1]>a){
        return n;
    }
    else{
        if(v[n]>a){
            return bin_sch(v,beg,n-1,a);
        }
        else{
            return bin_sch(v,n+1,end,a);
        }
    }

}

int main() {
	int T,N,M,K,X,i,j,k,x,y,z,q,temp,num,times,odd,ans1,ans2,ans3,a,b,c,d,pos,rmg,n,m,tot;
	/*
    // vector<vector<int> > v(n+1);
    // vector<int> v;
    // int n = sizeof(arr)/sizeof(arr[0]);
    // sort(arr, arr+n);
    // sort(arr, arr+n, greater<int>());
    // sort(v.begin(), v.end());
    // sort(v.begin(), v.end(), greater<int>());
    // vector_name.insert (position, val); // auto it = vec.insert(vec.begin()+1, 3);
    // vector_name.insert(position, size, val); // how many times do you want to insert : size
    */

    cin>>n>>M;

    int time[n];
    int count[101];
    vector<int> v;

    i=0;
    while(i<101){
        count[i] = 0;
        i++;
    }

    i=0;
    while(i<n){
        cin>>time[i];
        i++;
    }

    tot = 0;
    times = 0;
    i=0;
    while(i<n){

        //tot = tot + time[i];

        if(tot+time[i]<=M){
            tot = tot + time[i];
            cout<<times<<' ';
        }
        else{
            while(tot+time[i]>M){
                tot = tot - never(count,101);
                times++;
            }
            tot = tot + time[i];
            cout<<times<<' ';
        }
        //disp(count,101);
        count[time[i]]++;
        i++;
    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef     long long                            ll;
typedef     long long int                        llt;
typedef     unsigned int                         ut;

const int md = 1000000007; // i.e. pow(10,9) + 7

void disp(int arr[], int n){
    int i;
    i=0;
    //cout<<endl;
    while(i<n){
        cout<<arr[i]<<' ';
        i++;
    }
    //cout<<endl;
    return;
}

void disp_v(vector<int> &v){
    int i;
    i=0;
    cout<<endl;
    while(i<v.size()){
        cout<<v[i]<<' ';
        i++;
    }
    //cout<<endl;
    return;
}

int never(int arr[][2], int m, int a, int b){
    int i;
    i=0;
    while(i<m){

        if(arr[i][0]!=a && arr[i][1]!=a && arr[i][0]!=b && arr[i][1]!=b){
            return 0;
        }

        i++;
    }
    return 1;
}

int max(int a, int b){
    if(a>b){
        return a;
    }
    return b;
}

int min(int a, int b){
    if(a>b){
        return b;
    }
    return a;
}

int bin_sch(vector<int> &v, int beg, int end, int a){
    if(beg>end){
        return -1;
    }
    if(beg==end && beg>=v.size()-1){
        return -1;
    }
    int n;
    n = (beg+end)/2;

    if (v[n]<=a && v[n+1]>a){
        return n;
    }
    else{
        if(v[n]>a){
            return bin_sch(v,beg,n-1,a);
        }
        else{
            return bin_sch(v,n+1,end,a);
        }
    }

}

int main() {
	int T,N,M,K,X,i,j,k,x,y,z,q,count,temp,num,times,odd,ans1,ans2,ans3,a,b,c,d,pos,rmg,n,m,tot;
	/*
    // vector<vector<int> > v(n+1);
    // vector<int> v;
    // int n = sizeof(arr)/sizeof(arr[0]);
    // sort(arr, arr+n);
    // sort(arr, arr+n, greater<int>());
    // sort(v.begin(), v.end());
    // sort(v.begin(), v.end(), greater<int>());
    // vector_name.insert (position, val); // auto it = vec.insert(vec.begin()+1, 3);
    // vector_name.insert(position, size, val); // how many times do you want to insert : size
    */

    cin>>n>>M;

    int time[n];
    int ans[n];
    vector<int> v;

    i=0;
    while(i<n){
        cin>>time[i];
        ans[i] = -1;
        i++;
    }

    tot = 0;

    i=0;
    while(i<n){

        // create a vector and push the time into it
        if(i==0){
            // push it into the vector
            v.push_back(time[0]);
            tot = time[0];
            ans[0] = 0;
        }
        else{

            // sort the vector v in ascending order and find the first numbers whose sum + time[i] < (just less than) M
            // the remaining would have to be failed and store in ans[i]

            // sort(v.begin(), v.end());

            /*
            int sum;
            sum = time[i];
            j=0;
            while( sum+v[j]<=M && j<v.size() ){

                sum = sum + v[j];

                j++;
            }
            */

            j = v.size()-1;
            temp = tot;
            while(temp+time[i]>M && j>=0){
                temp = temp - v[j];
                j--;
            }

            //ans[i] = v.size() - j;
            ans[i] = v.size() - 1 - j;

            pos = bin_sch(v,0,v.size()-1,time[i]);
            //cout<<time[i]<<' '<<pos<<endl;
            if(pos==-1){
                if(v.back()<=time[i]){
                    v.push_back(time[i]);
                }
                else{
                    v.insert(v.begin(), time[i]);
                }
            }
            else{
                v.insert(v.begin()+pos+1, time[i]);
            }

            tot = tot + time[i];

            //v.insert(v.begin()+j, time[i]);

            //v.push_back(time[i]);

        }
        //disp_v(v);
        //cout<<"tot = "<<tot<<endl;
        i++;
    }

    disp(ans,n);

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef     long long                            ll;
typedef     long long int                        llt;
typedef     unsigned int                         ut;

const llt md = 1000000007; // i.e. pow(10,9) + 7

void disp(llt arr[], llt n){
    llt i;
    i=0;
    //cout<<endl;
    while(i<n){
        cout<<arr[i]<<' ';
        i++;
    }
    //cout<<endl;
    return;
}

void disp_v(vector<llt> &v){
    llt i;
    i=0;
    cout<<endl;
    while(i<v.size()){
        cout<<v[i]<<' ';
        i++;
    }
    cout<<endl;
    return;
}

llt never(llt arr[][2], llt m, llt a, llt b){
    llt i;
    i=0;
    while(i<m){

        if(arr[i][0]!=a && arr[i][1]!=a && arr[i][0]!=b && arr[i][1]!=b){
            return 0;
        }

        i++;
    }
    return 1;
}

llt max(llt a, llt b){
    if(a>b){
        return a;
    }
    return b;
}

llt min(llt a, llt b){
    if(a>b){
        return b;
    }
    return a;
}

llt bin_sch(vector<llt> &v, llt beg, llt end, llt a){
    if(beg>end){
        return -1;
    }
    if(beg==end && beg>=v.size()-1){
        return -1;
    }
    llt n;
    n = (beg+end)/2;

    if (v[n]<=a && v[n+1]>a){
        return n;
    }
    else{
        if(v[n]>a){
            return bin_sch(v,beg,n-1,a);
        }
        else{
            return bin_sch(v,n+1,end,a);
        }
    }

}

// 1 4 5 6 8 9
// 0 1 2 3 4 5

int main() {
	llt T,N,M,K,X,i,j,k,x,y,z,q,count,temp,num,sum,times,odd,ans1,ans2,ans3,a,b,c,d,pos,rmg,n,m;

    // vector<vector<llt> > v(n+1);
    // vector<llt> v;
    // int n = sizeof(arr)/sizeof(arr[0]);
    // sort(arr, arr+n);
    // sort(arr, arr+n, greater<int>());
    // sort(v.begin(), v.end());
    // sort(v.begin(), v.end(), greater<int>());
    // vector_name.insert (position, val);
    // vector_name.insert(position, size, val); // how many times do you want to insert : size

    cin>>n>>M;

    llt time[n];
    llt ans[n];
    vector<llt> v;

    i=0;
    while(i<n){
        cin>>time[i];
        ans[i] = -1;
        i++;
    }

    sum = 0;
    times = 0;
    i=0;
    while(i<n){

        // create a vector and push the time into it
        if(i==0){
            // push it into the vector
            v.push_back(time[0]);
            sum = time[0];
            cout<<times<<' ';
        }
        else{

            // sort the vector v in ascending order and find the first numbers whose sum + time[i] < (just less than) M
            // the remaining would have to be failed and store in ans[i]

            // sort(v.begin(), v.end());

            if(sum+time[i]<=M){
                // don't update times and push it into the sorted array

                pos = bin_sch(v,0,v.size()-1,time[i]);
                //cout<<time[i]<<' '<<pos<<endl;
                if(pos==-1){
                    if(v.back()<=time[i]){
                        v.push_back(time[i]);
                    }
                    else{
                        v.insert(v.begin(), time[i]);
                    }
                }
                else{
                    v.insert(v.begin()+pos+1, time[i]);
                }

                cout<<times<<' ';
                sum = sum+time[i];

            }
            else{

                while(sum+time[i]>M && v.size()>0){
                    // pop from v, and update times and sum
                    sum = sum - v.back();
                    times++;
                    v.pop_back();
                }

                sum = sum+time[i];

                // now push time[i]

                pos = bin_sch(v,0,v.size()-1,time[i]);
                //cout<<time[i]<<' '<<pos<<endl;
                if(pos==-1){
                    if(v.back()<=time[i]){
                        v.push_back(time[i]);
                    }
                    else{
                        v.insert(v.begin(), time[i]);
                    }
                }
                else{
                    v.insert(v.begin()+pos+1, time[i]);
                }

                cout<<times<<' ';

            }

        }

        i++;
        //disp_v(v);
    }

    //disp(ans,n);

	return 0;
}