#include <bits/stdc++.h>
using namespace std;
void res(vector<pair<int, int> >& v, int& i){
	int matrica[v[i].first+1][v[i].second+1] = {0};
	
	for(int j = 1; j < v[i].first+1; ++j){
		matrica[j][1] = 1;
		matrica[1][j] = 1;
		matrica[v[i].first][j] = 1;
		matrica[j][v[i].first] = 1;
 	}
 	int p = -1;
 	for(int r = v[i].first-1; r > 2; r--){
 		p += 1;
 		for(int k = 3+p; k < v[i].first; k++){
 			matrica[r][k] = 1;
		}
	}
	
	for(int r = 1; r < v[i].first+1; r++){
		for(int k = 1; k < v[i].first+1; k++){
			cout << matrica[r][k] << " ";
		}
		cout << endl;
	}
}
int main()  {
	
	int t;
	cin >> t;
	vector<pair<int, int> > v(t);
	vector<bool> m(t, true);
	for(int i = 0; i < t; ++i){
		cin >> v[i].first >> v[i].second;
		if(v[i].first != v[i].second) m[i] = false;
	}
	for(int i = 0; i < t; ++i){
		if(m[i]){
			res(v, i);
		}
		else cout << -1 << endl;
	}
	
	
	
	
return 0;

}