Problem: A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!

You are given integers n,k. Construct a grid A with size n × n consisting of integers 0 and 1. The very important condition should be satisfied: the sum of all elements in the grid is exactly k. In other words, the number of 1 in the grid is equal to k.

Let's define:

  * A_{i,j} as the integer in the i-th row and the j-th column. 
  * R_i = A_{i,1}+A_{i,2}+...+A_{i,n} (for all 1 ≤ i ≤ n). 
  * C_j = A_{1,j}+A_{2,j}+...+A_{n,j} (for all 1 ≤ j ≤ n). 
  * In other words, R_i are row sums and C_j are column sums of the grid A. 
  * For the grid A let's define the value f(A) = (max(R)-min(R))^2 + (max(C)-min(C))^2 (here for an integer sequence X we define max(X) as the maximum value in X and min(X) as the minimum value in X). 



Find any grid A, which satisfies the following condition. Among such grids find any, for which the value f(A) is the minimum possible. Among such tables, you can find any.

Input

The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases. Next t lines contain descriptions of test cases.

For each test case the only line contains two integers n, k (1 ≤ n ≤ 300, 0 ≤ k ≤ n^2).

It is guaranteed that the sum of n^2 for all test cases does not exceed 10^5.

Output

For each test case, firstly print the minimum possible value of f(A) among all tables, for which the condition is satisfied.

After that, print n lines contain n characters each. The j-th character in the i-th line should be equal to A_{i,j}.

If there are multiple answers you can print any.

Example

Input


4
2 2
3 8
1 0
4 16


Output


0
10
01
2
111
111
101
0
0
0
1111
1111
1111
1111

Note

In the first test case, the sum of all elements in the grid is equal to 2, so the condition is satisfied. R_1 = 1, R_2 = 1 and C_1 = 1, C_2 = 1. Then, f(A) = (1-1)^2 + (1-1)^2 = 0, which is the minimum possible value of f(A).

In the second test case, the sum of all elements in the grid is equal to 8, so the condition is satisfied. R_1 = 3, R_2 = 3, R_3 = 2 and C_1 = 3, C_2 = 2, C_3 = 3. Then, f(A) = (3-2)^2 + (3-2)^2 = 2. It can be proven, that it is the minimum possible value of f(A).

Solution (in JAVA):

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


public class Equal {
    static class pair implements Comparable<pair> {
        int v, w;

        public pair(int v, int w) {
            this.v = v;
            this.w = w;
        }

        @Override
        public int compareTo(pair o) {
            if (v == o.v)
                return w - o.w;
            return o.v - v;
        }
    }

    static class tri implements Comparable<tri> {
        int v, i, j;

        public tri(int v, int i, int j) {
            this.v = v;
            this.i = i;
            this.j = j;
        }

        @Override
        public int compareTo(tri o) {

            return v - o.v;
        }
    }

    static ArrayList<Integer>[] tree;
    static int timer = 0;
    static int[] timein;
    static int[] timeout;
    static int[][] powerParent;
    static int[] depth;
    static int[][] minWeight;

    static void dfs(int u, int parent) {

        timein[u] = ++timer;
//        powerParent[u][0] = parent;
////        minWeight[u][0] = weight;
//        if (parent == -1)
//            powerParent[u][0] = u;
//        for (int i = 1; i <= 32; i++) {
//            powerParent[u][i] = powerParent[powerParent[u][i - 1]][i - 1];
//            minWeight[u][i] = Math.min(minWeight[u][i - 1], minWeight[powerParent[u][i - 1]][i - 1]);
//        }
        for (int i = 0; i < tree[u].size(); i++) {
            int v = tree[u].get(i);
            if (v == parent)
                continue;
            depth[v] = depth[u] + 1;
            dfs(v, u);
        }


        timeout[u] = timer;
    }

    static boolean isAncestor(int u, int v) {
        return timein[u] <= timein[v] && timeout[v] <= timeout[u];
    }

    static int lca(int u, int v) {
        if (isAncestor(u, v))
            return u;
        if (isAncestor(v, u))
            return v;
        for (int i = 32; i >= 0; i--) {
            int temp = powerParent[u][i];
            if (!isAncestor(temp, v)) {
                u = temp;
            }
        }
        return powerParent[u][0];
    }

    static int distance(int u, int v) {
        return depth[u] + depth[v] - 2 * depth[lca(u, v)];
    }

    static int nthAncestor(int u, int n) {
        int c = -1;

        while (n > 0) {
            c++;
            if (n % 2 == 0) {
                n /= 2;
                continue;
            }
            u = powerParent[u][c];
            n /= 2;

        }
        return u;
    }

    static int nthMinWeight(int u, int n) {
        int c = -1;

        int min = (int) (1e9);
        while (n > 0) {
            c++;
            if (n % 2 == 0) {
                n /= 2;
                continue;
            }
            min = Math.min(min, minWeight[u][c]);
            u = powerParent[u][c];
            n /= 2;

        }
        return min;
    }


    static class SegmentTree {        // 1-based DS, OOP

        int N;            //the number of elements in the array as a power of 2 (i.e. after padding)
        int[] array, lazy;
        double[] sTree;

        public SegmentTree(int[] in) {
            array = in;
            N = in.length - 1;
            sTree = new double[N << 1];        //no. of nodes = 2*N - 1, we add one to cross out index zero
            lazy = new int[N << 1];
            build(1, 1, N);
        }

        public void build(int node, int b, int e)    // O(n)
        {
            if (b == e)
                sTree[node] = array[b];
            else {
                int mid = b + e >> 1;
                build(node << 1, b, mid);
                build(node << 1 | 1, mid + 1, e);
                sTree[node] = sTree[node << 1] + sTree[node << 1 | 1];
            }
        }


        public void update_point(int index, double oval, double nval)            // O(log n)
        {
            index += N - 1;
            sTree[index] -= oval;
            sTree[index] += nval;
            while (index > 1) {
                index >>= 1;
                sTree[index] = sTree[index << 1] + sTree[index << 1 | 1];
            }
        }


        public void update_range(int i, int j, double oval, double nval)        // O(log n)
        {
            update_range(1, 1, N, i, j, oval, nval);
        }

        public void update_range(int node, int b, int e, int i, int j, double oval, double nval) {
            if (i > e || j < b)
                return;
            if (b >= i && e <= j) {
                sTree[node] -= oval;
                sTree[node] += nval;

            } else {
                int mid = b + e >> 1;
//                propagate(node, b, mid, e);
                update_range(node << 1, b, mid, i, j, oval, nval);
                update_range(node << 1 | 1, mid + 1, e, i, j, oval, nval);
                sTree[node] = sTree[node << 1] + sTree[node << 1 | 1];
            }

        }

//        public void propagate(int node, int b, int mid, int e) {
//            lazy[node << 1] += lazy[node];
//            lazy[node << 1 | 1] += lazy[node];
//            sTree[node << 1] += (mid - b + 1) * lazy[node];
//            sTree[node << 1 | 1] += (e - mid) * lazy[node];
//            lazy[node] = 0;
//        }

        public double query(int i, int j) {
            return query(1, 1, N, i, j);
        }

        public double query(int node, int b, int e, int i, int j)    // O(log n)
        {
            if (i > e || j < b)
                return 0;
            if (b >= i && e <= j)
                return sTree[node];
            int mid = b + e >> 1;
//            propagate(node, b, mid, e);
            double q1 = query(node << 1, b, mid, i, j);
            double q2 = query(node << 1 | 1, mid + 1, e, i, j);
            return q1 + q2;

        }
    }

    public static void main(String[] args) throws IOException {
        //BufferedReader br = new BufferedReader(new FileReader("name.in"));
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        PrintWriter out = new PrintWriter(System.out);
        int T = Integer.parseInt(br.readLine());
        while (T-- > 0) {
            st = new StringTokenizer(br.readLine());
            int n = Integer.parseInt(st.nextToken());
            int k = Integer.parseInt(st.nextToken());
            if (k % n != 0)
                out.println(2);
            else out.println(0);
            int[][] c = new int[n][n];
            int cur = 0;
            int x = 0;
            int y = 0;
            int count = 0;
            while (count < k) {


                x = 0;
                y = cur++;

                c[x++][y++] = 1;
                count++;
                while (count < k && count % n != 0) {
                    if (y == n)
                        y = 0;
                    c[x++][y++] = 1;
                    count++;
                }

            }
            for (int i = 0; i <n ; i++) {
                for (int j = 0; j <n ; j++) {
                    out.print(c[i][j]);
                }
                out.println();
            }
        }

        out.flush();
        out.close();

    }


}