#include <bits/stdc++.h>

using namespace std;

int main(){

    int t;
    
    cin >> t;

    while (t-->0){
        int n, m;
        cin >> n;
        cin >> m;

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

        for (int i = 0; i < n; i++){
            for (int j = 0; j < m; j++){
                cout << 1 << (j + 1 < m ? ' ' : '\n');
            }
        }
    }

    
    return 0;
}