// PetarR57.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int t;
    cin >> t;
    vector<pair<int, int>> matrice(t);

    for (int i = 0; i < t; i++) {

        int n;
        int m;

        cin >> n >> m;
        matrice[i] = make_pair(n, m);
    }

    for (int i = 0; i < t; i++) {

        int n = matrice[i].first;
        int m = matrice[i].second;

        if (n != m) cout << "-1 ";
        else {

            for (int i = 0; i < m; i++) cout << "1 ";
            if (n != 1) cout << '\n';

            for (int i = 1; i < n - 1; i++) {
                cout << "1 ";
                for (int j = 1; j < m - i; j++) {
                    cout << "0 ";
                }

                for (int j = m - i; j < m; j++) {
                    cout << "1 ";
                }
                cout << "\n";
            }

            if (n != 1){
                for (int i = 0; i < m; i++) cout << 1 << " ";
                cout << '\n';
            }
            
        }

        cout << "\n";
    }
}