import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class BEquivalentStrings {
        char[] first;
        char[] second;

        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            first = sc.next().toCharArray();
            second = sc.next().toCharArray();
            pw.println(isEquivalent(0, first.length - 1, 0, second.length - 1) ? "YES" : "NO");
        }

        private boolean isEquivalent(int i, int j, int b, int e) {
            if (i == j)
                return first[i] == second[b];
            if (isEqual(i, j, b, e))
                return true;
            if ((j - i + 1) % 2 == 1)
                return false;
            int firstMid = (i + j) / 2;
            int secondMid = (b + e) / 2;
            return (isEquivalent(i, firstMid, b, secondMid) && isEquivalent(firstMid + 1, j, secondMid + 1, e)) || (isEquivalent(i, firstMid, secondMid + 1, e) && isEquivalent(firstMid + 1, j, b, secondMid));
        }

        private boolean isEqual(int i, int j, int b, int e) {
            while (i <= j) {
                if (first[i] != second[b])
                    return false;
                i++;
                b++;
            }
            return true;
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class BEquivalentStrings {
        char[] first;
        char[] second;
        long[] pow;
        long[] hash;

        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            first = sc.next().toCharArray();
            second = sc.next().toCharArray();
            preProcess();
            pw.println(isEquivalent(0, first.length - 1, 0, second.length - 1) ? "YES" : "NO");
        }

        private void preProcess() {
            pow = new long[first.length + second.length + 1];
            hash = new long[first.length + second.length + 1];
            pow[0] = 1;
            int p = 37;
            for (int i = 1; i < pow.length; i++) {
                int add = (i - 1) < first.length ? first[i - 1] : second[i - first.length - 1];
                hash[i] = (hash[i - 1] * p + add);
                pow[i] = (pow[i - 1] * p);
            }
        }

        private boolean isEquivalent(int i, int j, int b, int e) {
            if (i == j)
                return first[i] == second[b];
            if (isEqual(i, j, b, e))
                return true;
            if ((j - i + 1) % 2 == 1 || !isAnagram(i, j, b, e))
                return false;
            int firstMid = (i + j) / 2;
            int secondMid = (b + e) / 2;
            return (isEquivalent(i, firstMid, b, secondMid) && isEquivalent(firstMid + 1, j, secondMid + 1, e)) || (isEquivalent(i, firstMid, secondMid + 1, e) && isEquivalent(firstMid + 1, j, b, secondMid));
        }

        private boolean isAnagram(int i, int j, int b, int e) {
            int[] freq = new int[26];
            while (i <= j) {
                freq[first[i] - 'a']--;
                freq[second[b] - 'a']++;
                i++;
                b++;
            }
            for (int x : freq)
                if (x != 0)
                    return false;
            return true;
        }

        private boolean isEqual(int i, int j, int b, int e) {
            return hash[j + 1] - hash[i] * pow[j - i + 1] == hash[first.length + e + 1] - hash[first.length + b] * pow[e - b + 1];
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class BEquivalentStrings {
        char[] first;
        char[] second;
        long mod = (long) 1e9 + 9;
        long[] pow;
        long[] hash;

        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            first = sc.next().toCharArray();
            second = sc.next().toCharArray();
            preProcess();
            pw.println(isEquivalent(0, first.length - 1, 0, second.length - 1) ? "YES" : "NO");
        }

        private void preProcess() {
            pow = new long[first.length + second.length];
            int prime = 31;
            pow[0] = 1;
            for (int i = 1; i < pow.length; i++)
                pow[i] = (pow[i - 1] * prime % mod + mod) % mod;
            hash = new long[first.length + second.length + 1];
            for (int i = 1; i < hash.length; i++) {
                if (i - 1 < first.length)
                    hash[i] = (mod + (1l * first[i - 1] - 'a' + 1) * pow[i - 1] % mod) % mod;
                else
                    hash[i] = (mod + (1l * second[i - 1 - first.length] - 'a' + 1) * pow[i - 1] % mod) % mod;
                hash[i] = (hash[i - 1] + hash[i]) % mod;
            }
        }

        private boolean isEquivalent(int i, int j, int b, int e) {
            if (i == j)
                return first[i] == second[b];
            if (isEqual(i, j, b, e))
                return true;
            if ((j - i + 1) % 2 == 1)
                return false;
            int firstMid = (i + j) / 2;
            int secondMid = (b + e) / 2;
            return (isEquivalent(i, firstMid, b, secondMid) && isEquivalent(firstMid + 1, j, secondMid + 1, e)) || (isEquivalent(i, firstMid, secondMid + 1, e) && isEquivalent(firstMid + 1, j, b, secondMid));
        }

        private boolean isEqual(int i, int j, int b, int e) {
            if (b - i >= 0)
                return ((hash[j + 1] - hash[i] + mod) % mod) * pow[b - i] % mod == (hash[first.length + e + 1] - hash[first.length + b] + mod) % mod;
            else
                return (hash[j + 1] - hash[i] + mod) % mod == ((hash[first.length + e + 1] - hash[first.length + b] + mod) % mod) * pow[i - b] % mod;
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class BEquivalentStrings {
        char[] first;
        char[] second;
        long[] pow;
        long[] hash;
        long mod = (long) 1e9 + 7;

        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            first = sc.next().toCharArray();
            second = sc.next().toCharArray();
            preProcess();
            pw.println(isEquivalent(0, first.length - 1, 0, second.length - 1) ? "YES" : "NO");
        }

        private void preProcess() {
            pow = new long[first.length + second.length + 1];
            hash = new long[first.length + second.length + 1];
            pow[0] = 1;
            int p = 37;
            for (int i = 1; i < pow.length; i++) {
                int add = (i - 1) < first.length ? first[i - 1] : second[i - first.length - 1];
                hash[i] = (hash[i - 1] % mod * p % mod + add) % mod;
                pow[i] = (pow[i - 1] % mod * p) % mod;
            }
        }

        private boolean isEquivalent(int i, int j, int b, int e) {
            if (i == j)
                return first[i] == second[b];
            if (isEqual(i, j, b, e))
                return true;
            if ((j - i + 1) % 2 == 1)
                return false;
            int firstMid = (i + j) / 2;
            int secondMid = (b + e) / 2;
            return (isEquivalent(i, firstMid, b, secondMid) && isEquivalent(firstMid + 1, j, secondMid + 1, e)) || (isEquivalent(i, firstMid, secondMid + 1, e) && isEquivalent(firstMid + 1, j, b, secondMid));
        }

        private boolean isEqual(int i, int j, int b, int e) {
            return (hash[j] % mod + mod - hash[i] * pow[j - i] % mod) % mod == (hash[first.length + e] % mod + mod - hash[first.length + b] % mod * pow[e - b] % mod) % mod;
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class BEquivalentStrings {
        char[] first;
        char[] second;
        long[] pow;
        long[] hash;
        long mod = (long) 1e9 + 7;

        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            first = sc.next().toCharArray();
            second = sc.next().toCharArray();
            preProcess();
            pw.println(isEquivalent(0, first.length - 1, 0, second.length - 1) ? "YES" : "NO");
        }

        private void preProcess() {
            pow = new long[first.length + second.length + 1];
            hash = new long[first.length + second.length + 1];
            pow[0] = 1;
            int p = 37;
            for (int i = 1; i < pow.length; i++) {
                int add = (i - 1) < first.length ? first[i - 1] : second[i - first.length - 1];
                hash[i] = (hash[i - 1] % mod * p % mod + add) % mod;
                pow[i] = (pow[i - 1] % mod * p) % mod;
            }
        }

        private boolean isEquivalent(int i, int j, int b, int e) {
            if (i == j)
                return first[i] == second[b];
            if (isEqual(i, j, b, e))
                return true;
            if ((j - i + 1) % 2 == 1)
                return false;
            int firstMid = (i + j) / 2;
            int secondMid = (b + e) / 2;
            return (isEquivalent(i, firstMid, b, secondMid) && isEquivalent(firstMid + 1, j, secondMid + 1, e)) || (isEquivalent(i, firstMid, secondMid + 1, e) && isEquivalent(firstMid + 1, j, b, secondMid));
        }

        private boolean isEqual(int i, int j, int b, int e) {
            return (hash[j + 1] % mod + mod - hash[i] * pow[j - i + 1] % mod) % mod == (hash[first.length + e + 1] % mod + mod - hash[first.length + b] % mod * pow[e - b + 1] % mod) % mod;
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class BEquivalentStrings {
        char[] first;
        char[] second;
        long[] pow;
        long[] hash;

        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            first = sc.next().toCharArray();
            second = sc.next().toCharArray();
            preProcess();
            pw.println(isEquivalent(0, first.length - 1, 0, second.length - 1) ? "YES" : "NO");
        }

        private void preProcess() {
            pow = new long[first.length + second.length + 1];
            hash = new long[first.length + second.length + 1];
            pow[0] = 1;
            int p = 37;
            for (int i = 1; i < pow.length; i++) {
                int add = (i - 1) < first.length ? first[i - 1] : second[i - first.length - 1];
                hash[i] = hash[i - 1] * p + add;
                pow[i] = pow[i - 1] * p;
            }
        }

        private boolean isEquivalent(int i, int j, int b, int e) {
            if (i == j)
                return first[i] == second[b];
            if (isEqual(i, j, b, e))
                return true;
            if ((j - i + 1) % 2 == 1)
                return false;
            int firstMid = (i + j) / 2;
            int secondMid = (b + e) / 2;
            return (isEquivalent(i, firstMid, b, secondMid) && isEquivalent(firstMid + 1, j, secondMid + 1, e)) || (isEquivalent(i, firstMid, secondMid + 1, e) && isEquivalent(firstMid + 1, j, b, secondMid));
        }

        private boolean isEqual(int i, int j, int b, int e) {
            return hash[j] - hash[i] * pow[j - i] == hash[first.length + e] - hash[first.length + b] * pow[e - b];
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class BEquivalentStrings {
        char[] first;
        char[] second;
        long[] pow;
        long[] hash;

        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            first = sc.next().toCharArray();
            second = sc.next().toCharArray();
            preProcess();
            pw.println(isEquivalent(0, first.length - 1, 0, second.length - 1) ? "YES" : "NO");
        }

        private void preProcess() {
            pow = new long[first.length + second.length + 1];
            hash = new long[first.length + second.length + 1];
            pow[0] = 1;
            int p = 37;
            for (int i = 1; i < pow.length; i++) {
                int add = (i - 1) < first.length ? first[i - 1] : second[i - first.length - 1];
                hash[i] = (hash[i - 1] * p + add);
                pow[i] = (pow[i - 1] * p);
            }
        }

        private boolean isEquivalent(int i, int j, int b, int e) {
            if (i == j)
                return first[i] == second[b];
            if (isEqual(i, j, b, e))
                return true;
            if ((j - i + 1) % 2 == 1)
                return false;
            int firstMid = (i + j) / 2;
            int secondMid = (b + e) / 2;
            return (isEquivalent(i, firstMid, b, secondMid) && isEquivalent(firstMid + 1, j, secondMid + 1, e)) || (isEquivalent(i, firstMid, secondMid + 1, e) && isEquivalent(firstMid + 1, j, b, secondMid));
        }

        private boolean isEqual(int i, int j, int b, int e) {
            return hash[j + 1] - hash[i] * pow[j - i + 1] == hash[first.length + e + 1] - hash[first.length + b] * pow[e - b + 1];
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class BEquivalentStrings {
        char[] first;
        char[] second;

        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            first = sc.next().toCharArray();
            second = sc.next().toCharArray();
            pw.println(isEquivalent(0, first.length - 1, 0, second.length - 1) ? "YES" : "NO");
        }

        private boolean isEquivalent(int i, int j, int b, int e) {
            if (i == j)
                return first[i] == second[b];
            if (isEqual(i, j, b, e))
                return true;
            if ((j - i + 1) % 2 == 1)
                return false;
            int firstMid = (i + j) / 2;
            int secondMid = (b + e) / 2;
            return (isEquivalent(i, firstMid, b, firstMid) && isEquivalent(firstMid + 1, j, secondMid + 1, e)) || (isEquivalent(i, firstMid, secondMid + 1, e) && isEquivalent(firstMid + 1, j, b, secondMid));
        }

        private boolean isEqual(int i, int j, int b, int e) {
            while (i <= j) {
                if (first[i] != second[b])
                    return false;
                i++;
                b++;
            }
            return true;
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class BEquivalentStrings {
        char[] first;
        char[] second;
        long[] pow;
        long[] hash;

        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            first = sc.next().toCharArray();
            second = sc.next().toCharArray();
            preProcess();
            pw.println(isEquivalent(0, first.length - 1, 0, second.length - 1) ? "YES" : "NO");
        }

        private void preProcess() {
            pow = new long[first.length + second.length + 1];
            hash = new long[first.length + second.length + 1];
            pow[0] = 1;
            int p = 37;
            for (int i = 1; i < pow.length; i++) {
                int add = (i - 1) < first.length ? first[i - 1] : second[i - first.length - 1];
                hash[i] = hash[i - 1] * p + add;
                pow[i] = pow[i - 1] * p;
            }
        }

        private boolean isEquivalent(int i, int j, int b, int e) {
            if (i == j)
                return first[i] == second[b];
            if (isEqual(i, j, b, e))
                return true;
            if ((j - i + 1) % 2 == 1)
                return false;
            int firstMid = (i + j) / 2;
            int secondMid = (b + e) / 2;
            return (isEquivalent(i, firstMid, b, secondMid) && isEquivalent(firstMid + 1, j, secondMid + 1, e)) || (isEquivalent(i, firstMid, secondMid + 1, e) && isEquivalent(firstMid + 1, j, b, secondMid));
        }

        private boolean isEqual(int i, int j, int b, int e) {
            return hash[j + 1] - hash[i] * pow[j - i] == hash[first.length + e + 1] - hash[first.length + b] * pow[e - b];
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class BEquivalentStrings {
        char[] first;
        char[] second;
        long[] pow;
        long[] hash;

        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            first = sc.next().toCharArray();
            second = sc.next().toCharArray();
            preProcess();
            pw.println(isEquivalent(0, first.length - 1, 0, second.length - 1) ? "YES" : "NO");
        }

        private void preProcess() {
            pow = new long[first.length + second.length + 1];
            hash = new long[first.length + second.length + 1];
            pow[0] = 1;
            int p = 31;
            for (int i = 1; i < pow.length; i++) {
                int add = (i - 1) < first.length ? first[i - 1] : second[i - first.length - 1];
                hash[i] = hash[i - 1] * p + add;
                pow[i] = pow[i - 1] * p;
            }
        }

        private boolean isEquivalent(int i, int j, int b, int e) {
            if (i == j)
                return first[i] == second[b];
            if (isEqual(i, j, b, e))
                return true;
            if ((j - i + 1) % 2 == 1)
                return false;
            int firstMid = (i + j) / 2;
            int secondMid = (b + e) / 2;
            return (isEquivalent(i, firstMid, b, secondMid) && isEquivalent(firstMid + 1, j, secondMid + 1, e)) || (isEquivalent(i, firstMid, secondMid + 1, e) && isEquivalent(firstMid + 1, j, b, secondMid));
        }

        private boolean isEqual(int i, int j, int b, int e) {
            return hash[j] - hash[i] * pow[j - i] == hash[first.length + e] - hash[first.length + b] * pow[e - b];
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class BEquivalentStrings {
        char[] first;
        char[] second;
        int mod = (int) 1e9 + 9;
        long[] pow;
        long[] hashFirst;
        long[] hashSecond;

        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            first = sc.next().toCharArray();
            second = sc.next().toCharArray();
            preProcess();
            pw.println(isEquivalent(0, first.length - 1, 0, second.length - 1) ? "YES" : "NO");
        }

        private void preProcess() {
            pow = new long[first.length];
            int prime = 263;
            pow[0] = 1;
            for (int i = 1; i < pow.length; i++)
                pow[i] = (pow[i - 1] * prime + mod) % mod;
            hashFirst = new long[first.length + 1];
            hashSecond = new long[second.length + 1];
            for (int i = 1; i <= first.length; i++) {
                hashFirst[i] = (mod + (first[i - 1] - 'a' + 1) * pow[i - 1] % mod) % mod;
                hashFirst[i] = (hashFirst[i - 1] + hashFirst[i]) % mod;
                hashSecond[i] = (mod + (second[i - 1] - 'a' + 1) * pow[i - 1] % mod) % mod;
                hashSecond[i] = (hashSecond[i - 1] + hashSecond[i]) % mod;
            }
        }

        private boolean isEquivalent(int i, int j, int b, int e) {
            if (i == j)
                return first[i] == second[b];
            if (isEqual(i, j, b, e))
                return true;
            if ((j - i + 1) % 2 == 1)
                return false;
            int firstMid = (i + j) / 2;
            int secondMid = (b + e) / 2;
            return (isEquivalent(i, firstMid, b, secondMid) && isEquivalent(firstMid + 1, j, secondMid + 1, e)) || (isEquivalent(i, firstMid, secondMid + 1, e) && isEquivalent(firstMid + 1, j, b, secondMid));
        }

        private boolean isEqual(int i, int j, int b, int e) {
            return (hashFirst[j + 1] - hashFirst[i] + mod) % mod == (hashSecond[e + 1] - hashSecond[b] + mod) % mod;
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class BEquivalentStrings {
        char[] first;
        char[] second;
        long mod = (long) 1e9 + 9;
        long[] pow;
        long[] hashFirst;
        long[] hashSecond;

        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            first = sc.next().toCharArray();
            second = sc.next().toCharArray();
            preProcess();
            pw.println(isEquivalent(0, first.length - 1, 0, second.length - 1) ? "YES" : "NO");
        }

        private void preProcess() {
            pow = new long[first.length];
            int prime = 31;
            pow[0] = 1;
            for (int i = 1; i < pow.length; i++)
                pow[i] = (pow[i - 1] * prime % mod + mod) % mod;
            hashFirst = new long[first.length + 1];
            hashSecond = new long[second.length + 1];
            for (int i = 1; i <= first.length; i++) {
                hashFirst[i] = (mod + (1l * first[i - 1] - 'a' + 1) * pow[i - 1] % mod) % mod;
                hashFirst[i] = (hashFirst[i - 1] + hashFirst[i]) % mod;
                hashSecond[i] = (mod + (1l * second[i - 1] - 'a' + 1) * pow[i - 1] % mod) % mod;
                hashSecond[i] = (hashSecond[i - 1] + hashSecond[i]) % mod;
            }
        }

        private boolean isEquivalent(int i, int j, int b, int e) {
            if (i == j)
                return first[i] == second[b];
            if (isEqual(i, j, b, e))
                return true;
            if ((j - i + 1) % 2 == 1)
                return false;
            int firstMid = (i + j) / 2;
            int secondMid = (b + e) / 2;
            return (isEquivalent(i, firstMid, b, secondMid) && isEquivalent(firstMid + 1, j, secondMid + 1, e)) || (isEquivalent(i, firstMid, secondMid + 1, e) && isEquivalent(firstMid + 1, j, b, secondMid));
        }

        private boolean isEqual(int i, int j, int b, int e) {
            if (i < b)
                return ((hashFirst[j + 1] - hashFirst[i] + mod) % mod) * pow[b - i] == (hashSecond[e + 1] - hashSecond[b] + mod) % mod;
            else
                return (hashFirst[j + 1] - hashFirst[i] + mod) % mod == ((hashSecond[e + 1] - hashSecond[b] + mod) % mod) * pow[i - b];
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class BEquivalentStrings {
        char[] first;
        char[] second;
        long[] pow;
        long[] hash;

        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            first = sc.next().toCharArray();
            second = sc.next().toCharArray();
            preProcess();
            pw.println(isEquivalent(0, first.length - 1, 0, second.length - 1) ? "YES" : "NO");
        }

        private void preProcess() {
            pow = new long[first.length + second.length + 1];
            hash = new long[first.length + second.length + 1];
            pow[0] = 1;
            int p = 263;
            for (int i = 1; i < pow.length; i++) {
                int add = (i - 1) < first.length ? first[i - 1] : second[i - first.length - 1];
                hash[i] = hash[i - 1] * p + add;
                pow[i] = pow[i - 1] * p;
            }
        }

        private boolean isEquivalent(int i, int j, int b, int e) {
            if (i == j)
                return first[i] == second[b];
            if (isEqual(i, j, b, e))
                return true;
            if ((j - i + 1) % 2 == 1)
                return false;
            int firstMid = (i + j) / 2;
            int secondMid = (b + e) / 2;
            return (isEquivalent(i, firstMid, b, secondMid) && isEquivalent(firstMid + 1, j, secondMid + 1, e)) || (isEquivalent(i, firstMid, secondMid + 1, e) && isEquivalent(firstMid + 1, j, b, secondMid));
        }

        private boolean isEqual(int i, int j, int b, int e) {
            return hash[j] - hash[i] * pow[j - i] == hash[first.length + e] - hash[first.length + b] * pow[e - b];
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class CodeForces_211102I {
	public static void main(String[] args) throws IOException{
		BufferedReader bf =new BufferedReader(new InputStreamReader(System.in));
		StringBuilder br1=new StringBuilder(bf.readLine());
		StringBuilder br2=new StringBuilder(bf.readLine());
		if(br1.length() != br2.length()){
			System.out.println("NO");
		}
		else{
			if(br1.equals(br2)){
				System.out.println("YES");return;}
			else{
				if(solve(br1.toString(),br2.toString())){
					System.out.println("YES");
					}
				else{
					System.out.println("NO");
				}
				}
		}
//			StringBuilder a1=new StringBuilder(br1.substring(0,br1.length()/2));
//			StringBuilder a2=new StringBuilder(br1.substring(br1.length()/2));
//
//			StringBuilder b1=new StringBuilder(br2.substring(0,br2.length()/2));
//			StringBuilder b2=new StringBuilder(br2.substring(br2.length()/2));
//			System.out.println(a1.toString()+" "+a2.toString()+" "+b1.toString()+" "+b2.toString()+" ");
//			if(a1.equals(b1) && a2.equals(b2) || a1.equals(b2) && a2.equals(b1) ){
//				System.out.println("YES");
//			}
//			else
//				System.out.println("NO");
//		}
	}
	public static boolean solve(String s1,String s2){
		if(s1.length()%2 ==1)
			return s1.equals(s2);
		if(s1.equals(s2))
			return true;
		if(s1.length() == 1 && s2.length() ==1 && !s1.equals(s2))
			return false;
		return (solve(s1.substring(0,s1.length()/2),s2.substring(0,s2.length()/2)) && solve(s1.substring(s1.length()/2),s2.substring(s2.length()/2)))
				||
				(solve(s1.substring(0,s1.length()/2),s2.substring(s2.length()/2)) && solve(s1.substring(s1.length()/2),s2.substring(0,s2.length()/2)));

	}

}


//package Contest1_1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.InputMismatchException;

public class CodeForces_211102I {
	public static void main(String[] args) throws IOException{
		InputReader in = new InputReader(System.in);
		String br1=(in.ns());
		String br2=(in.ns());

				if(solve(br1,br2)){
					System.out.println("YES");
					}
				else{
					System.out.println("NO");
				}

//			StringBuilder a1=new StringBuilder(br1.substring(0,br1.length()/2));
//			StringBuilder a2=new StringBuilder(br1.substring(br1.length()/2));
//
//			StringBuilder b1=new StringBuilder(br2.substring(0,br2.length()/2));
//			StringBuilder b2=new StringBuilder(br2.substring(br2.length()/2));
//			System.out.println(a1.toString()+" "+a2.toString()+" "+b1.toString()+" "+b2.toString()+" ");
//			if(a1.equals(b1) && a2.equals(b2) || a1.equals(b2) && a2.equals(b1) ){
//				System.out.println("YES");
//			}
//			else
//				System.out.println("NO");
//		}
	}
	public static boolean solve(String s1,String s2){
		if(s1.length()%2 ==1 || s2.length()%2 ==1 )
			return s1.equals(s2);
		if(s1.equals(s2))
			return true;
		String a1=s1.substring(0,s1.length()/2);
		String b1=s2.substring(0,s2.length()/2);
		String a2=s1.substring(s1.length()/2);
		String b2=s2.substring(s2.length()/2);
		return solve(a1,b1) && solve(a2,b2) || solve(a1,b2) && solve(a2,b1);

	}

static class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int ni() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c & 15;
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public long nl() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c & 15;
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String ns() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public char[] ncs() {
		return ns().toCharArray();
	}

	public String nLine() {
		int c = read();
		// while (c != '\n' && c != '\r' && c != '\t' && c != -1)
		// c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (c != '\n' && c != '\r' && c != '\t' && c != -1);
		return res.toString();
	}

	public static boolean isSpaceChar(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

}

}


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

public class CodeForces_211102I {
	public static void main(String[] args) throws IOException{
		InputReader in = new InputReader(System.in);
		String br1=(in.ns());
		String br2=(in.ns());
		PrintWriter out = new PrintWriter(System.out);

				if(solve(br1,br2)){
					out.println("YES");
					}
				else{
					out.println("NO");
				}
				out.close();

//			StringBuilder a1=new StringBuilder(br1.substring(0,br1.length()/2));
//			StringBuilder a2=new StringBuilder(br1.substring(br1.length()/2));
//
//			StringBuilder b1=new StringBuilder(br2.substring(0,br2.length()/2));
//			StringBuilder b2=new StringBuilder(br2.substring(br2.length()/2));
//			System.out.println(a1.toString()+" "+a2.toString()+" "+b1.toString()+" "+b2.toString()+" ");
//			if(a1.equals(b1) && a2.equals(b2) || a1.equals(b2) && a2.equals(b1) ){
//				System.out.println("YES");
//			}
//			else
//				System.out.println("NO");
//		}
	}
	public static boolean solve(String s1,String s2){
		int len=s1.length();
		if(len%2 ==1 )
			return s1.equals(s2);
		if(s1.equals(s2))
			return true;
		String a1=s1.substring(0,len/2);
		String b1=s2.substring(0,len/2);
		String a2=s1.substring(len/2);
		String b2=s2.substring(len/2);
		return (solve(a1,b1) && solve(a2,b2)) || (solve(a1,b2) && solve(a2,b1));
//		boolean flag1 = solve(a1, b2) && solve(a2, a1);
//		boolean flag2 = flag1 || (solve(a1, b1)
//				&& solve(a2, b2));
//		return flag2;

	}

static class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int ni() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c & 15;
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public long nl() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c & 15;
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String ns() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public char[] ncs() {
		return ns().toCharArray();
	}

	public String nLine() {
		int c = read();
		// while (c != '\n' && c != '\r' && c != '\t' && c != -1)
		// c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (c != '\n' && c != '\r' && c != '\t' && c != -1);
		return res.toString();
	}

	public static boolean isSpaceChar(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

}

}


//package Contest1_1;

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

public class CodeForces_211102I {
	public static void main(String[] args) throws IOException{
		InputReader in = new InputReader(System.in);
		String br1=(in.ns());
		String br2=(in.ns());
		PrintWriter out = new PrintWriter(System.out);

				if(solve(br1,br2)){
					out.println("YES");
					}
				else{
					out.println("NO");
				}
				out.close();

//			StringBuilder a1=new StringBuilder(br1.substring(0,br1.length()/2));
//			StringBuilder a2=new StringBuilder(br1.substring(br1.length()/2));
//
//			StringBuilder b1=new StringBuilder(br2.substring(0,br2.length()/2));
//			StringBuilder b2=new StringBuilder(br2.substring(br2.length()/2));
//			System.out.println(a1.toString()+" "+a2.toString()+" "+b1.toString()+" "+b2.toString()+" ");
//			if(a1.equals(b1) && a2.equals(b2) || a1.equals(b2) && a2.equals(b1) ){
//				System.out.println("YES");
//			}
//			else
//				System.out.println("NO");
//		}
	}
	public static boolean solve(String s1,String s2){
		if(s1.length()%2 ==1 || s2.length()%2 ==1 )
			return s1.equals(s2);
		if(s1.equals(s2))
			return true;
		String a1=s1.substring(0,s1.length()/2);
		String b1=s2.substring(0,s2.length()/2);
		String a2=s1.substring(s1.length()/2);
		String b2=s2.substring(s2.length()/2);
		return solve(a1,b1) && solve(a2,b2) || solve(a1,b2) && solve(a2,b1);

	}

static class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int ni() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c & 15;
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public long nl() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c & 15;
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String ns() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public char[] ncs() {
		return ns().toCharArray();
	}

	public String nLine() {
		int c = read();
		// while (c != '\n' && c != '\r' && c != '\t' && c != -1)
		// c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (c != '\n' && c != '\r' && c != '\t' && c != -1);
		return res.toString();
	}

	public static boolean isSpaceChar(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

}

}


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

public class CO_559B {
	static int imax = Integer.MAX_VALUE, imin = Integer.MIN_VALUE;
	static long lmax = Long.MAX_VALUE, lmin = Long.MIN_VALUE;
	static long mod = (long) 1e9 + 7;

	public static void main(String[] args) throws java.lang.Exception {
		// File file=new File("C:\\Users\\EagleEye\\Desktop\\input.txt");
		// File file1=new File("C:\\Users\\EagleEye\\Desktop\\output.txt");
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		// int test=in.ni();
		int test = 1;
		int i = 0, j = 0;
		while (test-- > 0) {
			// int n = in.ni();
			String str1 = in.ns();
			String str2 = in.ns();
			if (find(str1, str2)) {
				out.println("YES");
			} else
				out.println("NO");
		}
		out.close();
	}

	static boolean find(String str1, String str2) {
		if (str1.length() % 2 == 1) {
			return str1.equals(str2);
		} else {
			if (str1.equals(str2)) {
				return true;
			}
			int len = str1.length();
			boolean flag1 = (find(str1.substring(0, len / 2), str2.substring(len / 2))
					&& find(str1.substring(len / 2), str2.substring(0, len / 2)));
			boolean flag2 = flag1 || (find(str1.substring(0, len / 2), str2.substring(0, len / 2))
					&& find(str1.substring(len / 2), str2.substring(len / 2)));
			return flag2;
		}
	}

	static class Pair {
		String x, y;

		Pair(String x, String y) {
			this.x = x;
			this.y = y;
		}

		/*
		 * (non-Javadoc)
		 *
		 * @see java.lang.Object#hashCode()
		 */
		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + ((x == null) ? 0 : x.hashCode());
			result = prime * result + ((y == null) ? 0 : y.hashCode());
			return result;
		}

		/*
		 * (non-Javadoc)
		 *
		 * @see java.lang.Object#equals(java.lang.Object)
		 */
		@Override
		public boolean equals(Object obj) {
			if (this == obj) {
				return true;
			}
			if (obj == null) {
				return false;
			}
			if (!(obj instanceof Pair)) {
				return false;
			}
			Pair other = (Pair) obj;
			if (x == null) {
				if (other.x != null) {
					return false;
				}
			} else if (!x.equals(other.x)) {
				return false;
			}
			if (y == null) {
				if (other.y != null) {
					return false;
				}
			} else if (!y.equals(other.y)) {
				return false;
			}
			return true;
		}

		public String toString() {
			return x + " " + y;
		}
	}

	static void print(int arr[], int len) {
		for (int i = 0; i < len; i++)
			System.out.print(arr[i] + " ");
		System.out.println();
	}

	static class InputReader {

		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int ni() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c & 15;
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nl() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c & 15;
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public String ns() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public char[] ncs() {
			return ns().toCharArray();
		}

		public String nLine() {
			int c = read();
			// while (c != '\n' && c != '\r' && c != '\t' && c != -1)
			// c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (c != '\n' && c != '\r' && c != '\t' && c != -1);
			return res.toString();
		}

		public static boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

	}

}


/**
*   @author: Kshitiz Srivastava (Pirate_ksh) @ MNNIT Allahabad
*/
#include<bits/stdc++.h>
using namespace std;

// General
#define ll long long
#define ld long double
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007 // 998244353
#define PI 3.1415926535897932384
#define endl "\n"
#define debug(x) cout<<x<<endl
#define REP(i,n) for(i=0;i<n;++i)
#define FOR(i,x,n) for(i=x;i<n;++i)
#define RREP(i,n) for(i=n-1;i>=0;--i)
#define RFOR(i,x,n) for(i=n-1;i>=x;--i)
#define TR(i,c) for(auto i=c.begin();i!=c.end();++i)
#define RTR(i,c) for(auto i=c.rbegin();i!=c.rend();++i)

// Bounds
#define lb(a,x) a.lower_bound(x)
#define ub(a,x) a.upper_bound(x)
#define all(a) a.begin(),a.end()

// Vector
#define vi vector <int>
#define pb(v,x) v.push_back(x)
#define vll vector <ll>

// Map
#define mii map <int, int>
#define umii unordered_map <int, int>

// Set
#define si set <int>
#define msi multiset<int>

// Pair
#define vpii vector<pair < int, int > >
#define vpll vector<pair < ll, ll > >
#define pii pair < int, int >
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define vppi vector<pair<pair<int,int>,int>>
#define ppi pair<pair<int,int>,int>

void solve();

vector<ll> pow2;

int main(){
    io
    ll t;
    t=1;
    cin >> t;
    pow2.resize(61);
    pow2[0] = 1;
    ll two = 2, i;
    FOR(i,1,61) pow2[i] = two * pow2[i-1];
    while(t--) solve();
    return 0;
}

ll bin2dec(string &s) {
    reverse(all(s));
    ll ret = 0, n = (ll)s.length();
    for(ll i = 0; i < n; ++i)
        if(s[i] == '1') ret += pow2[i];
    return ret;
}

string dec2bin(ll n, ll m) {
    string ans;
    while(n) {
        ans+=to_string(n%2);
        n/=2;
    }
    ll rem = m - (ll)ans.length();
    while(rem--) pb(ans,'0');
    reverse(all(ans));
    return ans;
}

void solve() {
    ll i, j, n, m, effec;
    cin >> n >> m;
    effec = pow2[m] - n;
    effec -= 1;
    effec /= 2;
    vector<string> s(n);
    REP(i,n) cin >> s[i];
    vector<ll> mark(n);
    REP(i,n) mark[i] = bin2dec(s[i]);;
    sort(all(mark));
    REP(i,n) if(mark[i] <= effec) effec++;
    cout << dec2bin(effec,m) << endl;
}


/**
*   @author: Kshitiz Srivastava (Pirate_ksh) @ MNNIT Allahabad
*/
#include<bits/stdc++.h>
using namespace std;

// General
#define ll long long
#define ld long double
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007 // 998244353
#define PI 3.1415926535897932384
#define endl "\n"
#define debug(x) cout<<x<<endl
#define REP(i,n) for(i=0;i<n;++i)
#define FOR(i,x,n) for(i=x;i<n;++i)
#define RREP(i,n) for(i=n-1;i>=0;--i)
#define RFOR(i,x,n) for(i=n-1;i>=x;--i)
#define TR(i,c) for(auto i=c.begin();i!=c.end();++i)
#define RTR(i,c) for(auto i=c.rbegin();i!=c.rend();++i)

// Bounds
#define lb(a,x) a.lower_bound(x)
#define ub(a,x) a.upper_bound(x)
#define all(a) a.begin(),a.end()

// Vector
#define vi vector <int>
#define pb(v,x) v.push_back(x)
#define vll vector <ll>

// Map
#define mii map <int, int>
#define umii unordered_map <int, int>

// Set
#define si set <int>
#define msi multiset<int>

// Pair
#define vpii vector<pair < int, int > >
#define vpll vector<pair < ll, ll > >
#define pii pair < int, int >
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define vppi vector<pair<pair<int,int>,int>>
#define ppi pair<pair<int,int>,int>

void solve();

vector<ll> pow2;

int main(){
    io
    ll t;
    t=1;
    cin >> t;
    pow2.resize(61);
    pow2[0] = 1;
    ll two = 2, i;
    FOR(i,1,61) pow2[i] = two * pow2[i-1];
    while(t--) solve();
    return 0;
}

ll bin2dec(string &s) {
    reverse(all(s));
    ll ret = 0, n = (ll)s.length();
    for(ll i = 0; i < n; ++i)
        if(s[i] == '1') ret += pow2[i];
    return ret;
}

string dec2bin(ll n, ll m) {
    string ans;
    while(n) {
        ans+=to_string(n%2);
        n/=2;
    }
    ll rem = m - (ll)ans.length();
    while(rem--) pb(ans,'0');
    reverse(all(ans));
    return ans;
}

void solve() {
    ll i, j, n, m, effec;
    cin >> n >> m;
    effec = pow2[m] - n;
    effec -= 1;
    effec /= 2;
    vector<string> s(n);
    REP(i,n) cin >> s[i];
    vector<ll> mark;
    REP(i,n) {
        ll dec = bin2dec(s[i]);
        if(dec <= effec) effec++;
    }
    cout << dec2bin(effec,m) << endl;
}


/**
*   @author: Kshitiz Srivastava (Pirate_ksh) @ MNNIT Allahabad
*/
#include<bits/stdc++.h>
using namespace std;

// General
#define ll long long
#define ld long double
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007 // 998244353
#define PI 3.1415926535897932384
#define endl "\n"
#define debug(x) cout<<x<<endl
#define REP(i,n) for(i=0;i<n;++i)
#define FOR(i,x,n) for(i=x;i<n;++i)
#define RREP(i,n) for(i=n-1;i>=0;--i)
#define RFOR(i,x,n) for(i=n-1;i>=x;--i)
#define TR(i,c) for(auto i=c.begin();i!=c.end();++i)
#define RTR(i,c) for(auto i=c.rbegin();i!=c.rend();++i)

// Bounds
#define lb(a,x) a.lower_bound(x)
#define ub(a,x) a.upper_bound(x)
#define all(a) a.begin(),a.end()

// Vector
#define vi vector <int>
#define pb(v,x) v.push_back(x)
#define vll vector <ll>

// Map
#define mii map <int, int>
#define umii unordered_map <int, int>

// Set
#define si set <int>
#define msi multiset<int>

// Pair
#define vpii vector<pair < int, int > >
#define vpll vector<pair < ll, ll > >
#define pii pair < int, int >
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define vppi vector<pair<pair<int,int>,int>>
#define ppi pair<pair<int,int>,int>

void solve();

vector<ll> pow2;

int main(){
    io
    ll t;
    t=1;
    cin >> t;
    pow2.resize(61);
    pow2[0] = 1;
    ll two = 2, i;
    FOR(i,1,61) pow2[i] = two * pow2[i-1];
    while(t--) solve();
    return 0;
}

ll bin2dec(string &s) {
    reverse(all(s));
    ll ret = 0, n = (ll)s.length();
    for(ll i = 0; i < n; ++i)
        if(s[i] == '1') ret += pow2[i];
    return ret;
}

string dec2bin(ll n, ll m) {
    string ans;
    while(n) {
        ans+=to_string(n%2);
        n/=2;
    }
    ll rem = m - (ll)ans.length();
    while(rem--) pb(ans,'0');
    reverse(all(ans));
    return ans;
}

void solve() {
    ll i, j, n, m, effec;
    cin >> n >> m;
    effec = pow2[m] - n;
    effec -= 1;
    effec /= 2;
    vector<string> s(n);
    REP(i,n) cin >> s[i];
    mii mark;
    REP(i,n) {
        ll dec = bin2dec(s[i]);
        mark[dec+1] = 1;
    }
    mark[pow2[m]+1] = 1;
    effec += 1;
    // cout << "effec=" << effec << endl;
    ll already = 0, prev = 0, ans;
    for(auto i=mark.begin(); i != mark.end(); ++i) {
        int curr = i -> F;
        // cout << "curr=" << curr << endl;
        already += curr - prev - 1;
        if(already >= effec) {
            ll preval = already - (curr - prev - 1);
            // cout << "preval=" << preval << " ";
            // cout << "already=" << already <<" prev=" << prev << endl;
            ans = prev + (effec - preval) - 1;
            break;
        }
        prev = curr;
    }
    cout << dec2bin(ans,m) << endl;
}


/**
*   @author: Kshitiz Srivastava (Pirate_ksh) @ MNNIT Allahabad
*/
#include<bits/stdc++.h>
using namespace std;

// General
#define ll long long
#define ld long double
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007 // 998244353
#define PI 3.1415926535897932384
#define endl "\n"
#define debug(x) cout<<x<<endl
#define REP(i,n) for(i=0;i<n;++i)
#define FOR(i,x,n) for(i=x;i<n;++i)
#define RREP(i,n) for(i=n-1;i>=0;--i)
#define RFOR(i,x,n) for(i=n-1;i>=x;--i)
#define TR(i,c) for(auto i=c.begin();i!=c.end();++i)
#define RTR(i,c) for(auto i=c.rbegin();i!=c.rend();++i)

// Bounds
#define lb(a,x) a.lower_bound(x)
#define ub(a,x) a.upper_bound(x)
#define all(a) a.begin(),a.end()

// Vector
#define vi vector <int>
#define pb(v,x) v.push_back(x)
#define vll vector <ll>

// Map
#define mii map <int, int>
#define umii unordered_map <int, int>

// Set
#define si set <int>
#define msi multiset<int>

// Pair
#define vpii vector<pair < int, int > >
#define vpll vector<pair < ll, ll > >
#define pii pair < int, int >
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define vppi vector<pair<pair<int,int>,int>>
#define ppi pair<pair<int,int>,int>

void solve();

vector<ll> pow2;

int main(){
    io
    ll t;
    t=1;
    cin >> t;
    pow2.resize(61);
    pow2[0] = 1;
    ll two = 2, i;
    FOR(i,1,61) pow2[i] = two * pow2[i-1];
    while(t--) solve();
    return 0;
}

ll bin2dec(string &s) {
    reverse(all(s));
    ll ret = 0, n = (ll)s.length();
    for(ll i = 0; i < n; ++i)
        if(s[i] == '1') ret += pow2[i];
    return ret;
}

string dec2bin(ll n, ll m) {
    string ans;
    while(n) {
        ans+=to_string(n%2);
        n/=2;
    }
    ll rem = m - (ll)ans.length();
    while(rem--) pb(ans,'0');
    reverse(all(ans));
    return ans;
}

void solve() {
    ll i, j, n, m, effec;
    cin >> n >> m;
    effec = pow2[m] - n;
    effec -= 1;
    effec /= 2;
    vector<string> s(n);
    REP(i,n) cin >> s[i];
    vector<ll> mark;
    REP(i,n) {
        ll dec = bin2dec(s[i]);
        pb(mark,dec);
    }
    pb(mark, pow2[m]);
    sort(all(mark));
    effec += 1;
    // cout << "effec=" << effec << endl;
    ll already = 0, prev = -1, ans;
    for(i=0; i < (ll)mark.size(); ++i) {
        int curr = mark[i];
        // cout << "curr=" << curr << endl;
        already += curr - prev - 1;
        if(already >= effec) {
            ll preval = already - (curr - prev - 1);
            // cout << "preval=" << preval << " ";
            // cout << "already=" << already <<" prev=" << prev << endl;
            ans = prev + (effec - preval);
            break;
        }
        prev = curr;
    }
    cout << dec2bin(ans,m) << endl;
}


/**
*   @author: Kshitiz Srivastava (Pirate_ksh) @ MNNIT Allahabad
*/
#include<bits/stdc++.h>
using namespace std;

// General
#define ll long long
#define ld long double
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007 // 998244353
#define PI 3.1415926535897932384
#define endl "\n"
#define debug(x) cout<<x<<endl
#define REP(i,n) for(i=0;i<n;++i)
#define FOR(i,x,n) for(i=x;i<n;++i)
#define RREP(i,n) for(i=n-1;i>=0;--i)
#define RFOR(i,x,n) for(i=n-1;i>=x;--i)
#define TR(i,c) for(auto i=c.begin();i!=c.end();++i)
#define RTR(i,c) for(auto i=c.rbegin();i!=c.rend();++i)

// Bounds
#define lb(a,x) a.lower_bound(x)
#define ub(a,x) a.upper_bound(x)
#define all(a) a.begin(),a.end()

// Vector
#define vi vector <int>
#define pb(v,x) v.push_back(x)
#define vll vector <ll>

// Map
#define mii map <int, int>
#define umii unordered_map <int, int>

// Set
#define si set <int>
#define msi multiset<int>

// Pair
#define vpii vector<pair < int, int > >
#define vpll vector<pair < ll, ll > >
#define pii pair < int, int >
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define vppi vector<pair<pair<int,int>,int>>
#define ppi pair<pair<int,int>,int>

void solve();

vector<ll> pow2;

int main(){
    io
    ll t;
    t=1;
    cin >> t;
    pow2.resize(61);
    pow2[0] = 1;
    ll two = 2, i;
    FOR(i,1,61) pow2[i] = two * pow2[i-1];
    while(t--) solve();
    return 0;
}

ll bin2dec(string &s) {
    reverse(all(s));
    ll ret = 0, n = (ll)s.length();
    for(ll i = 0; i < n; ++i)
        if(s[i] == '1') ret += pow2[i];
    return ret;
}

string dec2bin(ll n, ll m) {
    string ans;
    while(n) {
        ans+=to_string(n%2);
        n/=2;
    }
    ll rem = m - (ll)ans.length();
    while(rem--) pb(ans,'0');
    reverse(all(ans));
    return ans;
}

void solve() {
    ll i, j, n, m, effec;
    cin >> n >> m;
    effec = pow2[m] - n;
    effec -= 1;
    effec /= 2;
    vector<string> s(n);
    REP(i,n) cin >> s[i];
    vector<ll> mark;
    REP(i,n) {
        ll dec = bin2dec(s[i]);
        pb(mark,dec);
    }
    pb(mark, pow2[m]);
    sort(all(mark));
    // cout << "effec=" << effec << endl;
    ll already = -1, prev = -1, ans;
    for(i=0; i < (ll)mark.size(); ++i) {
        int curr = mark[i];
        // cout << "curr=" << curr << endl;
        already += (curr - prev - (ll)1);
        if(already >= effec) {
            ll preval = already - (curr - prev - (ll)1);
            // cout << "preval=" << preval << " ";
            // cout << "already=" << already <<" prev=" << prev << endl;
            ans = prev + (effec - preval);
            break;
        }
        prev = curr;
    }
    cout << dec2bin(ans,m) << endl;
}


/**
*   @author: Kshitiz Srivastava (Pirate_ksh) @ MNNIT Allahabad
*/
#include<bits/stdc++.h>
using namespace std;

// General
#define ll long long
#define ld long double
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007 // 998244353
#define PI 3.1415926535897932384
#define endl "\n"
#define debug(x) cout<<x<<endl
#define REP(i,n) for(i=0;i<n;++i)
#define FOR(i,x,n) for(i=x;i<n;++i)
#define RREP(i,n) for(i=n-1;i>=0;--i)
#define RFOR(i,x,n) for(i=n-1;i>=x;--i)
#define TR(i,c) for(auto i=c.begin();i!=c.end();++i)
#define RTR(i,c) for(auto i=c.rbegin();i!=c.rend();++i)

// Bounds
#define lb(a,x) a.lower_bound(x)
#define ub(a,x) a.upper_bound(x)
#define all(a) a.begin(),a.end()

// Vector
#define vi vector <int>
#define pb(v,x) v.push_back(x)
#define vll vector <ll>

// Map
#define mii map <int, int>
#define umii unordered_map <int, int>

// Set
#define si set <int>
#define msi multiset<int>

// Pair
#define vpii vector<pair < int, int > >
#define vpll vector<pair < ll, ll > >
#define pii pair < int, int >
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define vppi vector<pair<pair<int,int>,int>>
#define ppi pair<pair<int,int>,int>

void solve();

vector<ll> pow2;

int main(){
    io
    ll t;
    t=1;
    cin >> t;
    pow2.resize(61);
    pow2[0] = 1;
    ll two = 2, i;
    FOR(i,1,61) pow2[i] = two * pow2[i-1];
    while(t--) solve();
    return 0;
}

ll bin2dec(string &s) {
    reverse(all(s));
    ll ret = 0, n = (ll)s.length();
    for(ll i = 0; i < n; ++i)
        if(s[i] == '1') ret += pow2[i];
    return ret;
}

string dec2bin(ll n, ll m) {
    string ans;
    while(n) {
        ans+=to_string(n%2);
        n/=2;
    }
    ll rem = m - (ll)ans.length();
    while(rem--) pb(ans,'0');
    reverse(all(ans));
    return ans;
}

void solve() {
    ll i, j, n, m, effec;
    cin >> n >> m;
    effec = pow2[m] - n;
    effec -= 1;
    effec /= 2;
    vector<string> s(n);
    REP(i,n) cin >> s[i];
    vector<ll> mark;
    REP(i,n) {
        ll dec = bin2dec(s[i]);
        pb(mark,dec+1);
    }
    pb(mark, pow2[m]+(ll)1);
    sort(all(mark));
    effec += 1;
    // cout << "effec=" << effec << endl;
    ll already = 0, prev = 0, ans;
    for(i=0; i < (ll)mark.size(); ++i) {
        int curr = mark[i];
        // cout << "curr=" << curr << endl;
        already += curr - prev - 1;
        if(already >= effec) {
            ll preval = already - (curr - prev - 1);
            // cout << "preval=" << preval << " ";
            // cout << "already=" << already <<" prev=" << prev << endl;
            ans = prev + (effec - preval) - 1;
            break;
        }
        prev = curr;
    }
    cout << dec2bin(ans,m) << endl;
}


/**
*   @author: Kshitiz Srivastava (Pirate_ksh) @ MNNIT Allahabad
*/
#include<bits/stdc++.h>
using namespace std;

// General
#define ll long long
#define ld long double
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007 // 998244353
#define PI 3.1415926535897932384
#define endl "\n"
#define debug(x) cout<<x<<endl
#define REP(i,n) for(i=0;i<n;++i)
#define FOR(i,x,n) for(i=x;i<n;++i)
#define RREP(i,n) for(i=n-1;i>=0;--i)
#define RFOR(i,x,n) for(i=n-1;i>=x;--i)
#define TR(i,c) for(auto i=c.begin();i!=c.end();++i)
#define RTR(i,c) for(auto i=c.rbegin();i!=c.rend();++i)

// Bounds
#define lb(a,x) a.lower_bound(x)
#define ub(a,x) a.upper_bound(x)
#define all(a) a.begin(),a.end()

// Vector
#define vi vector <int>
#define pb(v,x) v.push_back(x)
#define vll vector <ll>

// Map
#define mii map <int, int>
#define umii unordered_map <int, int>

// Set
#define si set <int>
#define msi multiset<int>

// Pair
#define vpii vector<pair < int, int > >
#define vpll vector<pair < ll, ll > >
#define pii pair < int, int >
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define vppi vector<pair<pair<int,int>,int>>
#define ppi pair<pair<int,int>,int>

void solve();

int main(){
    io
    ll t;
    t=1;
    cin >> t;
    while(t--) solve();
    return 0;
}

ll power(ll x, ll y) {
    ll res = 1;
    while (y > 0) {
        if (y & 1)
            res = res * x;
        y = y>>1;
        x = x * x;
    }
    return res;
}

ll bin2dec(string &s) {
    reverse(all(s));
    ll ret = 0, n = (ll)s.length();
    for(ll i = 0; i < n; ++i)
        if(s[i] == '1') ret += power((ll)2,i);
    return ret;
}

string dec2bin(ll n, ll m) {
    string ans;
    while(n) {
        ans+=to_string(n%2);
        n/=2;
    }
    ll rem = m - (ll)ans.length();
    while(rem--) pb(ans,'0');
    reverse(all(ans));
    return ans;
}

void solve() {
    ll i, j, n, m, effec;
    cin >> n >> m;
    effec = power((ll)2,m) - n;
    effec -= 1;
    effec /= 2;
    vector<string> s(n);
    REP(i,n) cin >> s[i];
    mii mark;
    REP(i,n) {
        ll dec = bin2dec(s[i]);
        mark[dec+1] = 1;
    }
    mark[power((ll)2,m)+(ll)1] = 1;
    effec += 1;
    // cout << "effec=" << effec << endl;
    ll already = 0, prev = 0, ans;
    for(auto i=mark.begin(); i != mark.end(); ++i) {
        int curr = i -> F;
        // cout << "curr=" << curr << endl;
        already += curr - prev - 1;
        if(already >= effec) {
            ll preval = already - (curr - prev - 1);
            // cout << "preval=" << preval << " ";
            // cout << "already=" << already <<" prev=" << prev << endl;
            ans = prev + (effec - preval) - 1;
            break;
        }
        prev = curr;
    }
    cout << dec2bin(ans,m) << endl;
}


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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=1e5 + 5;
const int M=1e9 + 7;

int n,m;
vi v;
int tot;
int lef;
int tar;

int check(int x)
{
	int toleft = x;
	int c=0;
	for(int xx:v)
	{
		if(xx<=x)
			c++;
		else
			break;
	}
	toleft -= c;
	if(toleft>=tar)
		return 1;
	return 0;
}

int binsearch(int lo, int hi)
{
	while(lo<hi)
	{
		int mid=(lo+hi)>>1;
		if(check(mid))
			hi=mid;
		else
			lo= mid+1;
	}
	return lo;
}

int32_t main()
{
	IOS;
	//memset(dp,-1,sizeof(dp));
	int T;
	cin >> T;
	while(T--)
	{
		v.clear();
		cin >> n >> m;
		rep(i,1,n)
		{
			string s;
			cin >> s;
			unsigned long decimal = std::bitset<64>(s).to_ulong();
    		int dec= decimal;
    		v.pb(dec);
		}
		tot = pow(2,m);
		lef = tot - n;
		sort(all(v));
		if(lef%2==1)
			tar = lef/2;
		else
			tar = lef/2-1;
//		cout << tar << endl;
//		for(int x:v)
//			cout << x << " ";
//		cout << endl;
//		rep(i,0,tot-1)
//		{
//			cout << i << " " << check(i) << endl;
//		}
		int ans = binsearch(0,tot-1);
		//cout << ans << endl;
		if(ans==0)
		{
			rep(j,0,m-1)
				cout << "0";
			cout << endl;
			continue;
		}
		std::string anss = std::bitset<64>(ans).to_string();
    	int j=0;
    	while(anss[j]=='0')
    		j++;
    	string ss =  anss.substr(j,anss.size()-j);
    	while(ss.size()<m)
    		ss = "0" + ss;
    	cout << ss << endl;
	}
}


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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=1e5 + 5;
const int M=1e9 + 7;

int n,m;
vi v;
int tot;
int lef;
int tar;

int check(int x)
{
	int toleft = x;
	int c=0;
	for(int xx:v)
	{
		if(xx<=x)
			c++;
		else
			break;
	}
	toleft -= c;
	if(toleft>=tar)
		return 1;
	return 0;
}

int binsearch(int lo, int hi)
{
	while(lo<hi)
	{
		int mid=(lo+hi)>>1;
		if(check(mid))
			hi=mid;
		else
			lo= mid+1;
	}
	return lo;
}

int32_t main()
{
	IOS;
	//memset(dp,-1,sizeof(dp));
	int T;
	cin >> T;
	while(T--)
	{
		v.clear();
		cin >> n >> m;
		rep(i,1,n)
		{
			string s;
			cin >> s;
			unsigned long decimal = std::bitset<67>(s).to_ulong();
    		int dec= decimal;
    		v.pb(dec);
		}
		tot = pow(2,m);
		lef = tot - n;
		sort(all(v));
		if(lef%2==1)
			tar = lef/2;
		else
			tar = lef/2-1;
//		cout << tar << endl;
//		for(int x:v)
//			cout << x << " ";
//		cout << endl;
//		rep(i,0,tot-1)
//		{
//			cout << i << " " << check(i) << endl;
//		}
		int ans = binsearch(0,tot-1);
		//cout << ans << endl;
		if(ans==0)
		{
			rep(j,0,m-1)
				cout << "0";
			cout << endl;
			continue;
		}
		std::string anss = std::bitset<67>(ans).to_string();
    	int j=0;
    	while(anss[j]=='0')
    		j++;
    	string ss =  anss.substr(j,anss.size()-j);
    	while(ss.size()<m)
    		ss = "0" + ss;
    	cout << ss << endl;
	}
}


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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=1e5 + 5;
const int M=1e9 + 7;

int n,m;
vi v;
int tot;
int lef;
int tar;

int check(int x)
{
	int toleft = x;
	int c=0;
	for(int xx:v)
	{
		if(xx<=x)
			c++;
		else
			break;
	}
	toleft -= c;
	if(toleft>=tar)
		return 1;
	return 0;
}

int binsearch(int lo, int hi)
{
	while(lo<hi)
	{
		int mid=(lo+hi)>>1;
		if(check(mid))
			hi=mid;
		else
			lo= mid+1;
	}
	return lo;
}

int32_t main()
{
	IOS;
	//memset(dp,-1,sizeof(dp));
	int T;
	cin >> T;
	while(T--)
	{
		v.clear();
		cin >> n >> m;
		rep(i,1,n)
		{
			string s;
			cin >> s;
			unsigned long decimal = std::bitset<64>(s).to_ulong();
    		int dec= decimal;
    		v.pb(dec);
		}
		tot = pow(2,m);
		lef = tot - n;
		sort(all(v));
		if(lef%2==1)
			tar = lef/2;
		else
			tar = lef/2-1;
//		cout << tar << endl;
//		for(int x:v)
//			cout << x << " ";
//		cout << endl;
//		rep(i,0,tot-1)
//		{
//			cout << i << " " << check(i) << endl;
//		}
		int ans = binsearch(0,tot-1);
		//cout << ans << endl;
		if(ans==0)
		{
			rep(j,0,m-1)
				cout << "0";
			cout << endl;
			continue;
		}
		for(int i = m - 1; i >= 0; i--)
			cout << (ans >> i & 1);
		cout << endl;
	}
}


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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=1e5 + 5;
const int M=1e9 + 7;

int n,m;
vi v;
int tot;
int lef;
int tar;

int check(int x)
{
	int toleft = x;
	int c=0;
	for(int xx:v)
	{
		if(xx<=x)
			c++;
		else
			break;
	}
	toleft -= c;
	if(toleft>=tar)
		return 1;
	return 0;
}

int binsearch(int lo, int hi)
{
	while(lo<hi)
	{
		int mid=(lo+hi)>>1;
		if(check(mid))
			hi=mid;
		else
			lo= mid+1;
	}
	return lo;
}

int32_t main()
{
	IOS;
	//memset(dp,-1,sizeof(dp));
	int T;
	cin >> T;
	while(T--)
	{
		v.clear();
		cin >> n >> m;
		rep(i,1,n)
		{
			string s;
			cin >> s;
			int val=0;
			for(auto &it:s)
				val = val * 2 + (it - '0');
			//cout << val << " ";
    		v.pb(val);
		}
		//cout << endl;
		tot = pow(2,m);
		lef = tot - n;
		sort(all(v));
		if(lef%2==1)
			tar = lef/2;
		else
			tar = (lef/2)-1;
		int ans = binsearch(0,tot-1);
		if(ans==0)
		{
			rep(j,0,m-1)
				cout << "0";
			cout << endl;
			continue;
		}
		for(int i = m - 1; i >= 0; i--)
			cout << (ans >> i & 1);
		cout << endl;
//		std::string anss = std::bitset<67>(ans).to_string();
//    	int j=0;
//    	while(anss.size()>m)
//    		anss.erase(anss.begin());
//    	cout << anss << endl;
	}
}


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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=1e5 + 5;
const int M=1e9 + 7;

int n,m;
vi v;
int tot;
int lef;
int tar;

int check(int x)
{
	int toleft = x;
	int c=0;
	for(int xx:v)
	{
		if(xx<=x)
			c++;
		else
			break;
	}
	toleft -= c;
	if(toleft>=tar)
		return 1;
	return 0;
}

int binsearch(int lo, int hi)
{
	while(lo<hi)
	{
		int mid=(lo+hi)>>1;
		if(check(mid))
			hi=mid;
		else
			lo= mid+1;
	}
	return lo;
}

int32_t main()
{
	IOS;
	//memset(dp,-1,sizeof(dp));
	int T;
	cin >> T;
	while(T--)
	{
		v.clear();
		cin >> n >> m;
		rep(i,1,n)
		{
			string s;
			cin >> s;
			int val=0;
			for(auto &it:s)
				val = val * 2 + (it - '0');
			//cout << val << " ";
    		v.pb(val);
		}
		tot = pow(2,m);
		lef = tot - n;
		sort(all(v));
		if(lef%2==1)
			tar = lef/2;
		else
			tar = lef/2-1;
//		cout << tar << endl;
//		for(int x:v)
//			cout << x << " ";
//		cout << endl;
//		rep(i,0,tot-1)
//		{
//			cout << i << " " << check(i) << endl;
//		}
		int ans = binsearch(0,tot-1);
		//cout << ans << endl;
		if(ans==0)
		{
			rep(j,0,m-1)
				cout << "0";
			cout << endl;
			continue;
		}
		std::string anss = std::bitset<64>(ans).to_string();
    	int j=0;
    	while(anss[j]=='0')
    		j++;
    	string ss =  anss.substr(j,anss.size()-j);
    	while(ss.size()<m)
    		ss = "0" + ss;
    	cout << ss << endl;
	}
}


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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=1e5 + 5;
const int M=1e9 + 7;

int n,m;
vi v;
int tot;
int lef;
int tar;

int check(int x)
{
	int toleft = x;
	int c=0;
	for(int xx:v)
	{
		if(xx<=x)
			c++;
		else
			break;
	}
	toleft -= c;
	if(toleft>=tar)
		return 1;
	return 0;
}

int binsearch(int lo, int hi)
{
	while(lo<hi)
	{
		int mid=(lo+hi)>>1;
		if(check(mid))
			hi=mid;
		else
			lo= mid+1;
	}
	return lo;
}

int32_t main()
{
	IOS;
	//memset(dp,-1,sizeof(dp));
	int T;
	cin >> T;
	while(T--)
	{
		v.clear();
		cin >> n >> m;
		rep(i,1,n)
		{
			string s;
			cin >> s;
			unsigned long decimal = std::bitset<67>(s).to_ulong();
    		int dec= decimal;
    		v.pb(dec);
		}
		tot = pow(2,m);
		lef = tot - n;
		sort(all(v));
		if(lef%2==1)
			tar = lef/2;
		else
			tar = lef/2-1;
		int ans = binsearch(0,tot-1);
		if(ans==0)
		{
			rep(j,0,m-1)
				cout << "0";
			cout << endl;
			continue;
		}
		std::string anss = std::bitset<67>(ans).to_string();
    	int j=0;
    	while(anss.size()>m)
    		anss.erase(anss.begin());
    	cout << anss << endl;
	}
}


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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=1e5 + 5;
const int M=1e9 + 7;

int n,m;
vi v;
int tot;
int lef;
int tar;

int check(int x)
{
	int toleft = x;
	int c=0;
	for(int xx:v)
	{
		if(xx<=x)
			c++;
		else
			break;
	}
	toleft -= c;
	if(toleft>=tar)
		return 1;
	return 0;
}

int binsearch(int lo, int hi)
{
	while(lo<hi)
	{
		int mid=(lo+hi)>>1;
		if(check(mid))
			hi=mid;
		else
			lo= mid+1;
	}
	return lo;
}

int32_t main()
{
	IOS;
	//memset(dp,-1,sizeof(dp));
	int T;
	cin >> T;
	while(T--)
	{
		v.clear();
		cin >> n >> m;
		rep(i,1,n)
		{
			string s;
			cin >> s;
			unsigned long decimal = std::bitset<67>(s).to_ulong();
    		int dec= decimal;
    		v.pb(dec);
		}
		tot = pow(2,m);
		lef = tot - n;
		sort(all(v));
		if(lef%2==1)
			tar = lef/2;
		else
			tar = (lef/2)-1;
		int ans = binsearch(0,tot-1);
		if(ans==0)
		{
			rep(j,0,m-1)
				cout << "0";
			cout << endl;
			continue;
		}
		std::string anss = std::bitset<67>(ans).to_string();
    	int j=0;
    	while(anss.size()>m)
    		anss.erase(anss.begin());
    	cout << anss << endl;
	}
}


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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=1e5 + 5;
const int M=1e9 + 7;

int n,m;
vi v;
int tot;
int lef;
int tar;

int check(int x)
{
	int toleft = x;
	int c=0;
	for(int xx:v)
	{
		if(xx<=x)
			c++;
		else
			break;
	}
	toleft -= c;
	if(toleft>=tar)
		return 1;
	return 0;
}

int binsearch(int lo, int hi)
{
	while(lo<hi)
	{
		int mid=(lo+hi)>>1;
		if(check(mid))
			hi=mid;
		else
			lo= mid+1;
	}
	return lo;
}

int32_t main()
{
	IOS;
	//memset(dp,-1,sizeof(dp));
	int T;
	cin >> T;
	while(T--)
	{
		v.clear();
		cin >> n >> m;
		rep(i,1,n)
		{
			string s;
			cin >> s;
			unsigned long long decimal = std::bitset<67>(s).to_ulong();
    		int dec= decimal;
    		v.pb(dec);
		}
		tot = pow(2,m);
		lef = tot - n;
		sort(all(v));
		if(lef%2==1)
			tar = lef/2;
		else
			tar = (lef/2)-1;
		int ans = binsearch(0,tot-1);
		if(ans==0)
		{
			rep(j,0,m-1)
				cout << "0";
			cout << endl;
			continue;
		}
		std::string anss = std::bitset<67>(ans).to_string();
    	int j=0;
    	while(anss.size()>m)
    		anss.erase(anss.begin());
    	cout << anss << endl;
	}
}


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

void decToBinary(int n,int m)
{
    // Size of an integer is assumed to be 32 bits
    for (int i = m-1; i >= 0; i--) {
        int k = n >> i;
        if (k & 1)
            cout << "1";
        else
            cout << "0";
    }
}
long long int c(string m){
    reverse(m.begin(), m.end());
    long long int a = 0,p = 1;
    for(int i = 0; i < m.size();i++){
        a += (m[i] - '0')*p;
        p*=2;
    }
    return a;
}

int main()
{
    int t;
    cin>>t;
    while(t--){
        int n,m;
        long long int ans;
        cin>>n>>m;
        vector <long long int> v;
        for(int i = 0;i < n;i++){
            string str;
            cin>>str;
            v.push_back(c(str));
        }

        int flag = 0;
        long long int mid  = ((1<<m)- 2)/2;
        vector <long long int> vis(1000000,0);
        for(int i = 0;i<n;i++){
            vis[v[i]] = 1;
            if(flag==0){
                if(v[i]<=mid){
                    mid+=1;
                    while(vis[mid]!=0){
                        //cout<<"YAY"<<"\n";
                        mid+=1;
                    }

                }
                else{

                }
            }
            else if(flag == 1){
                if(v[i]<mid){

                }
                else{
                    mid-=1;
                    while(vis[mid]!=0&&mid>=0){
                        mid-=1;
                    }

                }
            }
            //cout<<mid<<"\n";
            flag =  1 - flag;

        }
        decToBinary(mid,m);
        cout<<"\n";

    }

    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
void decToBinary(int n,int m)
{
    // Size of an integer is assumed to be 32 bits
    for (int i = m-1; i >= 0; i--) {
        int k = n >> i;
        if (k & 1)
            cout << "1";
        else
            cout << "0";
    }
}
long long int c(string m){
    reverse(m.begin(), m.end());
    long long int a = 0,p = 1;
    for(int i = 0; i < m.size();i++){
        a += (m[i] - '0')*p;
        p*=2;
    }
    return a;
}

int main()
{
    int t;
    cin>>t;
    while(t--){
        int n,m;
        long long int ans;
        cin>>n>>m;
        vector <long long int> v;
        for(int i = 0;i < n;i++){
            string str;
            cin>>str;
            v.push_back(c(str));
        }

        int flag = 0;
        long long int mid  = ((1<<m)- 2)/2;

        for(int i = 0;i<n;i++){
            if(flag==0){
                if(v[i]<=mid){
                    mid+=1;
                }
                else{

                }
            }
            else if(flag == 1){
                if(v[i]<mid){

                }
                else{
                    mid = mid - 1;
                }
            }
            flag =  1 - flag;

        }
        decToBinary(mid,m);
        cout<<"\n";

    }

    return 0;
}


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

void decToBinary(int n,int m)
{
    // Size of an integer is assumed to be 32 bits
    for (int i = m-1; i >= 0; i--) {
        int k = n >> i;
        if (k & 1)
            cout << "1";
        else
            cout << "0";
    }
}
long long int c(string m){
    reverse(m.begin(), m.end());
    long long int a = 0,p = 1;
    for(int i = 0; i < m.size();i++){
        a += (m[i] - '0')*p;
        p*=2;
    }
    return a;
}

int main()
{
    int t;
    cin>>t;
    while(t--){
        int n,m;
        long long int ans;
        cin>>n>>m;
        vector <long long int> v;
        for(int i = 0;i < n;i++){
            string str;
            cin>>str;
            v.push_back(c(str));
        }

        int flag = 0;
        long long int mid  = ((1<<m)- 2)/2;
        vector <long long int> vis(10000000000,0);
        for(int i = 0;i<n;i++){
            vis[v[i]] = 1;
            if(flag==0){
                if(v[i]<=mid){
                    mid+=1;
                    while(vis[mid]!=0){
                        //cout<<"YAY"<<"\n";
                        mid+=1;
                    }

                }
                else{

                }
            }
            else if(flag == 1){
                if(v[i]<mid){

                }
                else{
                    mid-=1;
                    while(vis[mid]!=0&&mid>=0){
                        mid-=1;
                    }

                }
            }
            //cout<<mid<<"\n";
            flag =  1 - flag;

        }
        decToBinary(mid,m);
        cout<<"\n";

    }

    return 0;
}


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

void decToBinary(int n,int m)
{
    // Size of an integer is assumed to be 32 bits
    for (int i = m-1; i >= 0; i--) {
        int k = n >> i;
        if (k & 1)
            cout << "1";
        else
            cout << "0";
    }
}
long long int c(string m){
    reverse(m.begin(), m.end());
    long long int a = 0,p = 1;
    for(int i = 0; i < m.size();i++){
        a += (m[i] - '0')*p;
        p*=2;
    }
    return a;
}

int main()
{
    int t;
    cin>>t;
    while(t--){
        int n,m;
        long long int ans;
        cin>>n>>m;
        vector <long long int> v;
        for(int i = 0;i < n;i++){
            string str;
            cin>>str;
            v.push_back(c(str));
        }

        int flag = 0;
        long long int mid  = ((1ll<<m)- 2)/2;
        unordered_map<long long int,int> vis;
        //for(int i = 0;i < n;i++) vis[v[i]] = 1;
        for(int i = 0;i<n;i++){
            vis[v[i]] = 1;
            if(flag==0){
                if(v[i]<=mid){
                    mid+=1;
                    while(vis[mid]==1){
                        //cout<<"YAY"<<"\n";
                        mid+=1;
                    }

                }
                else{

                }
            }
            else if(flag == 1){
                if(v[i]<mid){

                }
                else{
                    mid-=1;
                    while(vis[mid]==1&&mid>=0){
                        mid-=1;
                    }

                }
            }
            //cout<<mid<<"\n";
            flag =  1 - flag;

        }
        decToBinary(mid,m);
        cout<<"\n";

    }

    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
#define max LLONG_MAX
void decToBinary(int n,int m)
{
    // Size of an integer is assumed to be 32 bits
    for (int i = m-1; i >= 0; i--) {
        int k = n >> i;
        if (k & 1)
            cout << "1";
        else
            cout << "0";
    }
}
long long int c(string m){
    reverse(m.begin(), m.end());
    long long int a = 0,p = 1;
    for(int i = 0; i < m.size();i++){
        a += (m[i] - '0')*p;
        p*=2;
    }
    return a;
}

int main()
{
    int t;
    cin>>t;
    while(t--){
        int n,m;
        long long int ans;
        cin>>n>>m;
        vector <long long int> v;
        for(int i = 0;i < n;i++){
            string str;
            cin>>str;
            v.push_back(c(str));
        }

        int flag = 0;
        long long int mid  = ((1<<m)- 2)/2;
        vector <long long int> vis(max,0);
        for(int i = 0;i<n;i++){
            vis[v[i]] = 1;
            if(flag==0){
                if(v[i]<=mid){
                    mid+=1;
                    while(vis[mid]!=0){
                        //cout<<"YAY"<<"\n";
                        mid+=1;
                    }

                }
                else{

                }
            }
            else if(flag == 1){
                if(v[i]<mid){

                }
                else{
                    mid-=1;
                    while(vis[mid]!=0&&mid>=0){
                        mid-=1;
                    }

                }
            }
            //cout<<mid<<"\n";
            flag =  1 - flag;

        }
        decToBinary(mid,m);
        cout<<"\n";

    }

    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
using ll = long long;
void decToBinary(long long int n,int m)
{
    // Size of an integer is assumed to be 32 bits
    for (int i = m-1; i >= 0; i--) {
        long long int k = n >> i;
        if (k & 1)
            cout << "1";
        else
            cout << "0";
    }
}
long long int c(string m){
    reverse(m.begin(), m.end());
    long long int a = 0,p = 1;
    for(int i = 0; i < m.size();i++){
        a += (m[i] - '0')*p;
        p*=2;
    }
    return a;
}

int main()
{
    int t;
    cin>>t;
    while(t--){
        int n,m;
        long long int ans;
        cin>>n>>m;
        vector <long long int> v;
        for(int i = 0;i < n;i++){
            string str;
            cin>>str;
            v.push_back(c(str));
        }

        int flag = 0;
        long long int mid  = ((1ll<<m)- 2)/2;
        unordered_map<long long int,int> vis;
        //for(int i = 0;i < n;i++) vis[v[i]] = 1;
        for(int i = 0;i<n;i++){
            vis[v[i]] = 1;
            if(flag==0){
                if(v[i]<=mid){
                    mid+=1;
                    while(vis[mid]==1){
                        //cout<<"YAY"<<"\n";
                        mid+=1;
                    }

                }
                else{

                }
            }
            else if(flag == 1){
                if(v[i]<mid){

                }
                else{
                    mid-=1;
                    while(vis[mid]==1&&mid>=0){
                        mid-=1;
                    }

                }
            }
            //cout<<mid<<"\n";
            flag =  1 - flag;

        }
        decToBinary(mid,m);
        cout<<"\n";

    }

    return 0;
}