#include <iostream>
#include <algorithm>


using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t; cin >> t;

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

        if (n != m) {
            cout << -1 << endl;
        }
        else {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n - i - 1; j++) {
                    cout << 0 << " ";
                }
                for (int k = 0; k < i + 1; k++) {
                    cout << 1 << " ";
                }
                cout << endl;
            }
        }
    }

    return 0;
}