int t = int.Parse(Console.ReadLine());
int[] m = new int[t];
int[] n = new int[t];

for(int i = 0 ; i < t; i++)
{
    string[] unos = Console.ReadLine().Split(' ');
    n[i] = int.Parse(unos[0]);
    m[i] = int.Parse(unos[1]);
    int[,] mat = new int[n[i], m[i]];
}
for (int i = 0; i < t; i++)
{
    

    if (m[i] == n[i])
    {
        for (int j = 0; j < n[i]; j++)
        {
            for (int k = 0; k < m[i]; k++)
            {

                if (j == 0 || j == n[i] - 1 || k == 0 || k == n[i] - 1)
                {
                    Console.Write(1 + " ");
                }
                else
                {
                    if (j + k >= m[i])
                    {
                        Console.Write(1 + " ");
                    }
                    else
                    {
                        Console.Write(0 + " ");
                    }
                }

            }
            Console.WriteLine();
        }
    }
    else
    {
        Console.WriteLine(-1);
    }
}