#include <iostream>
using namespace std;
int a[2005][2005];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--) {
        int n, m;
        cin >> n >> m;

        if (n != m) {
            cout << "-1\n";
            continue;
        }
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                a[i][j] = 0;

        for (int i = n - 1; i >= 0; i--) {
            int s = 0;
            for (int j = 0; j < n; j++) s += a[i][j];

            int k = i + 1;
            int x = (k - (s % k)) % k;
            if (s == 0) x = k;

            for (int j = 0; j < x; j++) {
                a[i][j] = 1;
                a[j][i] = 1;
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                cout << a[i][j] << (j == n - 1 ? "" : " ");
            }
            cout << "\n";
        }
    }
    return 0;
}