#include <iostream>
#include <vector>

using namespace std;

int main()
{

    int t;
    cin >> t;

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

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

        vector< vector<int> > mat = vector< vector<int> >(n);
        for (int i = 0; i < m; i++) {
            mat[i] = vector<int>(m);
        }

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

        for (int i = n-1; i>0; i--) {
            int br = i;
            while (br) {
                mat[i][n-br] = 1;
                mat[n - br--][i] = 1;
            }
        }

        for (int i = 0; i<n; i++) {
            for (int j = 0; j<m; j++) {
                cout << mat[i][j] << " ";
            }
            cout << "\n";
        }
    }
    return 0;
}