#include <bits/stdc++.h>
#define ihp ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;

int main()
{
ihp
int t,n,m,nesto=0;
vector<pair<int,int>> niz;
cin>>t;
niz.resize(t);
for(int i=0;i<t;i++)
{
    cin>>n>>m;
    get<0>(niz[i])=n;
    get<1>(niz[i])=m;
}
for(int i=0;i<t;i++)
{
    if(get<0>(niz[i])!=get<1>(niz[i]))
        cout<<"-1"<<endl;
    if(get<0>(niz[i])==get<1>(niz[i]))
        nesto=1;

    for(int j=0;j<get<0>(niz[i]);j++)
    {
        for(int k=0;k<get<1>(niz[i]);k++)
        {
            if(nesto==1)
            {
                if((j==0 or j==get<0>(niz[i])-1) or (k==0 or k==get<0>(niz[i])-1) or k+j>=get<0>(niz[i]))
                    cout<<"1"<<" ";
                if(k==get<0>(niz[i])-1)
                    cout<<endl;
                if(k>0 && k<get<0>(niz[i])-1 && j>0 && j<get<0>(niz[i])-1 && k+j<get<0>(niz[i]))
                    cout<<"0"<<" ";

            }
            else if(nesto==0)
            break;
        }



    }
nesto=0;
}


    return 0;
}