#include <bits/stdc++.h>
using namespace std;

int T, N, M;
int glob_matrica[10][10];

void proveri(vector<vector<uint8_t>> matrica, vector<uint8_t> sum_rows, vector<uint8_t> sum_cols) {
    for(uint8_t i = 0; i < N - 1; i++) {
        if(sum_rows[i] % (i + 1) != 0)
            return;
        if(sum_cols[i] % (i + 1) != 0)
            return;
    }
    //cout << "dobri.. kako" << endl;
    for(int i = 0; i < N - 1; i++) {
        for(int j = 0 ; j < N - 1; j++) {
            glob_matrica[i][j] = matrica[i][j];
        }
    }
}

void kombi(int i, int j, vector<vector<uint8_t>> matrica, vector<uint8_t> sum_rows, vector<uint8_t> sum_cols) {
    //cout << i << " " << j << endl;
    if(i >= N - 1)
        return;
    if(j >= N - 1)
        return;

    matrica[i][j] = 0;
    proveri(matrica, sum_rows, sum_cols);
    kombi(i, j + 1, matrica, sum_rows, sum_cols);
    if(j == N - 2)
        kombi(i + 1, 0, matrica, sum_rows, sum_cols);

    matrica[i][j] = 1;
    sum_rows[i]++;
    sum_cols[j]++;
    proveri(matrica, sum_rows, sum_cols);
    kombi(i, j + 1, matrica, sum_rows, sum_cols);
    if(j == N - 2)
        kombi(i + 1, 0, matrica, sum_rows, sum_cols);
}

void kombinacije() {
    if(N == 1) {
        cout << "1";
        return;
    }

    if(N == 2) {
        cout << "1 1\n1 1";
        return;
    }

    for(int i = N - 1; i < N; i++) {
        for(int j = 0; j < N; j++) {
            glob_matrica[i][j] = 1;
        }
    }
    for(int i = 0; i < N; i++) {
        for(int j = N - 1; j < N; j++) {
            glob_matrica[i][j] = 1;
        }
    }

    vector<vector<uint8_t>> matrica;
    matrica.resize(5);
    for(int i = 0; i < 5; i++) {
        matrica[i].resize(5, 0);
    }
    vector<uint8_t> sum_rows;
    sum_rows.resize(5, 1);

    vector<uint8_t> sum_cols;
    sum_cols.resize(5, 1);
    kombi(0, 0, matrica, sum_rows, sum_cols);

    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            cout << glob_matrica[i][j] << " ";
        }
        cout << '\n';
    }
};

int main() {
    ios::sync_with_stdio(false);

    cin >> T;
    for(int i = 0; i < T; i++) {
        cin >> N >> M;
        if(N != M)
            cout << -1 << '\n';
        else
            kombinacije();
    }
}