#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
    int t;
    cin>>t;
    for(int i =0;i<t;i++){
        int n,m;
        cin>>n>>m;
        if(n!=m){
            cout<<-1<<endl;
        }
        else{
            vector<vector<int>> matrica;
            vector<int> pocetno_krajnji={};
            for(int j =0;j<m;j++){
                pocetno_krajnji.push_back(1);
            }
            matrica.push_back(pocetno_krajnji);
            for(int j =1;j<m-1;j++){
                vector<int> trenutni = {};
                trenutni.push_back(1);
                for(int k =0;k<m-j-1;k++){
                    trenutni.push_back(0);
                }
                while(trenutni.size()<m){
                    trenutni.push_back(1);
                }
                matrica.push_back(trenutni);
            }
            matrica.push_back(pocetno_krajnji);

            for(int j=0;j<m;j++){
                for(int k=0;k<m;k++){
                    cout<<matrica[j][k]<<" ";
                }
                cout<<endl;
            }
        }
    }
}