using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class Program
    {
        static bool Matrica_postoji(int n, int m)
        {
            bool k = true;
            if (n != m)
                k = false;
            return k;
        }

        static void Main()
        {
            int t = int.Parse(Console.ReadLine());
            List<int> A = new List<int>();
            List<int> B = new List<int>();
            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 (Matrica_postoji(n, m))
                {
                    A.Add(n);
                    B.Add(n);
                }
                else
                    B.Add(-1);
            }
            for (int l = 0; l < B.Count; l++)
            {
                if (B[l] == -1)
                    Console.WriteLine("-1");
                else
                {
                    int[,] a = new int[A[l], A[l]];
                    for (int i = 0; i < A[l]; i++)
                    {
                        for (int j = 0; j < A[l]; j++)
                        {
                            if (i == 0 || j == 0 || i == A[l] - 1 || j == A[l] - 1 || (i + j >= A[l]))
                                a[i, j] = 1;
                            else
                                a[i, j] = 0;
                            Console.Write(a[i, j] + " ");
                        }
                        Console.WriteLine();
                    }
                }
            }
        }
    }
}