using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    internal class Program
    {
        static void Provera(int N, int M)
        {
            if (N != M)
            {
                Console.WriteLine(-1);
                return;
            }

            string output = "";

            for (int kolona = 1; kolona <= M; kolona++)
            {
                for (int red = 1; red <= N; red++)
                {
                    if (red == 1 || kolona == 1 || red == M || kolona == N)
                    {
                        //Console.WriteLine("Ispis");
                        output += "1 ";
                        continue;
                    }

                    if ((N - kolona) >= (red - 1))
                    {
                        output += "0 ";

                    }
                    else output += "1 ";
                }
                output += "\n";
            }

            Console.Write(output);
        }

        static void Main(string[] args)
        {
            int T = int.Parse(Console.ReadLine());

            int[][] inputs = new int[T][];

            for (int i = 0; i < T; i++)
            {
                inputs[i] = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            }

            for (int i = 0; i < T; i++)
            {
                Provera(inputs[i][0], inputs[i][1]);
            }
        }
    }
}