#include<bits/stdc++.h>

using namespace std;

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    if (n != m) {
      cout << "-1\n";
      continue;
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n - i - 1; j++)
        cout << "0 ";
      for (int j = n - i - 1; j < n; j++)
        cout << "1 ";
      cout << "\n";
    }
  }
  return 0;
}