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 = ix; j < n; j++)
                    {
                        ma[rd, j] = 1;
                    }
                    rd++; ix--;
                }
                for (int v = 0; v < n; v++)
                {
                    for (int k = 0; k < m; k++)
                    {
                        Console.Write(ma[v, k] + " ");
                    }
                    Console.WriteLine();
                }
            }
        }
    }
}