#include <iostream>

using namespace std;

int main()
{
    long n,m,i,j,b,k;
    cin>>b;
    for(k=0;k<b;k++)
    {
        cin>>n>>m;
        if(n!=m)
        {
            cout<<-1<<endl;
        }
        else
        {
            for(i=0;i<n;i++)
            {
                for(j=0;j<m;j++)
                {
                    if((j>=m-(j+1)&&i>=n-(i+1))||(j==0||i==0))
                    {
                        cout<<1<<" ";
                    }
                    else
                    {
                        cout<<0<<" ";
                    }
                }
                cout<<endl;
            }
        }
    }
    return 0;
}