#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 col = 0;
        for (int i = 0; i < N; i++) {
            for (int k = 0; k < i + 1; k++) {
                a[i][col] = 1;
                col = (col + 1) % M;
            }
        }

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

    return 0;
}