using System;

class ZADATAK
{
    static void Main()
    {
        int T = int.Parse(Console.ReadLine());
        for(int k = 0; k < T; k++)
        {
            string[] unos = Console.ReadLine().Split();
            int N = int.Parse(unos[0]);
            int M = int.Parse(unos[1]);
            if (N != M)
            {
                Console.WriteLine(-1);
                continue;
            }
            int[,] matrica = new int[N, M];
            for (int i = 0; i < N; i++)
            {
                int br = 2;
                for (int j = M - 1; j >= 0; j--)
                {
                    if (i == 0 || i == N - 1 || j == 0 || j == M - 1)
                    {
                        matrica[i, j] = 1;
                        continue;
                    }
                    if (br % (i + 1) != 0)
                    {
                        matrica[i, j] = 1;
                        br++;
                        continue;
                    }
                    matrica[i, j] = 0;
                }
            }
            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < M; j++)
                    Console.Write(matrica[i, j] + " ");
                Console.WriteLine();
            }
        }
    }
}