#include <bits/stdc++.h>

using namespace std;

#define int ll
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;

signed main()
{
	ios_base::sync_with_stdio(false); 
	cin.tie(nullptr); 
	cout.tie(nullptr); 
	cerr.tie(nullptr);	

	int t;
	cin >> t;

	while(t--){
		int n, m;
		cin >> n >> m;


		if (n != m){
			cout << "-1\n";
			continue;
		}

		for (int i = 1; i <= n; ++i){
			for (int j = 1; j <= m; ++j){
				if (i + j >= n + 1)
					cout << "1 ";
				else 
					cout << "0 ";
			}
			cout << '\n';
		}
	}
}
