int main(){
    int t;
    cin>>t;
    vector<pair<int,int>> a(t);
    for(int i=0;i<t;i++){
        cin>>a[i].first;
        cin>>a[i].second;
    }
    int br=0;
    for(int i=0;i<t;i++){
        if(a[i].first!=a[i].second){
            cout<<-1<<endl;
        }
        else{
            for(int j=0;j<a[i].first;j++){
                for(int k=0;k<a[i].second;k++){
                    if(j==0){
                        cout<<1<<" ";
                    }
                    else if(k==0){
                        cout<<1<<" ";
                    }
                    else if(k==a[i].first-1){
                        cout<<1<<" ";
                    }
                    else if(a[i].first-j>k){
                        cout<<0<<" ";
                    }
                    else{
                        cout<<1<<" ";
                    }
                }
                cout<<endl;
            }
        }
    }
}