#include <iostream>
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    int t; cin >> t;
    while(t--){
        int n; cin >> n;
        int m; cin >> m;
        int a[n][m];
        if(n==m){
            int nule = n-1;
            int br = 0;
            for(int i=0; i<n; i++){
                for(int j=0; j<m; j++){
                    if(i==0 || i==n-1){
                        a[i][j] = 1;
                    }
                    else if(j==0 || j==n-1)
                        a[i][j] = 1;
                    else{
                        if(br++ < nule)
                            a[i][j] = 0;
                        else
                            a[i][j] = 1;
                    }
                }
                nule--;
                br = 0;
            }
            for(int i=0; i<n; i++){
                for(int j=0; j<m; j++)
                    cout << a[i][j] << " ";
                cout << endl;
            }
        }
        else
            cout << "-1" << endl;
    }
    return 0;
}