#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);

    int t;cin>>t;

    for (int i = 0; i < t; ++i){
        int n,m;cin>>n>>m;

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

        vector<vector<int>> matrix(n, vector<int>(m, 0));

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

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

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

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

    return 0;
}