#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;
        }

        vector<vector<int>> mat(N, vector<int>(M, 1));

        if (N >= 2 && M >= 2) {
            if (N >= 4 && M >= 4) {
                mat[1][1] = 0;
                mat[1][2] = 0;
                mat[2][1] = 0;
            }
            
        }

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