using System;

class ZADATAK
{
    static void Main()
    {
        int T = int.Parse(Console.ReadLine());
        int[] N = new int[T];
        int[] M = new int[T];
        for (int i = 0; i < T; i++)
        {
            string[] unos = Console.ReadLine().Split();
            N[i] = int.Parse(unos[0]);
            M[i] = int.Parse(unos[1]);
        }
        for (int k = 0; k < T; k++)
        {
            int N0 = N[k];
            int M0 = M[k];
            if (N0 != M0)
            {
                Console.WriteLine(-1);
                continue;
            }
            int[,] matrica = new int[N0, M0];
            int br = 1;
            for (int i = 0; i < N0; i++)
            {
                for (int j = 0; j < M0; j++)
                {
                    if (i == 0 || i == N0 - 1 || j == 0 || j == M0 - 1)
                    {
                        Console.Write(1);
                        continue;
                    }
                    else if (j < M0 - br)
                    {
                        Console.Write(0);
                        continue;
                    }
                    else
                    {
                        Console.Write(1);
                        continue;
                    }
                }
                Console.WriteLine();
                br++;
            }
        }
    }
}