namespace okruznotakmicenje
{
    internal class Program
    {

        static void Main(string[] args)
        {
           int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                string[] s = Console.ReadLine().Split(' ');
                for (int j = 0; j < 1; j++)
                {
                    int k = int.Parse(s[0]);
                    int m = int.Parse(s[1]);
                    int[,] mars = new int[k, m];

                    for (int x = 0; x < k; x++)
                    {
                        for (int y = 0; y < m; y++)
                        {

                            if (m > k || k > m)
                            {
                                Console.WriteLine(-1);
                                break;
                            }
                            if (x + 1 == 1 || x + 1 == k || y + 1 == m || y + 1 == 1 || x+y>=k)
                            {
                                mars[x, y] = 1;
                            }
                            else mars[x, y] = 0;
                            Console.Write(mars[x, y] + " ");
                            mars[x, y] = 0;
                        }
                        Console.WriteLine();
                             if (m > k || k > m)
                            {
                                break;
                            }

                    }
                }
            }


        }
    }
}