using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
    static void Main(string[] args)
    {
        int t = int.Parse(Console.ReadLine());
        for (int i = 0; i < t; i++)
        {
            string[] s = Console.ReadLine().Split();
            int n = int.Parse(s[0]); int m = int.Parse(s[1]);
            if (n != m) Console.WriteLine(-1);
            else
            {
                int[,] ma = new int[n, m];
                int ix = n - 1; int rd = 0;
                while (ix >= 0)
                {
                    for (int j = 0; j < n; j++)
                    {
                        if(j >= ix) ma[rd, j] = 1;
                        Console.Write(ma[rd, j] + " ");
                    }
                    rd++; ix--;
                    Console.WriteLine();
                }
            }
        }
    }
}