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

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

    int T;
    cin >> T;

    while (T--) {
        int N, M;
        cin >> N >> M;

        if ((N == 1 && M > 1) || (M == 1 && N > 1)) {
            cout << -1 << '\n';
            continue;
        }

        if (N == 1 && M == 1) {
            cout << 1 << '\n';
            continue;
        }


        vector<vector<int>> a(N, vector<int>(M, 0));

        int kol = 0;

        for (int i = 0; i < N; i++) {

            for (int k = 0; k < i + 1; k++) {
                a[i][kol] = 1;


                kol = (kol + 1) % M;
            }
        }

        for (int i = 0; i < N; i++) {
            for (int j = 0; j < M; j++) {
                cout << a[i][j];
                if (j + 1 < M) cout << " ";
            }
            cout << "\n";
        }
    }

    return 0;
}