#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,m,t,j,k;
    cin>>t;
    for(i=0;i<t;i++)
    {
        cin>>n;
        cin>>m;
        if(n!=m)
        {
            cout<<"-1\n";
        }
        else
        {
            for(j=0;j<n;j++)
            {
                cout<<"1 ";
            }
            cout<<endl;
            for(j=0;j<n-2;j++)
            {
                cout<<"1 ";
                for(k=0;k<n-2;k++)
                {
                    cout<<"0 ";
                }
                cout<<"1\n";
            }
            for(j=0;j<n;j++)
            {
                cout<<"1 ";
            }
            cout<<endl;
        }
    }
}