#include <bits/stdc++.h>

using namespace std;

int main(){
    int t,m,n;
    int x=-1;
    cin>>t;
    for (int i=0; i<t;i++){
        cin>>n>>m;
        if(n>m or m>n ){
            cout<<x<<endl;
        }else if(m==n){
    int matrica [n+1][n+1];
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if((i<=2 and j<=n-2) or((i<=n-2 and i>2) and j<=n-i) or(i==n-1 and j==n-1)){
                matrica[i][j]=0;
            }else if(i>n-2){
                matrica[i][j]=1;
            }else{
                matrica[i][j]=1;
            }
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            cout<<matrica[i][j]<<" ";
            }
            cout<<endl;
            }
        }
    }


return 0;
}