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

int main() {
    int t ;
    cin >> t ;
    while (t--) {
        int n, m ;
        cin >> n >> m ;
        if (n != m) {
            cout << -1 << endl ;
            continue ;
        }
        for (int i = 0 ; i < n ; i++) {
            for (int j = 0 ; j < m ; j++) {
                if (i == 0) {
                    cout << 1 << " " ;
                    continue ;
                }
                if (j == 0) {
                    cout << 1  << " " ;
                    continue ;
                }
                if (j >= n-i) {
                    cout << 1 << " " ;
                    continue ;
                }
                cout << 0 << " " ;
            }
            cout << endl ;
        }
    }
}