using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int T = int.Parse(Console.ReadLine());
            for (int x = 0; x < T; x++)
            {
                string [] unos = Console.ReadLine().Split();
                int n = int.Parse(unos[0]);
                int m = int.Parse(unos[1]);
                int [,] matrica = new int [n, m];
                int ukupnoPolja = n * m;
                long brojKombinacija = (long)Math.Pow(2, ukupnoPolja);
                for (long i = 0; i < brojKombinacija; i++)
                {
                    int [,] mat = Generisi(brojKombinacija, n, m);
                    if (Uslovi(mat, n, m))
                    {
                        ispis(mat, n, m);
                        break;
                    }
                    else
                    {
                        Console.WriteLine("-1");
                        break;
                    }
                }
            }
        }
        static int [,] Generisi(long k, int r, int c)
        {
            int[,] m = new int[r, c];
            for (int i = r-1; i >= 0; i--)
            {
                for (int j = c-1; j >= 0; j--)
                {
                    m[i, j] = (int)(k % 2);
                }
            }
            return m;
        }
        static bool Uslovi(int [,] matrica, int n, int m)
        {
            if (Jedinica(matrica, n, m))
            {
                for (int i = 1; i <= n; i++)
                {
                    int red = ZbirReda(matrica, m, i - 1);
                    if (red % i == 0)
                    {
                    }
                    else
                    {
                        return false;
                    }
                }
                for (int i = 1; i <= m; i++)
                {
                    int kolona = ZbirKolone(matrica, n, i - 1);
                    if (kolona % i == 0)
                    {
                    }
                    else
                    {
                        return false;
                    }
                }
                return true;
            }
            else
            {
                return false;
            }
        }
        static int ZbirReda(int [,] mat, int red, int m)
        {
            int s = 0;
            for (int i = 0; i < m; i++)
            {
                s += mat[red, i];
            }
            return s;
        }
        static int ZbirKolone(int[,] matrica, int kolona, int n)
        {
            int s = 0;
            for (int j = 0; j < n; j++)
            {
                s += matrica[j, kolona];
            }
            return s;
        }
        static bool Jedinica (int [,] matrica, int n, int m)
        {
            for (int i =0; i < n; i++)
            {
                bool red = false;
                for (int j = 0; j < m; j++)
                {
                    if (matrica[i, j] == 1)
                    {
                        red = true; 
                        break;
                    }
                }
                if (!red)
                {
                    return false;
                }
            }
            for (int j = 0; j<m; j++)
            {
                bool red = false;
                for (int i = 0; i < n; i++)
                {
                    if (matrica[i, j] == 1)
                    {
                        red = true;
                        break;
                    }
                }
                if (!red)
                {
                    return false;
                }
            }
            return true;
        }
        static void ispis(int[,] matrica, int n, int m)
        {
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    Console.Write(matrica[i, j] + " ");
                }
                Console.WriteLine();
            }
        }
    }
}