#include <bits/stdc++.h>
#define endl '\n'
#define fi first
#define se second
#define pb push_back

using namespace std;

using ll = long long;

void solve()
{
    ll n,m,i,j;
    cin >> n >> m;
    if(n!=m)
    {
        cout << "-1" << endl;
        return;
    }

    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            if(m-j-1<=i)
            {
                cout << "1" << " ";
                continue;
            }
            cout << "0 ";
        }
        cout << endl;
    }


}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
}