#include <bits/stdc++.h>

using namespace std;

int main()
{


    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin>>t;

    while(t--)
    {
        long long n,m;
        cin>>n>>m;



        if(n!=m)
        {
            cout<<-1<< "\n";
            continue;
        }



        for (int i= 1;i<=n;i++)
        {
            for (int j=1;j<=m;j++)
                {
                if(j<1)
                cout<<" ";
                cout<<(i+j >= n+1?1:0);
            }
            cout<<"\n";
        }
    }

    return 0;
}