#include <iostream>
#include <vector>

using namespace std;

void solve() {
    int n, m;
    if (!(cin >> n >> m)) return;

    if (n != m) {
        cout << -1 << "\n";
        return;
    }

    vector<vector<int>> mat(n, vector<int>(n, 0));

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

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

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

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

    int t;
    if (!(cin >> t)) return 0;
    while (t--) {
        solve();
    }
    return 0;
}