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

namespace ConsoleApp2
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int t = int.Parse(Console.ReadLine());
            List<int> granice = new List<int>();
            for (int y = 0; y < t; y++)
            {
                string[] s = Console.ReadLine().Split();
                granice.Add(int.Parse(s[0]));
                granice.Add(int.Parse(s[1]));
            }
            int index = 0;
            for (int x = 0; x < t; x++)
            {
                
                int n = granice[index];
                int m = granice[index+1];
                int[,] mapa = new int[n, m];
                index += 2;
                if (n != m)
                {
                    Console.WriteLine("-1");
                }
                else
                {
                     
                    for(int pi = 0; pi < n; pi++) //prvi i poslednji red/kolona
                    {
                        mapa[0, pi] = 1;
                        mapa[n-1, pi] = 1;
                        mapa[pi, m-1] = 1;
                        mapa[pi, 0] = 1;
                    }
                    int br = 2;
                    for(int ip = n-2; ip >= 2; ip--) //popunjavanje unutrasnjosti
                    {
                        for(int jp = br; jp < m-1; jp++)
                        {
                            mapa[ip, jp] = 1;

                        }
                        br++;
                    }

                    for(int i = 0; i < n; i++) //ispis
                    {
                        for(int j = 0; j < m; j++)
                        {
                            Console.Write(mapa[i, j]);
                        }
                        Console.WriteLine();
                    }
                }
            }
        }
    }
}