#include <bits/stdc++.h>

using namespace std;

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

    int t; cin >> t;
    while (t--) {
        int n, m; cin >> n >> m;
        if (n != m) cout << "-1\n";

        int zeros = n - 1;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == 0 || !(zeros > 0 && j >= 1 && j <= zeros)) cout << "1 ";
                else cout << "0 ";
            }
            cout << "\n";
            zeros--;
        }
    }

    return 0;
}