#include<bits/stdc++.h>
using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        int64_t n,m;
        cin>>n>>m;
        if(n!=m){
            cout<<-1<<endl;
        }
        else if(n==1){
            cout<<1<<endl;
        }
        else{
            for(int64_t i=0;i<n;i++){
                cout<<1<<" ";
            }
            cout<<endl;
            for(int64_t i=0;i<n-2;i++){
                cout<<1<<" ";
                for(int64_t j=0;j<n-2-i;j++){
                    cout<<"0 ";
                }
                for(int64_t j=0;j<i;j++){
                    cout<<"1 ";
                }
                cout<<1<<endl;
            }
            for(int64_t i=0;i<n;i++){
                cout<<1<<" ";
            }
            cout<<endl;
        }
    }
}