#include<bits/stdc++.h>
using namespace std;
void promena(vector<vector<int,int>>& matrica,int& n){
	int br=1;
	for (int i=1;i<n-1;i++){
		br++;
		for (int j=1;j<n-br;j++){
			matrica[i][j]=0;
		}
	}
}
void ispis(vector<vector<int,int>>& matrica,int& n){
	for (int i=0;i<n;i++){
		for (int j=0;j<n;j++){
			cout<<matrica[i][j]<<" ";
		}
		cout<<endl;
	}
}
int main() {
	int t,n,m;
	cin>>t;
	for (int i=0;i<t;i++){
		cin>>n>>m;
		
		if(n!=m)cout<<-1<<endl;
		else{
			vector<vector<int,int>>matrica(1,m);
			for (int i=0;i<n;i++)matrica.resize(1,n);
			promena(matrica,n);
			ispis(matrica,n);
		}
	}
	return 0;
}