#include <bits/stdc++.h>

using namespace std;
typedef long long ll;


int main(){
    ll t;
    cin >> t;
    for (int test=0; test<t; test++){
        ll 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++){
                vector<int> red(m);
                if (i==0 || j==0 || i==n-1 || j==m-1){
                    cout << 1 << " ";
                }
                else if (i+j>n-1){
                    cout << 1 << " ";
                }
                else{
                    cout << 0 << " ";
                }
            }
            cout << endl;
        }
    }

    return 0;
}