#include <bits/stdc++.h>
using namespace std;

void print_matrix(int n, int m) {
    int a[n][m];

    for (int i = 0; i<n; i++) {
        for (int j = 0; j<m; j++) {
            a[i][j] = 0;
        }
    }

    for (int i = n-1; i>=0; i--) {
        for (int j = m-1; j>=n-i-1; j--) {
            a[i][j] = 1;
        }
    }

    for (int i = 0; i<n; i++) {
        for (int j = 0; j<m; j++) {
            cout<<a[i][j]<<' ';
        }
        cout<<'\n';
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    int n, m, t;
    cin>>t;
    
    for (int i = 0; i<t; i++) {
        cin>>n>>m;
        if (n!=m) {
            cout << -1 << '\n';
            continue;
        }

        print_matrix(n, m);
        cout<<'\n';


    }
}