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

namespace ConsoleApp1
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int t = Convert.ToInt32(Console.ReadLine());
            for (int i = 0; i < t; i++)
            {
                string[] unos = Console.ReadLine().Split(' ');
                int n = Convert.ToInt32(unos[0]);
                int m = Convert.ToInt32(unos[1]);
                int[,]matrica= new int[n+1, m+1];   
                Dictionary<int, List<int>> vrednostvrste = new Dictionary<int, List<int>>();
                if (m != n) Console.WriteLine(-1);
                else
                {
                    for (int red = 1; red <= n; red++) 
                    {
                        for (int kolona = 1; kolona <= n; kolona++) 
                        {
                            if (kolona == 1 || kolona == m || red == 1 || red == m) matrica[red, kolona] = 1;
                            else if (kolona + red > m + 1) matrica[red, kolona] = 1;
                            else matrica[red, kolona] = 0;

                            Console.Write(matrica[red, kolona] + " ");
                        }
                        Console.WriteLine();
                    }
                   



                }
            }
        }
    }
}