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

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