using System;
using System.Text;

public class Program{
    public static void Main(string[] args){
        int t = int.Parse(Console.ReadLine());

        while (t-- > 0){
            string inputovan = Console.ReadLine();string[] input = inputovan.Trim().Split(' ');
            int N = int.Parse(input[0]);
            int M = int.Parse(input[1]);


            if (N != M)
            {
                Console.WriteLine(-1);
                continue;
		//t--;
            }


            StringBuilder sb = new StringBuilder();

            for (int i = 1; i <= N; i++){
                for (int j = 1; j <= N; j++){
                    if (i + j >= N + 1)
                    {
                        sb.Append("1");
                    }
                    else
                    {
                        sb.Append("0");
                    }
                    if (j < N) sb.Append(" ");
                }
                sb.AppendLine();
            }
            Console.Write(sb.ToString());
        }
    }
}