#include <iostream>
#include <vector>
int main()
{
	int t;
	std::cin >> t;
	std::vector<std::pair<int, int>> v(t);
	for (int i = 0; i < t; i++) {
		std::cin >> v[i].first >> v[i].second;
	}

	for (int k = 0; k < t; k++) {
		if (v[k].first != v[k].second)std::cout << -1 << std::endl;
		else {
			int n = v[k].first;
			std::vector<int> rez(n, 0);
			rez[0] = 1;
			int poz = n - 1;
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					if (i == 0 || i == n - 1) std::cout << 1;
					else std::cout << rez[j];
				}
				std::cout << std::endl;
				rez[poz] = 1;
				poz--;
			}
		}
	}
}