internal class Program
{
    static void Main(string[] args)
    {
        int q = int.Parse(Console.ReadLine());
        while (q > 0)
        {
            q--;
            int[] ulaz = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int a, b;
            a = ulaz[0];
            b = ulaz[1];

            if (a != b)
            {
                Console.WriteLine(-1);
                continue;
            }
            else
            {
                for (int i = 0; i < a; i++)
                {
                    for (int j = 0; j < b; j++)
                    {
                        if (i == 0 || i == a - 1 || j == b - 1 || j == 0 || j + i > a || j == a - i)
                        {
                            Console.Write("1 ");
                        }
                        else
                        {
                            Console.Write("0 ");
                        }
                    }
                    Console.WriteLine();
                }
            }
        }
    }
}