using System;
using System.Text;

class Program
{
    static void Main()
    {
        int t = int.Parse(Console.ReadLine());
        var sb = new StringBuilder();

        while (t-- > 0)
        {
            var s = Console.ReadLine().Split();
            int n = int.Parse(s[0]);
            int m = int.Parse(s[1]);

            if (n != m)
            {
                sb.AppendLine("-1");
                continue;
            }

            for (int i = 1; i <= n; i++)
            {
                for (int j = 1; j <= n; j++)
                {
                    if (i > 1 && j > 1 && i + j <= n + 1)
                        sb.Append("0");
                    else
                        sb.Append("1");

                    if (j < n) sb.Append(" ");
                }
                sb.AppendLine();
            }
        }

        Console.Write(sb.ToString());
    }
}