#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
const int N = 2e5+10;
const int MOD = 1e9 + 7;
using namespace std;

void solve()
{
    int n,m;
    cin >> n >> m;
    vector<vector<ll>> a(n,vector<ll>(m));
    //for(int i = 0; i < n; i++)cin>>a[i];
    if(n!=m){
        cout << -1 << "\n";
        return;
    }
    for(int i = 0; i < n; i++){
        a[i][m-1] = 1;
    }

    for(int i = 0; i < m; i++){
        a[n-1][i] = 1;
    }

    for(int i = 0; i < n; i++){
        bool check = false;
        for(int j = 0; j < m; j++){
            if(j == m-i-1){
                check = true;
            }
            if(check){
                a[i][j] = 1;
            }
        }
    }



    for(int i = 0; i<n; i++){
        for(int j = 0; j < m; j++){
            cout << a[i][j] << " ";
        }
        cout << "\n";
    }

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t = 1;
    cin >> t;

    while(t--){
        solve();
    }

}